Can set forced state to relays
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::energy::consumption;
|
||||
use crate::energy::consumption::EnergyConsumption;
|
||||
use crate::energy::consumption_cache::ConsumptionCache;
|
||||
use crate::energy::consumption_history_file::ConsumptionHistoryFile;
|
||||
use crate::energy::engine::EnergyEngine;
|
||||
use crate::energy::engine::{EnergyEngine, RelayForcedState};
|
||||
use crate::utils::time_utils::time_secs;
|
||||
use actix::prelude::*;
|
||||
use openssl::x509::X509Req;
|
||||
@@ -328,6 +328,19 @@ impl Handler<UpdateDeviceRelay> for EnergyActor {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct SetRelayForcedState(pub DeviceRelayID, pub RelayForcedState);
|
||||
|
||||
impl Handler<SetRelayForcedState> for EnergyActor {
|
||||
type Result = anyhow::Result<()>;
|
||||
|
||||
fn handle(&mut self, msg: SetRelayForcedState, _ctx: &mut Context<Self>) -> Self::Result {
|
||||
self.engine.relay_state(msg.0).set_forced(msg.1);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete a device relay
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
@@ -408,6 +421,7 @@ pub struct ResRelayState {
|
||||
pub id: DeviceRelayID,
|
||||
pub on: bool,
|
||||
pub r#for: usize,
|
||||
pub forced_state: RelayForcedState,
|
||||
}
|
||||
|
||||
/// Get the state of all relays
|
||||
@@ -427,6 +441,7 @@ impl Handler<GetAllRelaysState> for EnergyActor {
|
||||
id: d.id,
|
||||
on: state.is_on(),
|
||||
r#for: state.state_for(),
|
||||
forced_state: state.actual_forced_state(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user