Add new engine tests for forced state
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
use crate::devices::device::{DeviceId, DeviceRelay, DeviceRelayID};
|
||||
use crate::energy::energy_actor;
|
||||
use crate::energy::engine::RelayForcedState;
|
||||
use crate::energy::engine::SetRelayForcedStateReq;
|
||||
use crate::server::WebEnergyActor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::utils::time_utils::time_secs;
|
||||
use actix_web::{HttpResponse, web};
|
||||
|
||||
/// Get the full list of relays
|
||||
@@ -87,19 +86,6 @@ pub async fn update(
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum SetRelayForcedStateReq {
|
||||
#[default]
|
||||
None,
|
||||
Off {
|
||||
for_secs: u64,
|
||||
},
|
||||
On {
|
||||
for_secs: u64,
|
||||
},
|
||||
}
|
||||
|
||||
/// Set relay forced status
|
||||
pub async fn set_forced_state(
|
||||
actor: WebEnergyActor,
|
||||
@@ -116,15 +102,7 @@ pub async fn set_forced_state(
|
||||
actor
|
||||
.send(energy_actor::SetRelayForcedState(
|
||||
path.id,
|
||||
match &req.0 {
|
||||
SetRelayForcedStateReq::None => RelayForcedState::None,
|
||||
SetRelayForcedStateReq::Off { for_secs } => RelayForcedState::Off {
|
||||
until: time_secs() + for_secs,
|
||||
},
|
||||
SetRelayForcedStateReq::On { for_secs } => RelayForcedState::On {
|
||||
until: time_secs() + for_secs,
|
||||
},
|
||||
},
|
||||
req.to_forced_state(),
|
||||
))
|
||||
.await??;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user