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,55 +219,62 @@ impl TeslaInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
async fn get_state(&mut self) -> Result<CarState, RequestError> {
|
||||||
async fn get_state(
|
// Endpoint::VehicleDataCombo or multiple Endpoints in one request
|
||||||
api: &FleetApi,
|
// doesn't seem to reliably get them all,
|
||||||
vehicle_id: VehicleId,
|
// so for each endpoint we do a new request
|
||||||
last_cop_state: &mut String,
|
let charge_state = self
|
||||||
) -> Result<CarState, RequestError> {
|
.api
|
||||||
// Endpoint::VehicleDataCombo or multiple Endpoints in one request
|
.vehicle_data(&GetVehicleData {
|
||||||
// doesn't seem to reliably get them all,
|
vehicle_id: self.vehicle.id,
|
||||||
// so for each endpoint we do a new request
|
endpoints: vec![Endpoint::ChargeState].into(),
|
||||||
let charge_state = api
|
})
|
||||||
.vehicle_data(&GetVehicleData {
|
.await?
|
||||||
vehicle_id,
|
.charge_state
|
||||||
endpoints: vec![Endpoint::ChargeState].into(),
|
.map(|v| v.into());
|
||||||
})
|
|
||||||
.await?
|
let location_data = self
|
||||||
.charge_state
|
.api
|
||||||
.map(|v| v.into());
|
.vehicle_data(&GetVehicleData {
|
||||||
|
vehicle_id: self.vehicle.id,
|
||||||
let location_data = api
|
endpoints: vec![Endpoint::LocationData].into(),
|
||||||
.vehicle_data(&GetVehicleData {
|
})
|
||||||
vehicle_id,
|
.await?
|
||||||
endpoints: vec![Endpoint::LocationData].into(),
|
.drive_state
|
||||||
})
|
.and_then(|v| v.try_into().ok());
|
||||||
.await?
|
|
||||||
.drive_state
|
let climate_state = self
|
||||||
.and_then(|v| v.try_into().ok());
|
.api
|
||||||
|
.vehicle_data(&GetVehicleData {
|
||||||
let climate_state = api
|
vehicle_id: self.vehicle.id,
|
||||||
.vehicle_data(&GetVehicleData {
|
endpoints: vec![Endpoint::ClimateState].into(),
|
||||||
vehicle_id,
|
})
|
||||||
endpoints: vec![Endpoint::ClimateState].into(),
|
.await?
|
||||||
})
|
.climate_state
|
||||||
.await?
|
.and_then(|v| {
|
||||||
.climate_state
|
if self.last_cop_state != v.cabin_overheat_protection {
|
||||||
.and_then(|v| {
|
log::warn!(
|
||||||
if *last_cop_state != v.cabin_overheat_protection {
|
"Current cabin overheat protection state: {}",
|
||||||
log::warn!(
|
v.cabin_overheat_protection
|
||||||
"Current cabin overheat protection state: {}",
|
);
|
||||||
v.cabin_overheat_protection
|
self.last_cop_state = v.cabin_overheat_protection.clone();
|
||||||
);
|
}
|
||||||
*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);
|
||||||
v.try_into().ok()
|
self.last_climate_keeper = v.climate_keeper_mode.clone();
|
||||||
});
|
}
|
||||||
|
if self.last_hvac_auto != v.hvac_auto_request {
|
||||||
Ok(CarState {
|
log::warn!("HVAC auto request set to: {}", v.hvac_auto_request);
|
||||||
charge_state,
|
self.last_hvac_auto = v.hvac_auto_request.clone();
|
||||||
location_data,
|
}
|
||||||
climate_state,
|
v.try_into().ok()
|
||||||
})
|
});
|
||||||
|
|
||||||
|
Ok(CarState {
|
||||||
|
charge_state,
|
||||||
|
location_data,
|
||||||
|
climate_state,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue