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:
		| @@ -25,6 +25,33 @@ impl DeviceState { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[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, | ||||
|     }, | ||||
| } | ||||
|  | ||||
| impl SetRelayForcedStateReq { | ||||
|     pub fn to_forced_state(&self) -> RelayForcedState { | ||||
|         match &self { | ||||
|             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, | ||||
|             }, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Default, Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)] | ||||
| #[serde(tag = "type")] | ||||
| pub enum RelayForcedState { | ||||
| @@ -440,7 +467,7 @@ impl EnergyEngine { | ||||
| mod test { | ||||
|     use crate::devices::device::{Device, DeviceId, DeviceRelayID}; | ||||
|     use crate::energy::consumption::EnergyConsumption; | ||||
|     use crate::energy::engine::EnergyEngine; | ||||
|     use crate::energy::engine::{EnergyEngine, SetRelayForcedStateReq}; | ||||
|     use crate::utils::time_utils::time_secs; | ||||
|     use rust_embed::Embed; | ||||
|  | ||||
| @@ -449,6 +476,8 @@ mod test { | ||||
|         id: DeviceRelayID, | ||||
|         on: bool, | ||||
|         r#for: usize, | ||||
|         #[serde(default)] | ||||
|         forced_state: SetRelayForcedStateReq, | ||||
|         should_be_on: bool, | ||||
|     } | ||||
|  | ||||
| @@ -496,6 +525,7 @@ mod test { | ||||
|                 let s = engine.relay_state(r.id); | ||||
|                 s.on = r.on; | ||||
|                 s.since = time_secs() as usize - r.r#for; | ||||
|                 s.forced_state = r.forced_state.to_forced_state() | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user