zigbee2mqtt_types_vendor_netvox/
lib.rs

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