Start to implement devices enrollment

This commit is contained in:
2024-07-01 21:10:45 +02:00
parent 378c296e71
commit 9ba4aa5194
21 changed files with 267 additions and 16 deletions

View File

@ -1,16 +1,20 @@
use crate::constants;
use crate::devices::device::DeviceId;
use crate::devices::devices_list::DevicesList;
use crate::energy::consumption;
use crate::energy::consumption::EnergyConsumption;
use actix::prelude::*;
pub struct EnergyActor {
curr_consumption: EnergyConsumption,
devices: DevicesList,
}
impl EnergyActor {
pub async fn new() -> anyhow::Result<Self> {
Ok(Self {
curr_consumption: consumption::get_curr_consumption().await?,
devices: DevicesList::load()?,
})
}
@ -62,3 +66,16 @@ impl Handler<GetCurrConsumption> for EnergyActor {
self.curr_consumption
}
}
/// Get current consumption
#[derive(Message)]
#[rtype(result = "bool")]
pub struct CheckDeviceExists(DeviceId);
impl Handler<CheckDeviceExists> for EnergyActor {
type Result = bool;
fn handle(&mut self, msg: CheckDeviceExists, _ctx: &mut Context<Self>) -> Self::Result {
self.devices.exists(&msg.0)
}
}