Can update device general information
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user