Can update device general information

This commit is contained in:
2024-07-22 22:19:48 +02:00
parent baf341d505
commit 4d5ba939d1
18 changed files with 546 additions and 147 deletions

View File

@ -1,5 +1,7 @@
//! # Devices entities definition
use crate::constants::StaticConstraints;
/// Device information provided directly by the device during syncrhonisation.
///
/// It should not be editable fro the Web UI
@ -100,3 +102,29 @@ pub struct DeviceRelay {
/// Specify relays that must be turned off before this relay can be started
conflicts_with: Vec<DeviceRelayID>,
}
/// Device general information
///
/// This structure is used to update device information
#[derive(serde::Deserialize, Debug, Clone)]
pub struct DeviceGeneralInfo {
pub name: String,
pub description: String,
pub enabled: bool,
}
impl DeviceGeneralInfo {
/// Check for errors in the structure
pub fn error(&self) -> Option<&'static str> {
let constraints = StaticConstraints::default();
if !constraints.dev_name_len.validate(&self.name) {
return Some("Invalid device name length!");
}
if !constraints.dev_description_len.validate(&self.description) {
return Some("Invalid device description length!");
}
None
}
}