Energy actor shall never fail

This commit is contained in:
Pierre HUBERT 2024-09-19 21:29:31 +02:00
parent fe0bc03c03
commit 719b0a0c5c
2 changed files with 6 additions and 10 deletions

View File

@ -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)?;

View File

@ -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