Can create a relay
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
			
		||||
use crate::constants;
 | 
			
		||||
use crate::devices::device::{Device, DeviceGeneralInfo, DeviceId, DeviceInfo, DeviceRelay};
 | 
			
		||||
use crate::devices::device::{
 | 
			
		||||
    Device, DeviceGeneralInfo, DeviceId, DeviceInfo, DeviceRelay, DeviceRelayID,
 | 
			
		||||
};
 | 
			
		||||
use crate::devices::devices_list::DevicesList;
 | 
			
		||||
use crate::energy::consumption;
 | 
			
		||||
use crate::energy::consumption::EnergyConsumption;
 | 
			
		||||
@@ -184,3 +186,29 @@ impl Handler<GetRelaysList> for EnergyActor {
 | 
			
		||||
        self.devices.relays_list()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Create a new device relay
 | 
			
		||||
#[derive(Message)]
 | 
			
		||||
#[rtype(result = "anyhow::Result<()>")]
 | 
			
		||||
pub struct CreateDeviceRelay(pub DeviceId, pub DeviceRelay);
 | 
			
		||||
 | 
			
		||||
impl Handler<CreateDeviceRelay> for EnergyActor {
 | 
			
		||||
    type Result = anyhow::Result<()>;
 | 
			
		||||
 | 
			
		||||
    fn handle(&mut self, msg: CreateDeviceRelay, _ctx: &mut Context<Self>) -> Self::Result {
 | 
			
		||||
        self.devices.relay_create(&msg.0, msg.1)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get the information about a single relay
 | 
			
		||||
#[derive(Message)]
 | 
			
		||||
#[rtype(result = "Option<DeviceRelay>")]
 | 
			
		||||
pub struct GetSingleRelay(pub DeviceRelayID);
 | 
			
		||||
 | 
			
		||||
impl Handler<GetSingleRelay> for EnergyActor {
 | 
			
		||||
    type Result = Option<DeviceRelay>;
 | 
			
		||||
 | 
			
		||||
    fn handle(&mut self, msg: GetSingleRelay, _ctx: &mut Context<Self>) -> Self::Result {
 | 
			
		||||
        self.devices.relay_get_single(msg.0)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user