log tesla online

This commit is contained in:
Alex Janka 2024-01-10 20:30:27 +11:00
parent 288faf6212
commit 3d7e33a154
3 changed files with 11 additions and 3 deletions

2
Cargo.lock generated
View file

@ -2262,7 +2262,7 @@ dependencies = [
[[package]] [[package]]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "0.1.12-prerelease" version = "0.1.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-channel", "async-channel",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "0.1.12-prerelease" version = "0.1.12"
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

@ -21,6 +21,7 @@ struct Metrics {
inside_temp: Gauge, inside_temp: Gauge,
outside_temp: Gauge, outside_temp: Gauge,
battery_heater: Gauge, battery_heater: Gauge,
tesla_online: Gauge,
} }
impl Metrics { impl Metrics {
@ -37,6 +38,8 @@ impl Metrics {
let outside_temp = gauge!("tesla_outside_temp"); let outside_temp = gauge!("tesla_outside_temp");
describe_gauge!("tesla_battery_heater", "Battery heater"); describe_gauge!("tesla_battery_heater", "Battery heater");
let battery_heater = gauge!("tesla_battery_heater"); let battery_heater = gauge!("tesla_battery_heater");
describe_gauge!("tesla_online", "Tesla online");
let tesla_online = gauge!("tesla_online");
Self { Self {
battery_level, battery_level,
@ -45,6 +48,7 @@ impl Metrics {
inside_temp, inside_temp,
outside_temp, outside_temp,
battery_heater, battery_heater,
tesla_online,
} }
} }
} }
@ -136,6 +140,7 @@ impl TeslaInterface {
async fn refresh_state(&mut self) { async fn refresh_state(&mut self) {
match get_state(&self.api, self.vehicle.id, &mut self.last_cop_state).await { match get_state(&self.api, self.vehicle.id, &mut self.last_cop_state).await {
Ok(new_state) => { Ok(new_state) => {
self.metrics.tesla_online.set(1.);
self.last_refresh = Instant::now(); self.last_refresh = Instant::now();
let mut state = self.state.write().expect("State handler panicked!!"); let mut state = self.state.write().expect("State handler panicked!!");
@ -167,7 +172,10 @@ impl TeslaInterface {
state.climate_state = Some(new_climate_state); 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:#?}")
}
} }
} }