Store relay consumption values
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::app_config::{AppConfig, ConsumptionHistoryType};
|
||||
use crate::constants;
|
||||
use crate::devices::device::{
|
||||
Device, DeviceGeneralInfo, DeviceId, DeviceInfo, DeviceRelay, DeviceRelayID,
|
||||
@@ -53,17 +53,26 @@ impl EnergyActor {
|
||||
});
|
||||
self.consumption_cache.add_value(latest_consumption);
|
||||
|
||||
let mut history = ConsumptionHistoryFile::open(time_secs())?;
|
||||
let devices_list = self.devices.full_list();
|
||||
|
||||
let mut history =
|
||||
ConsumptionHistoryFile::open(time_secs(), ConsumptionHistoryType::GridConsumption)?;
|
||||
history.set_consumption(time_secs(), latest_consumption)?;
|
||||
history.save()?;
|
||||
|
||||
let mut relays_consumption =
|
||||
ConsumptionHistoryFile::open(time_secs(), ConsumptionHistoryType::RelayConsumption)?;
|
||||
relays_consumption.set_consumption(
|
||||
time_secs(),
|
||||
self.engine.sum_relays_consumption(&devices_list) as EnergyConsumption,
|
||||
)?;
|
||||
relays_consumption.save()?;
|
||||
|
||||
if self.last_engine_refresh + AppConfig::get().refresh_interval > time_secs() {
|
||||
return Ok(());
|
||||
}
|
||||
self.last_engine_refresh = time_secs();
|
||||
|
||||
let devices_list = self.devices.full_list();
|
||||
|
||||
self.engine
|
||||
.refresh(self.consumption_cache.median_value(), &devices_list);
|
||||
|
||||
|
Reference in New Issue
Block a user