zigbee2mqtt_types_vendor_fischer___honsel/
lib.rs

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