From 3d7e33a1540aa1dc9438ce2495f701755b43b7f9 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 10 Jan 2024 20:30:27 +1100 Subject: [PATCH] log tesla online --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/api_interface.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e57abb..8e30cc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2262,7 +2262,7 @@ dependencies = [ [[package]] name = "tesla-charge-controller" -version = "0.1.12-prerelease" +version = "0.1.12" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index 3a49823..f732757 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tesla-charge-controller" -version = "0.1.12-prerelease" +version = "0.1.12" 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 d504713..0d88a64 100644 --- a/src/api_interface.rs +++ b/src/api_interface.rs @@ -21,6 +21,7 @@ struct Metrics { inside_temp: Gauge, outside_temp: Gauge, battery_heater: Gauge, + tesla_online: Gauge, } impl Metrics { @@ -37,6 +38,8 @@ impl Metrics { let outside_temp = gauge!("tesla_outside_temp"); describe_gauge!("tesla_battery_heater", "Battery heater"); let battery_heater = gauge!("tesla_battery_heater"); + describe_gauge!("tesla_online", "Tesla online"); + let tesla_online = gauge!("tesla_online"); Self { battery_level, @@ -45,6 +48,7 @@ impl Metrics { inside_temp, outside_temp, battery_heater, + tesla_online, } } } @@ -136,6 +140,7 @@ impl TeslaInterface { async fn refresh_state(&mut self) { match get_state(&self.api, self.vehicle.id, &mut self.last_cop_state).await { Ok(new_state) => { + self.metrics.tesla_online.set(1.); self.last_refresh = Instant::now(); let mut state = self.state.write().expect("State handler panicked!!"); @@ -167,7 +172,10 @@ impl TeslaInterface { state.climate_state = Some(new_climate_state); } } - Err(e) => error!("Error getting state: {e:#?}"), + Err(e) => { + self.metrics.tesla_online.set(0.); + error!("Error getting state: {e:#?}") + } } }