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