dont yell about offline or asleep error messages + reduce key refresh interval

This commit is contained in:
Alex Janka 2024-01-11 08:16:12 +11:00
parent 3d7e33a154
commit c3469e5259
3 changed files with 14 additions and 4 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" version = "0.1.13"
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" version = "0.1.13"
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

@ -75,7 +75,7 @@ pub enum InterfaceRequest {
FlashLights, 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 { impl TeslaInterface {
pub async fn load(auth_path: PathBuf) -> Result<Self, AuthLoadError> { pub async fn load(auth_path: PathBuf) -> Result<Self, AuthLoadError> {
@ -174,6 +174,16 @@ impl TeslaInterface {
} }
Err(e) => { Err(e) => {
self.metrics.tesla_online.set(0.); 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:#?}") error!("Error getting state: {e:#?}")
} }
} }
@ -200,7 +210,7 @@ async fn get_state(
api: &FleetApi, api: &FleetApi,
vehicle_id: VehicleId, vehicle_id: VehicleId,
last_cop_state: &mut String, last_cop_state: &mut String,
) -> Result<CarState> { ) -> Result<CarState, RequestError> {
// Endpoint::VehicleDataCombo or multiple Endpoints in one request // Endpoint::VehicleDataCombo or multiple Endpoints in one request
// doesn't seem to reliably get them all, // doesn't seem to reliably get them all,
// so for each endpoint we do a new request // so for each endpoint we do a new request