From c3469e5259319f23d0ebc12623a49613ee9b5da2 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 11 Jan 2024 08:16:12 +1100 Subject: [PATCH] dont yell about offline or asleep error messages + reduce key refresh interval --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/api_interface.rs | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e30cc7..19daa58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2262,7 +2262,7 @@ dependencies = [ [[package]] name = "tesla-charge-controller" -version = "0.1.12" +version = "0.1.13" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index f732757..9214bbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tesla-charge-controller" -version = "0.1.12" +version = "0.1.13" 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 0d88a64..cf95982 100644 --- a/src/api_interface.rs +++ b/src/api_interface.rs @@ -75,7 +75,7 @@ pub enum InterfaceRequest { FlashLights, } -const KEY_REFRESH_INTERVAL: Duration = Duration::from_secs(12 * 60 * 60); +const KEY_REFRESH_INTERVAL: Duration = Duration::from_secs(6 * 60 * 60); impl TeslaInterface { pub async fn load(auth_path: PathBuf) -> Result { @@ -174,6 +174,16 @@ impl TeslaInterface { } Err(e) => { self.metrics.tesla_online.set(0.); + if let RequestError::Teslatte(teslatte::error::TeslatteError::DecodeJsonError { + source: _, + request: _, + body, + }) = &e + { + if body.contains("vehicle is offline or asleep") { + return; + } + } error!("Error getting state: {e:#?}") } } @@ -200,7 +210,7 @@ async fn get_state( api: &FleetApi, vehicle_id: VehicleId, last_cop_state: &mut String, -) -> Result { +) -> Result { // Endpoint::VehicleDataCombo or multiple Endpoints in one request // doesn't seem to reliably get them all, // so for each endpoint we do a new request