#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct DeviceInfo { reference: String, version: semver::Version, max_relays: usize, } impl DeviceInfo { pub fn error(&self) -> Option<&str> { if self.reference.trim().is_empty() { return Some("Given device reference is empty or blank!"); } if self.max_relays == 0 { return Some("Given device cannot handle any relay!"); } None } } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)] pub struct DeviceId(pub String); #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct Device { /// The device ID id: DeviceId, /// Information about the device device: DeviceInfo, /// Name given to the device on the Web UI name: String, /// Description given to the device on the Web UI description: String, /// Specify whether the device is enabled or not enabled: bool, /// Specify whether the device has been validated or not validated: bool, /// Information about the relays handled by the device relays: Vec, } /// Structure that contains information about the minimal expected execution /// time of a device #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct DailyMinRuntime { min_runtime: usize, reset_time: usize, catch_up_hours: Vec, } #[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq)] pub struct DeviceRelayID(uuid::Uuid); #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct DeviceRelay { id: DeviceRelayID, name: String, enabled: bool, priority: usize, consumption: usize, minimal_uptime: usize, minimal_downtime: usize, daily_runtime: Option, depends_on: Vec, }