From 796c09c17a62f772bb608a1e1ec5e2060d73d353 Mon Sep 17 00:00:00 2001 From: gak Date: Wed, 24 Jan 2024 10:22:08 +1100 Subject: [PATCH] fix: remove vehicles list (#13) --- CHANGELOG.md | 6 ++++++ examples/basic.rs | 16 ++-------------- justfile | 3 +-- src/lib.rs | 5 +++-- src/main.rs | 4 ++-- src/vehicles.rs | 5 ++--- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4a9d51..fbd0757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.13] - 2023-01-24 + +### Changed + +- Vehicles list is gone from the API. Use `products` instead. (#13) + ## [0.1.12] - 2023-01-20 ### Changed diff --git a/examples/basic.rs b/examples/basic.rs index 2bd71f3..aa1cf35 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,8 +1,7 @@ use std::env; use teslatte::auth::AccessToken; use teslatte::products::Product; -use teslatte::vehicles::GetVehicleData; -use teslatte::{OwnerApi, VehicleApi}; +use teslatte::OwnerApi; #[tokio::main] async fn main() { @@ -17,19 +16,8 @@ async fn main() { } }; - let vehicles = api.vehicles().await.unwrap(); - dbg!(&*vehicles); - - if !vehicles.is_empty() { - let get_vehicle_data = GetVehicleData::new(vehicles[0].id.clone()); - let vehicle_data = api.vehicle_data(&get_vehicle_data).await.unwrap(); - dbg!(&vehicle_data); - } else { - println!("No vehicles found!"); - } - let products = api.products().await.unwrap(); - dbg!(&*products); + dbg!(&products); if !products.is_empty() { for product in &*products { diff --git a/justfile b/justfile index c973525..6eb0cbb 100644 --- a/justfile +++ b/justfile @@ -7,9 +7,8 @@ no_token_test: # Require an access token from "cli.json". Use `just auth` to generate. token_tests: - cargo run -- api vehicles - cargo run --no-default-features --features cli -- api vehicles cargo run -- api products + cargo run --no-default-features --features cli -- api products publish version: git diff-index --quiet HEAD diff --git a/src/lib.rs b/src/lib.rs index 76962b2..03d4740 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use crate::auth::{AccessToken, RefreshToken}; use crate::error::TeslatteError; use crate::vehicles::{ GetVehicleData, SetChargeLimit, SetChargingAmps, SetScheduledCharging, SetScheduledDeparture, - SetTemperatures, Vehicle, VehicleData, + SetTemperatures, VehicleData, }; use chrono::{DateTime, SecondsFormat, TimeZone}; use derive_more::{Deref, Display, From, FromStr}; @@ -28,7 +28,6 @@ pub mod cli; const API_URL: &str = "https://owner-api.teslamotors.com/api/1"; pub trait VehicleApi { - async fn vehicles(&self) -> Result, TeslatteError>; async fn vehicle_data( &self, get_vehicle_data: &GetVehicleData, @@ -314,6 +313,7 @@ struct ResponseError { struct Empty {} /// GET /api/1/[url] +#[allow(unused_macros)] macro_rules! get { ($name:ident, $return_type:ty, $url:expr) => { async fn $name(&self) -> Result<$return_type, crate::error::TeslatteError> { @@ -324,6 +324,7 @@ macro_rules! get { } }; } +#[allow(unused_imports)] pub(crate) use get; /// Same as get, but public. diff --git a/src/main.rs b/src/main.rs index 905c529..1712fe2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use teslatte::auth::{AccessToken, RefreshToken}; use teslatte::cli::energy::EnergySiteArgs; use teslatte::cli::powerwall::PowerwallArgs; use teslatte::cli::vehicle::VehicleArgs; -use teslatte::{OwnerApi, PrintResponses, VehicleApi}; +use teslatte::{OwnerApi, PrintResponses}; /// Teslatte /// @@ -106,7 +106,7 @@ async fn main() -> miette::Result<()> { api.print_responses = PrintResponses::Pretty; match api_args.command { ApiCommand::Vehicles => { - api.vehicles().await?; + panic!("Tesla API has changed. This command is no longer works with the Owners API."); } ApiCommand::Vehicle(v) => { v.run(&api).await?; diff --git a/src/vehicles.rs b/src/vehicles.rs index b3a8eb5..75a96c3 100644 --- a/src/vehicles.rs +++ b/src/vehicles.rs @@ -4,15 +4,14 @@ use derive_more::{Deref, DerefMut, From}; // Sometimes the API will return a null for a field where I've put in a non Option type, which // will cause the deserializer to fail. Please log an issue to fix these if you come across it. use crate::{ - get, get_args, post_arg, post_arg_empty, ApiValues, Empty, ExternalVehicleId, OwnerApi, - VehicleApi, VehicleId, + get_args, post_arg, post_arg_empty, ApiValues, Empty, ExternalVehicleId, OwnerApi, VehicleApi, + VehicleId, }; use serde::{Deserialize, Serialize}; use strum::{Display, EnumString}; #[rustfmt::skip] impl VehicleApi for OwnerApi { - get!(vehicles, Vec, "/vehicles"); get_args!(vehicle_data, VehicleData, "/vehicles/{}/vehicle_data", GetVehicleData); post_arg_empty!(wake_up, "/vehicles/{}/command/wake_up", VehicleId);