fundamentum_sdk_mqtt/models/commands/
custom_configuration_update.rs

1//! `Custom configuration update` module
2//!
3
4use std::hash::{Hash, Hasher};
5
6use serde::{Deserialize, Serialize};
7
8/// `ConfigUpdateParameters` definition
9/// See <https://dimonoff.atlassian.net/wiki/spaces/F2/pages/306437652531/Devices+Commands#Configuration-Update>
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
11pub struct ConfigUpdateParameters {
12    /// Apply all the new configurations if true. Apply only the diff otherwise.
13    pub deep_update: bool,
14    /// Number of second before timeout.
15    pub retry_timeout: u32,
16    /// Configuration to apply to the target device.
17    target_device: TargetDeviceConfig,
18}
19
20/// `TargetDeviceConfig` definition
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
22struct TargetDeviceConfig {
23    /// Unique-by-registry identifier given to a device during provisioning.
24    serial_number: String,
25    /// Actual device configuration of the target device.
26    actual_configuration: serde_json::Value,
27    /// New device configuration to apply to the target device.
28    new_configuration: serde_json::Value,
29}
30
31impl Hash for TargetDeviceConfig {
32    fn hash<H: Hasher>(&self, state: &mut H) {
33        self.serial_number.hash(state);
34        self.actual_configuration.to_string().hash(state);
35        self.new_configuration.to_string().hash(state);
36    }
37}
38
39impl ConfigUpdateParameters {
40    /// Returns the target device's serial number.
41    #[must_use]
42    #[expect(clippy::missing_const_for_fn, reason = "False positive")]
43    pub fn target_serial_number(&self) -> &str {
44        &self.target_device.serial_number
45    }
46
47    /// Returns the device's actual configuration.
48    #[must_use]
49    pub const fn current_config(&self) -> &serde_json::Value {
50        &self.target_device.actual_configuration
51    }
52
53    /// Returns the device's new configuration.
54    #[must_use]
55    pub const fn new_config(&self) -> &serde_json::Value {
56        &self.target_device.new_configuration
57    }
58}