fix: remove vehicles list (#13)

This commit is contained in:
gak 2024-01-24 10:22:08 +11:00
parent c8b45d5c3e
commit 796c09c17a
No known key found for this signature in database
6 changed files with 16 additions and 23 deletions

View file

@ -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/), 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). 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 ## [0.1.12] - 2023-01-20
### Changed ### Changed

View file

@ -1,8 +1,7 @@
use std::env; use std::env;
use teslatte::auth::AccessToken; use teslatte::auth::AccessToken;
use teslatte::products::Product; use teslatte::products::Product;
use teslatte::vehicles::GetVehicleData; use teslatte::OwnerApi;
use teslatte::{OwnerApi, VehicleApi};
#[tokio::main] #[tokio::main]
async fn 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(); let products = api.products().await.unwrap();
dbg!(&*products); dbg!(&products);
if !products.is_empty() { if !products.is_empty() {
for product in &*products { for product in &*products {

View file

@ -7,9 +7,8 @@ no_token_test:
# Require an access token from "cli.json". Use `just auth` to generate. # Require an access token from "cli.json". Use `just auth` to generate.
token_tests: token_tests:
cargo run -- api vehicles
cargo run --no-default-features --features cli -- api vehicles
cargo run -- api products cargo run -- api products
cargo run --no-default-features --features cli -- api products
publish version: publish version:
git diff-index --quiet HEAD git diff-index --quiet HEAD

View file

@ -6,7 +6,7 @@ use crate::auth::{AccessToken, RefreshToken};
use crate::error::TeslatteError; use crate::error::TeslatteError;
use crate::vehicles::{ use crate::vehicles::{
GetVehicleData, SetChargeLimit, SetChargingAmps, SetScheduledCharging, SetScheduledDeparture, GetVehicleData, SetChargeLimit, SetChargingAmps, SetScheduledCharging, SetScheduledDeparture,
SetTemperatures, Vehicle, VehicleData, SetTemperatures, VehicleData,
}; };
use chrono::{DateTime, SecondsFormat, TimeZone}; use chrono::{DateTime, SecondsFormat, TimeZone};
use derive_more::{Deref, Display, From, FromStr}; 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"; const API_URL: &str = "https://owner-api.teslamotors.com/api/1";
pub trait VehicleApi { pub trait VehicleApi {
async fn vehicles(&self) -> Result<Vec<Vehicle>, TeslatteError>;
async fn vehicle_data( async fn vehicle_data(
&self, &self,
get_vehicle_data: &GetVehicleData, get_vehicle_data: &GetVehicleData,
@ -314,6 +313,7 @@ struct ResponseError {
struct Empty {} struct Empty {}
/// GET /api/1/[url] /// GET /api/1/[url]
#[allow(unused_macros)]
macro_rules! get { macro_rules! get {
($name:ident, $return_type:ty, $url:expr) => { ($name:ident, $return_type:ty, $url:expr) => {
async fn $name(&self) -> Result<$return_type, crate::error::TeslatteError> { async fn $name(&self) -> Result<$return_type, crate::error::TeslatteError> {
@ -324,6 +324,7 @@ macro_rules! get {
} }
}; };
} }
#[allow(unused_imports)]
pub(crate) use get; pub(crate) use get;
/// Same as get, but public. /// Same as get, but public.

View file

@ -4,7 +4,7 @@ use teslatte::auth::{AccessToken, RefreshToken};
use teslatte::cli::energy::EnergySiteArgs; use teslatte::cli::energy::EnergySiteArgs;
use teslatte::cli::powerwall::PowerwallArgs; use teslatte::cli::powerwall::PowerwallArgs;
use teslatte::cli::vehicle::VehicleArgs; use teslatte::cli::vehicle::VehicleArgs;
use teslatte::{OwnerApi, PrintResponses, VehicleApi}; use teslatte::{OwnerApi, PrintResponses};
/// Teslatte /// Teslatte
/// ///
@ -106,7 +106,7 @@ async fn main() -> miette::Result<()> {
api.print_responses = PrintResponses::Pretty; api.print_responses = PrintResponses::Pretty;
match api_args.command { match api_args.command {
ApiCommand::Vehicles => { ApiCommand::Vehicles => {
api.vehicles().await?; panic!("Tesla API has changed. This command is no longer works with the Owners API.");
} }
ApiCommand::Vehicle(v) => { ApiCommand::Vehicle(v) => {
v.run(&api).await?; v.run(&api).await?;

View file

@ -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 // 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. // will cause the deserializer to fail. Please log an issue to fix these if you come across it.
use crate::{ use crate::{
get, get_args, post_arg, post_arg_empty, ApiValues, Empty, ExternalVehicleId, OwnerApi, get_args, post_arg, post_arg_empty, ApiValues, Empty, ExternalVehicleId, OwnerApi, VehicleApi,
VehicleApi, VehicleId, VehicleId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use strum::{Display, EnumString}; use strum::{Display, EnumString};
#[rustfmt::skip] #[rustfmt::skip]
impl VehicleApi for OwnerApi { impl VehicleApi for OwnerApi {
get!(vehicles, Vec<Vehicle>, "/vehicles");
get_args!(vehicle_data, VehicleData, "/vehicles/{}/vehicle_data", GetVehicleData); get_args!(vehicle_data, VehicleData, "/vehicles/{}/vehicle_data", GetVehicleData);
post_arg_empty!(wake_up, "/vehicles/{}/command/wake_up", VehicleId); post_arg_empty!(wake_up, "/vehicles/{}/command/wake_up", VehicleId);