2022-07-21 17:08:49 +10:00
|
|
|
use std::env;
|
2022-07-25 13:47:43 +10:00
|
|
|
use teslatte::auth::AccessToken;
|
2023-09-05 13:48:16 +10:00
|
|
|
use teslatte::products::Product;
|
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),
|
2023-08-29 10:29:06 +10:00
|
|
|
Err(_) => {
|
|
|
|
let api = Api::from_interactive_url().await.unwrap();
|
|
|
|
println!("TOKEN: {:?}", api.access_token);
|
|
|
|
api
|
|
|
|
}
|
2022-07-21 17:08:49 +10:00
|
|
|
};
|
2022-07-21 13:46:49 +10:00
|
|
|
|
|
|
|
let vehicles = api.vehicles().await.unwrap();
|
2023-09-05 13:48:16 +10:00
|
|
|
dbg!(&*vehicles);
|
2022-07-21 13:46:49 +10:00
|
|
|
|
2023-08-29 11:41:40 +10:00
|
|
|
if !vehicles.is_empty() {
|
2022-07-21 17:08:49 +10:00
|
|
|
let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap();
|
2023-09-05 13:48:16 +10:00
|
|
|
dbg!(&*vehicle_data);
|
2022-07-21 17:08:49 +10:00
|
|
|
} else {
|
|
|
|
println!("No vehicles found!");
|
|
|
|
}
|
2023-09-05 13:48:16 +10:00
|
|
|
|
|
|
|
let products = api.products().await.unwrap();
|
|
|
|
dbg!(&*products);
|
|
|
|
|
|
|
|
if !products.is_empty() {
|
|
|
|
for product in &*products {
|
|
|
|
match product {
|
|
|
|
Product::Vehicle(v) => {
|
|
|
|
dbg!(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
Product::Solar(e) => {
|
|
|
|
let site_info = api.energy_sites_site_info(&e.energy_site_id).await.unwrap();
|
|
|
|
dbg!(&*site_info);
|
|
|
|
|
|
|
|
let live_info = api
|
|
|
|
.energy_sites_live_status(&e.energy_site_id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
dbg!(&*live_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
Product::Powerwall(p) => {
|
|
|
|
let live_info = api
|
|
|
|
.energy_sites_live_status(&p.energy_site_id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
dbg!(&*live_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("No products found!");
|
|
|
|
}
|
2022-07-21 13:46:49 +10:00
|
|
|
}
|