only log changes in cop state
This commit is contained in:
parent
f3018ee9ba
commit
2c0a0480cd
|
@ -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<CarState> {
|
||||
async fn get_state(
|
||||
api: &FleetApi,
|
||||
vehicle_id: VehicleId,
|
||||
last_cop_state: &mut String,
|
||||
) -> Result<CarState> {
|
||||
// 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<CarState> {
|
|||
})
|
||||
.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,
|
||||
|
|
|
@ -20,11 +20,6 @@ impl TryFrom<teslatte::vehicles::ClimateState> for ClimateState {
|
|||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: teslatte::vehicles::ClimateState) -> Result<Self, Self::Error> {
|
||||
log::info!(
|
||||
"Current cabin overheat protection state: {}",
|
||||
value.cabin_overheat_protection
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
inside_temp: value
|
||||
.inside_temp
|
||||
|
|
Loading…
Reference in a new issue