Energy actor shall never fail
This commit is contained in:
		@@ -40,7 +40,7 @@ impl EnergyActor {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        let devices_list = self.devices.full_list();
 | 
					        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)?;
 | 
					        self.engine.persist_relays_state(&devices_list)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -169,11 +169,8 @@ impl EnergyEngine {
 | 
				
			|||||||
        curr_consumption - sum_relays_consumption(&self.relays_state, devices) as i32
 | 
					        curr_consumption - sum_relays_consumption(&self.relays_state, devices) as i32
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn refresh(
 | 
					    /// Refresh energy engine; this method shall never fail !
 | 
				
			||||||
        &mut self,
 | 
					    pub fn refresh(&mut self, curr_consumption: EnergyConsumption, devices: &[Device]) {
 | 
				
			||||||
        curr_consumption: EnergyConsumption,
 | 
					 | 
				
			||||||
        devices: &[Device],
 | 
					 | 
				
			||||||
    ) -> anyhow::Result<()> {
 | 
					 | 
				
			||||||
        let base_production = self.estimated_consumption_without_relays(curr_consumption, devices);
 | 
					        let base_production = self.estimated_consumption_without_relays(curr_consumption, devices);
 | 
				
			||||||
        log::info!("Estimated base production: {base_production}");
 | 
					        log::info!("Estimated base production: {base_production}");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -278,11 +275,12 @@ impl EnergyEngine {
 | 
				
			|||||||
                    continue;
 | 
					                    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 start_time = time_start_day + constraints.reset_time as u64;
 | 
				
			||||||
                let end_time = time_start_day + 3600 * 24 + constraints.reset_time as u64;
 | 
					                let end_time = time_start_day + 3600 * 24 + constraints.reset_time as u64;
 | 
				
			||||||
                let total_runtime =
 | 
					                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 {
 | 
					                if total_runtime > constraints.min_runtime {
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
@@ -357,8 +355,6 @@ impl EnergyEngine {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.print_summary(curr_consumption, devices);
 | 
					        self.print_summary(curr_consumption, devices);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        Ok(())
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Save relays state to disk
 | 
					    /// Save relays state to disk
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user