Complete enroll route

This commit is contained in:
2024-07-02 22:55:51 +02:00
parent e64a444bd0
commit 01ffe085d7
8 changed files with 121 additions and 23 deletions

View File

@ -1,9 +1,10 @@
use crate::constants;
use crate::devices::device::DeviceId;
use crate::devices::device::{DeviceId, DeviceInfo};
use crate::devices::devices_list::DevicesList;
use crate::energy::consumption;
use crate::energy::consumption::EnergyConsumption;
use actix::prelude::*;
use openssl::x509::X509Req;
pub struct EnergyActor {
curr_consumption: EnergyConsumption,
@ -79,3 +80,16 @@ impl Handler<CheckDeviceExists> for EnergyActor {
self.devices.exists(&msg.0)
}
}
/// Enroll device
#[derive(Message)]
#[rtype(result = "anyhow::Result<()>")]
pub struct EnrollDevice(pub DeviceId, pub DeviceInfo, pub X509Req);
impl Handler<EnrollDevice> for EnergyActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: EnrollDevice, _ctx: &mut Context<Self>) -> Self::Result {
self.devices.enroll(&msg.0, &msg.1, &msg.2)
}
}