teslatte/examples/basic.rs

31 lines
790 B
Rust
Raw Normal View History

use std::env;
2022-07-25 13:47:43 +10:00
use teslatte::auth::AccessToken;
2022-07-21 13:46:49 +10:00
use teslatte::Api;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
2022-07-25 13:47:43 +10:00
let api = match env::var("TESLA_ACCESS_TOKEN") {
Ok(t) => Api::new(AccessToken(t), None),
Err(_) => {
let api = Api::from_interactive_url().await.unwrap();
println!("TOKEN: {:?}", api.access_token);
api
}
};
2022-07-21 13:46:49 +10:00
let vehicles = api.vehicles().await.unwrap();
dbg!(&vehicles);
2023-08-29 11:41:40 +10:00
if !vehicles.is_empty() {
let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap();
dbg!(vehicle_data);
let charge_state = api.charge_state(&vehicles[0].id).await.unwrap();
dbg!(&charge_state);
} else {
println!("No vehicles found!");
}
2022-07-21 13:46:49 +10:00
}