From 2c0a0480cda56e2f7bd805dd31a13fe4aacf5c71 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 10 Jan 2024 11:51:30 +1100 Subject: [PATCH] only log changes in cop state --- src/api_interface.rs | 23 +++++++++++++++++++---- src/types.rs | 5 ----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/api_interface.rs b/src/api_interface.rs index 3d76879..22f8696 100644 --- a/src/api_interface.rs +++ b/src/api_interface.rs @@ -62,6 +62,7 @@ pub struct TeslaInterface { last_refresh: Instant, auth_path: PathBuf, metrics: Metrics, + last_cop_state: String, } #[derive(Serialize, Deserialize, Clone)] @@ -105,6 +106,7 @@ impl TeslaInterface { auth_path, vehicle, metrics, + last_cop_state: String::new(), }; interface.save_key()?; @@ -124,7 +126,7 @@ impl TeslaInterface { } pub async fn refresh(&mut self) { - info!("refreshing keys..."); + info!("refreshing..."); self.refresh_keys().await; self.refresh_state().await; } @@ -138,7 +140,7 @@ impl TeslaInterface { } async fn refresh_state(&mut self) { - match get_state(&self.api, self.vehicle.id).await { + match get_state(&self.api, self.vehicle.id, &mut self.last_cop_state).await { Ok(new_state) => { self.last_refresh = Instant::now(); let mut state = self.state.write().expect("State handler panicked!!"); @@ -192,7 +194,11 @@ impl TeslaInterface { } } -async fn get_state(api: &FleetApi, vehicle_id: VehicleId) -> Result { +async fn get_state( + api: &FleetApi, + vehicle_id: VehicleId, + last_cop_state: &mut String, +) -> Result { // 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 @@ -221,7 +227,16 @@ async fn get_state(api: &FleetApi, vehicle_id: VehicleId) -> Result { }) .await? .climate_state - .and_then(|v| v.try_into().ok()); + .and_then(|v| { + if *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(); + } + v.try_into().ok() + }); Ok(CarState { charge_state, diff --git a/src/types.rs b/src/types.rs index 1adccf5..127a2b3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -20,11 +20,6 @@ impl TryFrom for ClimateState { type Error = anyhow::Error; fn try_from(value: teslatte::vehicles::ClimateState) -> Result { - log::info!( - "Current cabin overheat protection state: {}", - value.cabin_overheat_protection - ); - Ok(Self { inside_temp: value .inside_temp