drive state, bump
This commit is contained in:
parent
1b042f6c94
commit
07deeeddc7
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2256,7 +2256,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tesla-charge-controller"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"chrono",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tesla-charge-controller"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
edition = "2021"
|
||||
license = "MITNFA"
|
||||
description = "Controls Tesla charge rate based on solar charge data"
|
||||
|
|
|
@ -12,7 +12,10 @@ use teslatte::{
|
|||
FleetApi, FleetVehicleApi,
|
||||
};
|
||||
|
||||
use crate::{errors::*, types::CarState};
|
||||
use crate::{
|
||||
errors::*,
|
||||
types::{CarState, FromDriveState},
|
||||
};
|
||||
|
||||
struct Metrics {
|
||||
battery_level: Gauge,
|
||||
|
@ -163,7 +166,6 @@ struct MonitoredValues {
|
|||
cop_state: String,
|
||||
climate_keeper: String,
|
||||
hvac_auto: String,
|
||||
shift_state: Option<String>,
|
||||
speed: Option<i64>,
|
||||
}
|
||||
|
||||
|
@ -285,7 +287,10 @@ impl TeslaInterface {
|
|||
}
|
||||
if let Some(new_location_data) = new_state.location_data {
|
||||
state.location_data = Some(new_location_data);
|
||||
self.metrics.drive_power.set(new_location_data.power as f64);
|
||||
}
|
||||
if let Some(new_drive_state) = new_state.drive_state {
|
||||
self.metrics.drive_power.set(new_drive_state.power as f64);
|
||||
state.drive_state = Some(new_drive_state);
|
||||
}
|
||||
if let Some(new_climate_state) = new_state.climate_state {
|
||||
self.metrics.inside_temp.set(new_climate_state.inside_temp);
|
||||
|
@ -366,7 +371,7 @@ impl TeslaInterface {
|
|||
v.into()
|
||||
});
|
||||
|
||||
let location_data = self
|
||||
let (location_data, drive_state) = self
|
||||
.api
|
||||
.vehicle_data(&GetVehicleData {
|
||||
vehicle_id: self.vehicle.id,
|
||||
|
@ -375,16 +380,13 @@ impl TeslaInterface {
|
|||
.await?
|
||||
.drive_state
|
||||
.and_then(|v| {
|
||||
if self.monitored_values.shift_state != v.shift_state {
|
||||
log::warn!("Current shift state: \"{:?}\"", v.shift_state);
|
||||
self.monitored_values.shift_state = v.shift_state.clone();
|
||||
}
|
||||
if self.monitored_values.speed != v.speed {
|
||||
log::warn!("Current speed: \"{:?}\"", v.speed);
|
||||
self.monitored_values.speed = v.speed;
|
||||
}
|
||||
v.try_into().ok()
|
||||
});
|
||||
})
|
||||
.map_or((None, None), |FromDriveState(a, b)| (Some(a), Some(b)));
|
||||
|
||||
let climate_state = self
|
||||
.api
|
||||
|
@ -417,6 +419,7 @@ impl TeslaInterface {
|
|||
charge_state,
|
||||
location_data,
|
||||
climate_state,
|
||||
drive_state,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
30
src/types.rs
30
src/types.rs
|
@ -1,6 +1,6 @@
|
|||
use chrono::DateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use teslatte::vehicles::ChargingState;
|
||||
use teslatte::vehicles::{ChargingState, ShiftState};
|
||||
|
||||
use crate::{config::access_config, errors::TeslaStateParseError};
|
||||
|
||||
|
@ -9,6 +9,7 @@ pub struct CarState {
|
|||
pub charge_state: Option<ChargeState>,
|
||||
pub location_data: Option<LocationData>,
|
||||
pub climate_state: Option<ClimateState>,
|
||||
pub drive_state: Option<DriveState>,
|
||||
}
|
||||
|
||||
impl CarState {
|
||||
|
@ -82,14 +83,22 @@ impl From<teslatte::vehicles::ChargeState> for ChargeState {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct FromDriveState(pub LocationData, pub DriveState);
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
||||
pub struct LocationData {
|
||||
pub gps_as_of: DateTime<chrono::Utc>,
|
||||
pub home: bool,
|
||||
pub power: i64,
|
||||
}
|
||||
|
||||
impl TryFrom<teslatte::vehicles::DriveState> for LocationData {
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
||||
pub struct DriveState {
|
||||
pub power: i64,
|
||||
pub speed: i64,
|
||||
pub shift_state: ShiftState,
|
||||
}
|
||||
|
||||
impl TryFrom<teslatte::vehicles::DriveState> for FromDriveState {
|
||||
type Error = TeslaStateParseError;
|
||||
|
||||
fn try_from(value: teslatte::vehicles::DriveState) -> Result<Self, Self::Error> {
|
||||
|
@ -104,11 +113,16 @@ impl TryFrom<teslatte::vehicles::DriveState> for LocationData {
|
|||
};
|
||||
let home = coords.overlaps(&access_config().coords);
|
||||
let power = value.power;
|
||||
Ok(Self {
|
||||
gps_as_of,
|
||||
home,
|
||||
power,
|
||||
})
|
||||
let speed = value.speed.unwrap_or(0);
|
||||
let shift_state = value.shift_state;
|
||||
Ok(Self(
|
||||
LocationData { gps_as_of, home },
|
||||
DriveState {
|
||||
power,
|
||||
speed,
|
||||
shift_state,
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 636c5fc4821286555cdab311dd520cd0d08965ce
|
||||
Subproject commit cd1ba77cf469693b707b21cc8f995c2decc768aa
|
Loading…
Reference in a new issue