2023-09-05 13:48:16 +10:00
|
|
|
use crate::energy_sites::{HistoryKind, HistoryPeriod};
|
|
|
|
use crate::products::GatewayId;
|
change!: vehicle_data now accepts a struct instead of VehicleId
To support "endpoints", e.g. requesting GPS.
From https://developer.tesla.com/docs/fleet-api#vehicle_data
String of URL-encoded, semicolon-separated values. Can be many of 'charge_state',
'climate_state', 'closures_state', 'drive_state', 'gui_settings', 'location_data',
'vehicle_config', 'vehicle_state', 'vehicle_data_combo'.
Before:
let vehicle_data = api.vehicle_data(&vehicle_id).await.unwrap();
After:
let get_vehicle_data = GetVehicleData::new(vehicles_id);
let vehicle_data = api.vehicle_data(&get_vehicle_data).await.unwrap();
Or with a endpoints:
let get_vehicle_data = GetVehicleData::new_with_endpoints(123u64, vec![Endpoint::ChargeState, Endpoint::ClimateState]);
let vehicle_data = api.vehicle_data(&get_vehicle_data).await.unwrap();
CLI:
You can still use vehicle-data without endpoints, but you won't get
location data. To fetch location_data:
teslatte api vehicle 123 vehicle-data location_data
2023-11-11 11:07:24 +11:00
|
|
|
use crate::{join_query_pairs, pub_get_arg, pub_get_args, rfc3339, ApiValues, OwnerApi};
|
2022-07-25 10:00:55 +10:00
|
|
|
use chrono::{DateTime, FixedOffset};
|
|
|
|
use derive_more::{Display, FromStr};
|
2022-07-21 21:00:45 +10:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
2023-10-20 12:18:38 +11:00
|
|
|
impl OwnerApi {
|
2023-10-22 09:17:32 +11:00
|
|
|
pub_get_arg!(powerwall_status, PowerwallStatus, "/powerwalls/{}/status", PowerwallId);
|
|
|
|
pub_get_args!(powerwall_energy_history, PowerwallEnergyHistory, "/powerwalls/{}/energyhistory", PowerwallEnergyHistoryValues);
|
2022-07-21 21:00:45 +10:00
|
|
|
}
|
|
|
|
|
2022-07-25 10:00:55 +10:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Display, FromStr)]
|
2022-07-21 21:00:45 +10:00
|
|
|
pub struct PowerwallId(pub String);
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
|
pub struct PowerwallStatus {
|
|
|
|
pub site_name: String,
|
|
|
|
pub id: GatewayId,
|
|
|
|
pub energy_left: f64,
|
|
|
|
pub total_pack_energy: i64,
|
|
|
|
pub percentage_charged: f64,
|
|
|
|
pub battery_power: i64,
|
|
|
|
}
|
2022-07-25 10:00:55 +10:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct PowerwallEnergyHistoryValues {
|
|
|
|
pub powerwall_id: PowerwallId,
|
|
|
|
pub period: HistoryPeriod,
|
|
|
|
pub kind: HistoryKind,
|
|
|
|
pub start_date: Option<DateTime<FixedOffset>>,
|
|
|
|
pub end_date: Option<DateTime<FixedOffset>>,
|
|
|
|
}
|
|
|
|
|
change!: vehicle_data now accepts a struct instead of VehicleId
To support "endpoints", e.g. requesting GPS.
From https://developer.tesla.com/docs/fleet-api#vehicle_data
String of URL-encoded, semicolon-separated values. Can be many of 'charge_state',
'climate_state', 'closures_state', 'drive_state', 'gui_settings', 'location_data',
'vehicle_config', 'vehicle_state', 'vehicle_data_combo'.
Before:
let vehicle_data = api.vehicle_data(&vehicle_id).await.unwrap();
After:
let get_vehicle_data = GetVehicleData::new(vehicles_id);
let vehicle_data = api.vehicle_data(&get_vehicle_data).await.unwrap();
Or with a endpoints:
let get_vehicle_data = GetVehicleData::new_with_endpoints(123u64, vec![Endpoint::ChargeState, Endpoint::ClimateState]);
let vehicle_data = api.vehicle_data(&get_vehicle_data).await.unwrap();
CLI:
You can still use vehicle-data without endpoints, but you won't get
location data. To fetch location_data:
teslatte api vehicle 123 vehicle-data location_data
2023-11-11 11:07:24 +11:00
|
|
|
impl ApiValues for PowerwallEnergyHistoryValues {
|
2022-07-25 10:00:55 +10:00
|
|
|
fn format(&self, url: &str) -> String {
|
2023-08-29 11:41:40 +10:00
|
|
|
let url = url.replace("{}", &self.powerwall_id.0.to_string());
|
2022-07-25 10:00:55 +10:00
|
|
|
let mut pairs: Vec<(&str, String)> = vec![
|
|
|
|
("period", self.period.to_string()),
|
|
|
|
("kind", self.kind.to_string()),
|
|
|
|
];
|
|
|
|
if let Some(start_date) = self.start_date {
|
|
|
|
let start_date = rfc3339(&start_date);
|
|
|
|
pairs.push(("start_date", start_date));
|
|
|
|
}
|
|
|
|
if let Some(end_date) = self.end_date {
|
|
|
|
let end_date = rfc3339(&end_date);
|
|
|
|
pairs.push(("end_date", end_date));
|
|
|
|
}
|
|
|
|
format!("{}?{}", url, join_query_pairs(&pairs))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
|
pub struct PowerwallEnergyHistory {}
|