zigbee2mqtt_types_vendor_solaredge/
lib.rs

1use serde::Deserialize;
2use serde::de::Unexpected;
3use serde::de;
4use serde::Deserializer;
5use zigbee2mqtt_types_base_types::LastSeen;
6/// solaredge:SEHAZB-DR-SWITCH-2 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SEHAZB-DR-SWITCH-2.html)
7///
8/// 
9#[cfg_attr(feature = "debug", derive(Debug))]
10#[cfg_attr(feature = "clone", derive(Clone))]
11#[derive(Deserialize)]
12pub struct ZigbeeSehazbDdrDswitchD2 {
13    ///Link quality (signal strength)
14    pub linkquality: f64,
15    ///Controls the behavior when the device is powered on after power loss
16    pub power_on_behavior: ZigbeeSehazbDdrDswitchD2Poweronbehavior,
17    ///Zigbee herdsman description: "On/off state of the switch"
18    ///The string values get converted into boolean with: ON = true and OFF = false
19    #[serde(deserialize_with = "zigbeesehazbddrdswitchd2_state_deserializer")]
20    pub state: bool,
21    /// Optional last_seen type, set as a global zigbee2mqtt setting
22    pub last_seen: Option<LastSeen>,
23    /// Optional elapsed type
24    pub elapsed: Option<u64>,
25}
26/// Deserialize bool from String with custom value mapping
27fn zigbeesehazbddrdswitchd2_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
28where
29    D: Deserializer<'de>,
30{
31    match String::deserialize(deserializer)?.as_ref() {
32        "ON" => Ok(true),
33        "OFF" => Ok(false),
34        other => Err(de::Error::invalid_value(
35            Unexpected::Str(other),
36            &"Value expected was either ON or OFF",
37        )),
38    }
39}
40
41
42#[cfg_attr(feature = "debug", derive(Debug))]
43#[cfg_attr(feature = "clone", derive(Clone))]
44#[derive(Deserialize, PartialEq)]
45pub enum ZigbeeSehazbDdrDswitchD2Poweronbehavior {
46    #[serde(rename = "off")]
47    Off,
48    #[serde(rename = "on")]
49    On,
50    #[serde(rename = "previous")]
51    Previous,
52    #[serde(rename = "toggle")]
53    Toggle,
54}
55#[cfg(all(feature = "last_seen_epoch", feature = "last_seen_iso_8601"))]
56compile_error!{"Feature last_seen epoch and iso_8601 are mutually exclusive and cannot be enabled together.
57This was done because it is a global setting in zigbee2mqtt and therefor can't see a reason both would be enabled.
58If you have a any reason to have both ways enabled please submit an issue to https://gitlab.com/seam345/zigbee2mqtt-types/-/issues"}