From 73b3a90462ad659c0f2a2721061c2f07ad679a20 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Tue, 23 Jan 2024 15:31:27 +1100 Subject: [PATCH] log some more fields --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/api_interface.rs | 36 ++++++++++++++++++++++++++++++++++++ src/types.rs | 10 ++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9406a24..7a6ab1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2633,7 +2633,7 @@ dependencies = [ [[package]] name = "tesla-charge-controller" -version = "1.0.26" +version = "1.0.27" dependencies = [ "chrono", "clap 4.4.11", diff --git a/Cargo.toml b/Cargo.toml index c0e34b6..70e2d9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tesla-charge-controller" -version = "1.0.26" +version = "1.0.27" edition = "2021" license = "MITNFA" description = "Controls Tesla charge rate based on solar charge data" diff --git a/src/api_interface.rs b/src/api_interface.rs index b74e8c2..75a8dfa 100644 --- a/src/api_interface.rs +++ b/src/api_interface.rs @@ -42,6 +42,11 @@ struct Metrics { home: Gauge, sentry_mode: Gauge, sentry_mode_available: Gauge, + charger_actual_current: Gauge, + charger_phases: Gauge, + charger_pilot_current: Gauge, + charger_power: Gauge, + charger_voltage: Gauge, } impl Metrics { @@ -95,6 +100,17 @@ impl Metrics { describe_gauge!("tesla_sentry_mode_available", "Sentry mode available"); let sentry_mode_available = gauge!("tesla_sentry_mode_available"); + describe_gauge!("tesla_charger_actual_current", "Charger actual current"); + let charger_actual_current = gauge!("tesla_charger_actual_current"); + describe_gauge!("tesla_charger_phases", "Charger phases"); + let charger_phases = gauge!("tesla_charger_phases"); + describe_gauge!("tesla_charger_pilot_current", "Charger pilot current"); + let charger_pilot_current = gauge!("tesla_charger_pilot_current"); + describe_gauge!("tesla_charger_power", "Charger power"); + let charger_power = gauge!("tesla_charger_power"); + describe_gauge!("tesla_charger_voltage", "Charger voltage"); + let charger_voltage = gauge!("tesla_charger_voltage"); + Self { battery_level, charge_rate, @@ -117,6 +133,11 @@ impl Metrics { home, sentry_mode, sentry_mode_available, + charger_actual_current, + charger_phases, + charger_pilot_current, + charger_power, + charger_voltage, } } } @@ -425,6 +446,21 @@ impl TeslaInterface { self.metrics .charging_state .set(new_charge_state.charging_state); + if let Some(v) = new_charge_state.charger_actual_current { + self.metrics.charger_actual_current.set(v as f64); + } + if let Some(v) = new_charge_state.charger_phases { + self.metrics.charger_phases.set(v as f64); + } + if let Some(v) = new_charge_state.charger_pilot_current { + self.metrics.charger_pilot_current.set(v as f64); + } + if let Some(v) = new_charge_state.charger_power { + self.metrics.charger_power.set(v as f64); + } + if let Some(v) = new_charge_state.charger_voltage { + self.metrics.charger_voltage.set(v as f64); + } state.charge_state = Some(new_charge_state); } if let Some(new_location_data) = new_state.location_data { diff --git a/src/types.rs b/src/types.rs index 77b7e64..f820f31 100644 --- a/src/types.rs +++ b/src/types.rs @@ -82,6 +82,11 @@ pub struct ChargeState { pub charge_enable_request: bool, pub charging_state: ChargingState, pub charge_limit_soc: i64, + pub charger_actual_current: Option, + pub charger_phases: Option, + pub charger_pilot_current: Option, + pub charger_power: Option, + pub charger_voltage: Option, } impl From for ChargeState { @@ -97,6 +102,11 @@ impl From for ChargeState { charge_enable_request: value.charge_enable_request, charging_state: value.charging_state, charge_limit_soc: value.charge_limit_soc, + charger_actual_current: value.charger_actual_current, + charger_phases: value.charger_phases, + charger_pilot_current: value.charger_pilot_current, + charger_power: value.charger_power, + charger_voltage: value.charger_voltage, } } }