2024-07-01 19:10:45 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
|
|
pub struct DeviceInfo {
|
|
|
|
reference: String,
|
|
|
|
version: semver::Version,
|
|
|
|
max_relays: usize,
|
|
|
|
}
|
|
|
|
|
2024-07-01 20:24:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-01 19:10:45 +00:00
|
|
|
#[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
|
2024-07-02 20:55:51 +00:00
|
|
|
pub id: DeviceId,
|
2024-07-01 19:10:45 +00:00
|
|
|
/// Information about the device
|
2024-07-02 20:55:51 +00:00
|
|
|
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,
|
2024-07-01 19:10:45 +00:00
|
|
|
/// Name given to the device on the Web UI
|
2024-07-02 20:55:51 +00:00
|
|
|
pub name: String,
|
2024-07-01 19:10:45 +00:00
|
|
|
/// Description given to the device on the Web UI
|
2024-07-02 20:55:51 +00:00
|
|
|
pub description: String,
|
|
|
|
/// Specify whether the device has been validated or not. Validated devices are given a
|
|
|
|
/// certificate
|
|
|
|
pub validated: bool,
|
2024-07-01 19:10:45 +00:00
|
|
|
/// Specify whether the device is enabled or not
|
2024-07-02 20:55:51 +00:00
|
|
|
pub enabled: bool,
|
2024-07-01 19:10:45 +00:00
|
|
|
/// Information about the relays handled by the device
|
2024-07-02 20:55:51 +00:00
|
|
|
pub relays: Vec<DeviceRelay>,
|
2024-07-01 19:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Structure that contains information about the minimal expected execution
|
|
|
|
/// time of a device
|
|
|
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
|
|
|
pub struct DailyMinRuntime {
|
2024-07-02 20:55:51 +00:00
|
|
|
pub min_runtime: usize,
|
|
|
|
pub reset_time: usize,
|
|
|
|
pub catch_up_hours: Vec<usize>,
|
2024-07-01 19:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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<DailyMinRuntime>,
|
|
|
|
depends_on: Vec<DeviceRelay>,
|
2024-07-02 20:55:51 +00:00
|
|
|
conflicts_with: Vec<DeviceRelay>,
|
2024-07-01 19:10:45 +00:00
|
|
|
}
|