From 719b0a0c5c98dd33381568cfbaf884944ddf71bd Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 19 Sep 2024 21:29:31 +0200 Subject: [PATCH] Energy actor shall never fail --- central_backend/src/energy/energy_actor.rs | 2 +- central_backend/src/energy/engine.rs | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/central_backend/src/energy/energy_actor.rs b/central_backend/src/energy/energy_actor.rs index 4565d07..9b677cb 100644 --- a/central_backend/src/energy/energy_actor.rs +++ b/central_backend/src/energy/energy_actor.rs @@ -40,7 +40,7 @@ impl EnergyActor { let devices_list = self.devices.full_list(); - self.engine.refresh(self.curr_consumption, &devices_list)?; + self.engine.refresh(self.curr_consumption, &devices_list); self.engine.persist_relays_state(&devices_list)?; diff --git a/central_backend/src/energy/engine.rs b/central_backend/src/energy/engine.rs index e21e1af..91035fe 100644 --- a/central_backend/src/energy/engine.rs +++ b/central_backend/src/energy/engine.rs @@ -169,11 +169,8 @@ impl EnergyEngine { curr_consumption - sum_relays_consumption(&self.relays_state, devices) as i32 } - pub fn refresh( - &mut self, - curr_consumption: EnergyConsumption, - devices: &[Device], - ) -> anyhow::Result<()> { + /// Refresh energy engine; this method shall never fail ! + pub fn refresh(&mut self, curr_consumption: EnergyConsumption, devices: &[Device]) { let base_production = self.estimated_consumption_without_relays(curr_consumption, devices); log::info!("Estimated base production: {base_production}"); @@ -278,11 +275,12 @@ impl EnergyEngine { continue; } - let time_start_day = time_start_of_day()?; + let time_start_day = time_start_of_day().unwrap_or(1726696800); let start_time = time_start_day + constraints.reset_time as u64; let end_time = time_start_day + 3600 * 24 + constraints.reset_time as u64; let total_runtime = - relay_state_history::relay_total_runtime(r.id, start_time, end_time)?; + relay_state_history::relay_total_runtime(r.id, start_time, end_time) + .unwrap_or(3600 * 24); if total_runtime > constraints.min_runtime { continue; @@ -357,8 +355,6 @@ impl EnergyEngine { } self.print_summary(curr_consumption, devices); - - Ok(()) } /// Save relays state to disk