zigbee2mqtt_types_vendor_matcall/
lib.rs

1use serde::Deserialize;
2use serde::de::Unexpected;
3use serde::de;
4use serde::Deserializer;
5use zigbee2mqtt_types_base_types::LastSeen;
6/// matcall:ZG401224 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/ZG401224.html)
7///
8/// 
9#[cfg_attr(feature = "debug", derive(Debug))]
10#[cfg_attr(feature = "clone", derive(Clone))]
11#[derive(Deserialize)]
12pub struct ZigbeeZg401224 {
13    ///Brightness of this light
14    pub brightness: f64,
15    ///Link quality (signal strength)
16    pub linkquality: f64,
17    ///Controls the behavior when the device is powered on after power loss
18    pub power_on_behavior: ZigbeeZg401224Poweronbehavior,
19    ///Zigbee herdsman description: "On/off state of this light"
20    ///The string values get converted into boolean with: ON = true and OFF = false
21    #[serde(deserialize_with = "zigbeezg401224_state_deserializer")]
22    pub state: bool,
23    /// Optional last_seen type, set as a global zigbee2mqtt setting
24    pub last_seen: Option<LastSeen>,
25    /// Optional elapsed type
26    pub elapsed: Option<u64>,
27}
28/// Deserialize bool from String with custom value mapping
29fn zigbeezg401224_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
30where
31    D: Deserializer<'de>,
32{
33    match String::deserialize(deserializer)?.as_ref() {
34        "ON" => Ok(true),
35        "OFF" => Ok(false),
36        other => Err(de::Error::invalid_value(
37            Unexpected::Str(other),
38            &"Value expected was either ON or OFF",
39        )),
40    }
41}
42
43/// matcall:ZG430700 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/ZG430700.html)
44///
45/// 
46#[cfg_attr(feature = "debug", derive(Debug))]
47#[cfg_attr(feature = "clone", derive(Clone))]
48#[derive(Deserialize)]
49pub struct ZigbeeZg430700 {
50    ///Brightness of this light
51    pub brightness: f64,
52    ///Link quality (signal strength)
53    pub linkquality: f64,
54    ///Controls the behavior when the device is powered on after power loss
55    pub power_on_behavior: ZigbeeZg430700Poweronbehavior,
56    ///Zigbee herdsman description: "On/off state of this light"
57    ///The string values get converted into boolean with: ON = true and OFF = false
58    #[serde(deserialize_with = "zigbeezg430700_state_deserializer")]
59    pub state: bool,
60    /// Optional last_seen type, set as a global zigbee2mqtt setting
61    pub last_seen: Option<LastSeen>,
62    /// Optional elapsed type
63    pub elapsed: Option<u64>,
64}
65/// Deserialize bool from String with custom value mapping
66fn zigbeezg430700_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
67where
68    D: Deserializer<'de>,
69{
70    match String::deserialize(deserializer)?.as_ref() {
71        "ON" => Ok(true),
72        "OFF" => Ok(false),
73        other => Err(de::Error::invalid_value(
74            Unexpected::Str(other),
75            &"Value expected was either ON or OFF",
76        )),
77    }
78}
79
80
81#[cfg_attr(feature = "debug", derive(Debug))]
82#[cfg_attr(feature = "clone", derive(Clone))]
83#[derive(Deserialize, PartialEq)]
84pub enum ZigbeeZg401224Poweronbehavior {
85    #[serde(rename = "off")]
86    Off,
87    #[serde(rename = "on")]
88    On,
89    #[serde(rename = "previous")]
90    Previous,
91    #[serde(rename = "toggle")]
92    Toggle,
93}
94#[cfg_attr(feature = "debug", derive(Debug))]
95#[cfg_attr(feature = "clone", derive(Clone))]
96#[derive(Deserialize, PartialEq)]
97pub enum ZigbeeZg430700Poweronbehavior {
98    #[serde(rename = "off")]
99    Off,
100    #[serde(rename = "on")]
101    On,
102    #[serde(rename = "previous")]
103    Previous,
104    #[serde(rename = "toggle")]
105    Toggle,
106}
107#[cfg(all(feature = "last_seen_epoch", feature = "last_seen_iso_8601"))]
108compile_error!{"Feature last_seen epoch and iso_8601 are mutually exclusive and cannot be enabled together.
109This was done because it is a global setting in zigbee2mqtt and therefor can't see a reason both would be enabled.
110If you have a any reason to have both ways enabled please submit an issue to https://gitlab.com/seam345/zigbee2mqtt-types/-/issues"}