Start to implement devices enrollment
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user