Skip to content

Commit

Permalink
fix: remove vehicles list (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
gak committed Jan 23, 2024
1 parent c8b45d5 commit 796c09c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 2 additions & 14 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<Vec<Vehicle>, TeslatteError>;
async fn vehicle_data(
&self,
get_vehicle_data: &GetVehicleData,
Expand Down Expand Up @@ -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> {
Expand All @@ -324,6 +324,7 @@ macro_rules! get {
}
};
}
#[allow(unused_imports)]
pub(crate) use get;

/// Same as get, but public.
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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?;
Expand Down
5 changes: 2 additions & 3 deletions src/vehicles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vehicle>, "/vehicles");
get_args!(vehicle_data, VehicleData, "/vehicles/{}/vehicle_data", GetVehicleData);
post_arg_empty!(wake_up, "/vehicles/{}/command/wake_up", VehicleId);

Expand Down

0 comments on commit 796c09c

Please sign in to comment.