#[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 pub id: DeviceId, /// Information about the device pub info: DeviceInfo, /// Time at which device was initially enrolled pub time_create: u64, /// Time at which device was last updated pub time_update: u64, /// Name given to the device on the Web UI pub name: String, /// Description given to the device on the Web UI pub description: String, /// Specify whether the device has been validated or not. Validated devices are given a /// certificate pub validated: bool, /// Specify whether the device is enabled or not pub enabled: bool, /// Information about the relays handled by the device pub 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 { pub min_runtime: usize, pub reset_time: usize, pub 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, conflicts_with: Vec, }