more data

This commit is contained in:
Alex Janka 2024-01-09 12:06:18 +11:00
parent 859326c132
commit f3018ee9ba
2 changed files with 33 additions and 1 deletions

View file

@ -18,7 +18,10 @@ use crate::{errors::*, types::CarState};
struct Metrics { struct Metrics {
battery_level: Gauge, battery_level: Gauge,
charge_rate: Gauge, charge_rate: Gauge,
charge_request: Gauge,
inside_temp: Gauge, inside_temp: Gauge,
outside_temp: Gauge,
battery_heater: Gauge,
} }
impl Metrics { impl Metrics {
@ -29,14 +32,23 @@ impl Metrics {
let battery_level = gauge!("tesla_battery_level"); let battery_level = gauge!("tesla_battery_level");
describe_gauge!("tesla_charge_rate", "Charge rate"); describe_gauge!("tesla_charge_rate", "Charge rate");
let charge_rate = gauge!("tesla_charge_rate"); let charge_rate = gauge!("tesla_charge_rate");
describe_gauge!("tesla_charge_request", "Requested charge rate");
let charge_request = gauge!("tesla_charge_request");
describe_gauge!("tesla_inside_temp", "Inside temperature"); describe_gauge!("tesla_inside_temp", "Inside temperature");
let inside_temp = gauge!("tesla_inside_temp"); let inside_temp = gauge!("tesla_inside_temp");
describe_gauge!("tesla_outside_temp", "Outside temperature");
let outside_temp = gauge!("tesla_outside_temp");
describe_gauge!("tesla_battery_heater", "Battery heater");
let battery_heater = gauge!("tesla_battery_heater");
( (
Self { Self {
battery_level, battery_level,
charge_rate, charge_rate,
charge_request,
inside_temp, inside_temp,
outside_temp,
battery_heater,
}, },
recorder, recorder,
) )
@ -136,6 +148,9 @@ impl TeslaInterface {
.battery_level .battery_level
.set(new_charge_state.battery_level as f64); .set(new_charge_state.battery_level as f64);
self.metrics.charge_rate.set(new_charge_state.charge_rate); self.metrics.charge_rate.set(new_charge_state.charge_rate);
self.metrics
.charge_request
.set(new_charge_state.charge_current_request as f64);
state.charge_state = Some(new_charge_state); state.charge_state = Some(new_charge_state);
} }
if let Some(new_location_data) = new_state.location_data { if let Some(new_location_data) = new_state.location_data {
@ -143,6 +158,16 @@ impl TeslaInterface {
} }
if let Some(new_climate_state) = new_state.climate_state { if let Some(new_climate_state) = new_state.climate_state {
self.metrics.inside_temp.set(new_climate_state.inside_temp); self.metrics.inside_temp.set(new_climate_state.inside_temp);
self.metrics
.outside_temp
.set(new_climate_state.outside_temp);
self.metrics
.battery_heater
.set(if new_climate_state.battery_heater {
1.0
} else {
0.0
});
state.climate_state = Some(new_climate_state); state.climate_state = Some(new_climate_state);
} }
} }

View file

@ -12,6 +12,8 @@ pub struct CarState {
#[derive(Clone, Copy, Serialize, Deserialize, Debug)] #[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct ClimateState { pub struct ClimateState {
pub inside_temp: f64, pub inside_temp: f64,
pub outside_temp: f64,
pub battery_heater: bool,
} }
impl TryFrom<teslatte::vehicles::ClimateState> for ClimateState { impl TryFrom<teslatte::vehicles::ClimateState> for ClimateState {
@ -26,7 +28,12 @@ impl TryFrom<teslatte::vehicles::ClimateState> for ClimateState {
Ok(Self { Ok(Self {
inside_temp: value inside_temp: value
.inside_temp .inside_temp
.context("no temperature in climate data")?, .context("no inside temperature in climate data")?,
outside_temp: value
.outside_temp
.context("no outside temperature in climate data")?,
battery_heater: value.battery_heater,
}) })
} }
} }