more charge state logging

This commit is contained in:
Alex Janka 2024-01-15 15:47:13 +11:00
parent 48b9b02b92
commit 0b5ca36bae
4 changed files with 26 additions and 2 deletions

2
Cargo.lock generated
View file

@ -2256,7 +2256,7 @@ dependencies = [
[[package]] [[package]]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "0.2.6" version = "0.2.7"
dependencies = [ dependencies = [
"async-channel", "async-channel",
"chrono", "chrono",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "0.2.6" version = "0.2.7"
edition = "2021" edition = "2021"
license = "MITNFA" license = "MITNFA"
description = "Controls Tesla charge rate based on solar charge data" description = "Controls Tesla charge rate based on solar charge data"

View file

@ -17,6 +17,8 @@ struct Metrics {
battery_level: Gauge, battery_level: Gauge,
charge_rate: Gauge, charge_rate: Gauge,
charge_request: Gauge, charge_request: Gauge,
charge_enable_request: Gauge,
charger_connected: Gauge,
inside_temp: Gauge, inside_temp: Gauge,
outside_temp: Gauge, outside_temp: Gauge,
battery_heater: Gauge, battery_heater: Gauge,
@ -34,6 +36,10 @@ impl Metrics {
let charge_rate = gauge!("tesla_charge_rate"); let charge_rate = gauge!("tesla_charge_rate");
describe_gauge!("tesla_charge_request", "Requested charge rate"); describe_gauge!("tesla_charge_request", "Requested charge rate");
let charge_request = gauge!("tesla_charge_request"); let charge_request = gauge!("tesla_charge_request");
describe_gauge!("tesla_charge_enable_request", "Charge enable request");
let charge_enable_request = gauge!("tesla_charge_enable_request");
describe_gauge!("tesla_charger_connected", "Charger connected");
let charger_connected = gauge!("tesla_charger_connected");
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"); describe_gauge!("tesla_outside_temp", "Outside temperature");
@ -56,6 +62,8 @@ impl Metrics {
battery_level, battery_level,
charge_rate, charge_rate,
charge_request, charge_request,
charge_enable_request,
charger_connected,
inside_temp, inside_temp,
outside_temp, outside_temp,
battery_heater, battery_heater,
@ -74,6 +82,7 @@ pub struct TeslaInterface {
last_refresh: Instant, last_refresh: Instant,
auth_path: PathBuf, auth_path: PathBuf,
metrics: Metrics, metrics: Metrics,
last_charging_state: String,
last_conn_charge_cable: String, last_conn_charge_cable: String,
last_cop_state: String, last_cop_state: String,
last_climate_keeper: String, last_climate_keeper: String,
@ -121,6 +130,7 @@ impl TeslaInterface {
auth_path, auth_path,
vehicle, vehicle,
metrics, metrics,
last_charging_state: String::new(),
last_conn_charge_cable: String::new(), last_conn_charge_cable: String::new(),
last_cop_state: String::new(), last_cop_state: String::new(),
last_climate_keeper: String::new(), last_climate_keeper: String::new(),
@ -174,6 +184,12 @@ impl TeslaInterface {
self.metrics self.metrics
.charge_request .charge_request
.set(new_charge_state.charge_current_request as f64); .set(new_charge_state.charge_current_request as f64);
self.metrics
.charge_enable_request
.set(bf(new_charge_state.charge_enable_request));
self.metrics
.charger_connected
.set(bf(new_charge_state.charger_connected));
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 {
@ -196,6 +212,7 @@ impl TeslaInterface {
self.metrics self.metrics
.remote_heater_control_enabled .remote_heater_control_enabled
.set(bf(new_climate_state.remote_heater_control_enabled)); .set(bf(new_climate_state.remote_heater_control_enabled));
state.climate_state = Some(new_climate_state); state.climate_state = Some(new_climate_state);
} }
} }
@ -265,6 +282,10 @@ impl TeslaInterface {
log::warn!("Current conn charge cable: \"{}\"", v.conn_charge_cable); log::warn!("Current conn charge cable: \"{}\"", v.conn_charge_cable);
self.last_conn_charge_cable = v.conn_charge_cable.clone(); self.last_conn_charge_cable = v.conn_charge_cable.clone();
} }
if self.last_charging_state != v.charging_state {
log::warn!("Current charging state: \"{}\"", v.charging_state);
self.last_charging_state = v.charging_state.clone();
}
v.into() v.into()
}); });

View file

@ -43,6 +43,7 @@ pub struct ChargeState {
pub charge_rate: f64, pub charge_rate: f64,
pub charge_current_request: i64, pub charge_current_request: i64,
pub charge_current_request_max: i64, pub charge_current_request_max: i64,
pub charger_connected: bool,
pub charge_enable_request: bool, pub charge_enable_request: bool,
pub charge_limit_soc: i64, pub charge_limit_soc: i64,
} }
@ -56,6 +57,7 @@ impl ChargeState {
impl From<teslatte::vehicles::ChargeState> for ChargeState { impl From<teslatte::vehicles::ChargeState> for ChargeState {
fn from(value: teslatte::vehicles::ChargeState) -> Self { fn from(value: teslatte::vehicles::ChargeState) -> Self {
let charger_connected = value.conn_charge_cable == "<invalid>";
ChargeState { ChargeState {
battery_level: value.battery_level, battery_level: value.battery_level,
battery_range: value.battery_range, battery_range: value.battery_range,
@ -63,6 +65,7 @@ impl From<teslatte::vehicles::ChargeState> for ChargeState {
charge_rate: value.charge_rate, charge_rate: value.charge_rate,
charge_current_request: value.charge_current_request, charge_current_request: value.charge_current_request,
charge_current_request_max: value.charge_current_request_max, charge_current_request_max: value.charge_current_request_max,
charger_connected,
charge_enable_request: value.charge_enable_request, charge_enable_request: value.charge_enable_request,
charge_limit_soc: value.charge_limit_soc, charge_limit_soc: value.charge_limit_soc,
} }