zigbee2mqtt_types_vendor_danalock/
lib.rs

1use serde::Deserialize;
2use serde::de::Unexpected;
3use serde::de;
4use serde::Deserializer;
5use zigbee2mqtt_types_base_types::LastSeen;
6/// danalock:V3-BTZB/V3-BTZBE [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/V3-BTZB/V3-BTZBE.html)
7///
8/// 
9#[cfg_attr(feature = "debug", derive(Debug))]
10#[cfg_attr(feature = "clone", derive(Clone))]
11#[derive(Deserialize)]
12pub struct ZigbeeV3Dbtzbv3Dbtzbe {
13    ///Triggered action on the lock
14    pub action: ZigbeeV3Dbtzbv3DbtzbeAction,
15    ///Source of the triggered action on the lock
16    pub action_source_name: ZigbeeV3Dbtzbv3DbtzbeActionsourcename,
17    ///ID of user that triggered the action on the lock
18    pub action_user: f64,
19    ///Remaining battery in %, can take up to 24 hours before reported.
20    pub battery: f64,
21    ///Link quality (signal strength)
22    pub linkquality: f64,
23    ///Actual state of the lock
24    pub lock_state: ZigbeeV3Dbtzbv3DbtzbeLockstate,
25    ///Zigbee herdsman description: "State of the lock"
26    ///The string values get converted into boolean with: LOCK = true and UNLOCK = false
27    #[serde(deserialize_with = "zigbeev3dbtzbv3dbtzbe_state_deserializer")]
28    pub state: bool,
29    /// Optional last_seen type, set as a global zigbee2mqtt setting
30    pub last_seen: Option<LastSeen>,
31    /// Optional elapsed type
32    pub elapsed: Option<u64>,
33}
34/// Deserialize bool from String with custom value mapping
35fn zigbeev3dbtzbv3dbtzbe_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
36where
37    D: Deserializer<'de>,
38{
39    match String::deserialize(deserializer)?.as_ref() {
40        "LOCK" => Ok(true),
41        "UNLOCK" => Ok(false),
42        other => Err(de::Error::invalid_value(
43            Unexpected::Str(other),
44            &"Value expected was either LOCK or UNLOCK",
45        )),
46    }
47}
48
49
50#[cfg_attr(feature = "debug", derive(Debug))]
51#[cfg_attr(feature = "clone", derive(Clone))]
52#[derive(Deserialize, PartialEq)]
53pub enum ZigbeeV3Dbtzbv3DbtzbeAction {
54    #[serde(rename = "auto_lock")]
55    AutoLock,
56    #[serde(rename = "key_lock")]
57    KeyLock,
58    #[serde(rename = "key_unlock")]
59    KeyUnlock,
60    #[serde(rename = "lock")]
61    Lock,
62    #[serde(rename = "lock_failure_invalid_pin_or_id")]
63    LockFailureInvalidPinOrId,
64    #[serde(rename = "lock_failure_invalid_schedule")]
65    LockFailureInvalidSchedule,
66    #[serde(rename = "manual_lock")]
67    ManualLock,
68    #[serde(rename = "manual_unlock")]
69    ManualUnlock,
70    #[serde(rename = "non_access_user_operational_event")]
71    NonAccessUserOperationalEvent,
72    #[serde(rename = "one_touch_lock")]
73    OneTouchLock,
74    #[serde(rename = "schedule_lock")]
75    ScheduleLock,
76    #[serde(rename = "schedule_unlock")]
77    ScheduleUnlock,
78    #[serde(rename = "unknown")]
79    Unknown,
80    #[serde(rename = "unlock")]
81    Unlock,
82    #[serde(rename = "unlock_failure_invalid_pin_or_id")]
83    UnlockFailureInvalidPinOrId,
84    #[serde(rename = "unlock_failure_invalid_schedule")]
85    UnlockFailureInvalidSchedule,
86}
87#[cfg_attr(feature = "debug", derive(Debug))]
88#[cfg_attr(feature = "clone", derive(Clone))]
89#[derive(Deserialize, PartialEq)]
90pub enum ZigbeeV3Dbtzbv3DbtzbeActionsourcename {
91    #[serde(rename = "keypad")]
92    Keypad,
93    #[serde(rename = "manual")]
94    Manual,
95    #[serde(rename = "rf")]
96    Rf,
97    #[serde(rename = "rfid")]
98    Rfid,
99}
100#[cfg_attr(feature = "debug", derive(Debug))]
101#[cfg_attr(feature = "clone", derive(Clone))]
102#[derive(Deserialize, PartialEq)]
103pub enum ZigbeeV3Dbtzbv3DbtzbeLockstate {
104    #[serde(rename = "locked")]
105    Locked,
106    #[serde(rename = "not_fully_locked")]
107    NotFullyLocked,
108    #[serde(rename = "unlocked")]
109    Unlocked,
110}
111#[cfg(all(feature = "last_seen_epoch", feature = "last_seen_iso_8601"))]
112compile_error!{"Feature last_seen epoch and iso_8601 are mutually exclusive and cannot be enabled together.
113This was done because it is a global setting in zigbee2mqtt and therefor can't see a reason both would be enabled.
114If you have a any reason to have both ways enabled please submit an issue to https://gitlab.com/seam345/zigbee2mqtt-types/-/issues"}