log climate keeper and hvac auto mode
This commit is contained in:
parent
9e3821ec29
commit
6278c92413
|
@ -8,7 +8,7 @@ use std::{
|
|||
use teslatte::{
|
||||
auth::{AccessToken, RefreshToken},
|
||||
vehicles::{Endpoint, GetVehicleData},
|
||||
FleetApi, FleetVehicleApi, VehicleId,
|
||||
FleetApi, FleetVehicleApi,
|
||||
};
|
||||
|
||||
use crate::{errors::*, types::CarState};
|
||||
|
@ -60,6 +60,8 @@ pub struct TeslaInterface {
|
|||
auth_path: PathBuf,
|
||||
metrics: Metrics,
|
||||
last_cop_state: String,
|
||||
last_climate_keeper: String,
|
||||
last_hvac_auto: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
|
@ -104,6 +106,8 @@ impl TeslaInterface {
|
|||
vehicle,
|
||||
metrics,
|
||||
last_cop_state: String::new(),
|
||||
last_climate_keeper: String::new(),
|
||||
last_hvac_auto: String::new(),
|
||||
};
|
||||
interface.save_key()?;
|
||||
|
||||
|
@ -137,7 +141,7 @@ impl TeslaInterface {
|
|||
}
|
||||
|
||||
async fn refresh_state(&mut self) {
|
||||
match get_state(&self.api, self.vehicle.id, &mut self.last_cop_state).await {
|
||||
match self.get_state().await {
|
||||
Ok(new_state) => {
|
||||
self.metrics.tesla_online.set(1.);
|
||||
let mut state = self
|
||||
|
@ -215,48 +219,54 @@ impl TeslaInterface {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_state(
|
||||
api: &FleetApi,
|
||||
vehicle_id: VehicleId,
|
||||
last_cop_state: &mut String,
|
||||
) -> Result<CarState, RequestError> {
|
||||
async fn get_state(&mut self) -> Result<CarState, RequestError> {
|
||||
// Endpoint::VehicleDataCombo or multiple Endpoints in one request
|
||||
// doesn't seem to reliably get them all,
|
||||
// so for each endpoint we do a new request
|
||||
let charge_state = api
|
||||
let charge_state = self
|
||||
.api
|
||||
.vehicle_data(&GetVehicleData {
|
||||
vehicle_id,
|
||||
vehicle_id: self.vehicle.id,
|
||||
endpoints: vec![Endpoint::ChargeState].into(),
|
||||
})
|
||||
.await?
|
||||
.charge_state
|
||||
.map(|v| v.into());
|
||||
|
||||
let location_data = api
|
||||
let location_data = self
|
||||
.api
|
||||
.vehicle_data(&GetVehicleData {
|
||||
vehicle_id,
|
||||
vehicle_id: self.vehicle.id,
|
||||
endpoints: vec![Endpoint::LocationData].into(),
|
||||
})
|
||||
.await?
|
||||
.drive_state
|
||||
.and_then(|v| v.try_into().ok());
|
||||
|
||||
let climate_state = api
|
||||
let climate_state = self
|
||||
.api
|
||||
.vehicle_data(&GetVehicleData {
|
||||
vehicle_id,
|
||||
vehicle_id: self.vehicle.id,
|
||||
endpoints: vec![Endpoint::ClimateState].into(),
|
||||
})
|
||||
.await?
|
||||
.climate_state
|
||||
.and_then(|v| {
|
||||
if *last_cop_state != v.cabin_overheat_protection {
|
||||
if self.last_cop_state != v.cabin_overheat_protection {
|
||||
log::warn!(
|
||||
"Current cabin overheat protection state: {}",
|
||||
v.cabin_overheat_protection
|
||||
);
|
||||
*last_cop_state = v.cabin_overheat_protection.clone();
|
||||
self.last_cop_state = v.cabin_overheat_protection.clone();
|
||||
}
|
||||
if self.last_climate_keeper != v.climate_keeper_mode {
|
||||
log::warn!("Current climate keeper mode: {}", v.climate_keeper_mode);
|
||||
self.last_climate_keeper = v.climate_keeper_mode.clone();
|
||||
}
|
||||
if self.last_hvac_auto != v.hvac_auto_request {
|
||||
log::warn!("HVAC auto request set to: {}", v.hvac_auto_request);
|
||||
self.last_hvac_auto = v.hvac_auto_request.clone();
|
||||
}
|
||||
v.try_into().ok()
|
||||
});
|
||||
|
@ -266,4 +276,5 @@ async fn get_state(
|
|||
location_data,
|
||||
climate_state,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue