Take relays consumption in account

This commit is contained in:
2024-09-16 22:27:43 +02:00
parent 79b2ad12d8
commit 20bc71851d
4 changed files with 81 additions and 14 deletions

View File

@ -1,3 +1,4 @@
use crate::app_config::AppConfig;
use crate::constants;
use crate::devices::device::{
Device, DeviceGeneralInfo, DeviceId, DeviceInfo, DeviceRelay, DeviceRelayID,
@ -9,6 +10,7 @@ use crate::energy::engine::EnergyEngine;
use crate::utils::time_utils::time_secs;
use actix::prelude::*;
use openssl::x509::X509Req;
use std::time::Duration;
pub struct EnergyActor {
curr_consumption: EnergyConsumption,
@ -49,12 +51,15 @@ impl Actor for EnergyActor {
fn started(&mut self, ctx: &mut Self::Context) {
log::info!("Energy actor successfully started!");
ctx.run_interval(constants::ENERGY_REFRESH_INTERVAL, |act, _ctx| {
log::info!("Performing energy refresh operation");
if let Err(e) = futures::executor::block_on(act.refresh()) {
log::error!("Energy refresh failed! {e}")
}
});
ctx.run_interval(
Duration::from_secs(AppConfig::get().refresh_interval),
|act, _ctx| {
log::info!("Performing energy refresh operation");
if let Err(e) = futures::executor::block_on(act.refresh()) {
log::error!("Energy refresh failed! {e}")
}
},
);
}
fn stopped(&mut self, _ctx: &mut Self::Context) {