zigbee2mqtt_types_vendor_samotech/
lib.rs

1use serde::Deserialize;
2use serde::de::Unexpected;
3use serde::de;
4use serde::Deserializer;
5use zigbee2mqtt_types_base_types::LastSeen;
6/// samotech:SM308 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM308.html)
7///
8/// 
9#[cfg_attr(feature = "debug", derive(Debug))]
10#[cfg_attr(feature = "clone", derive(Clone))]
11#[derive(Deserialize)]
12pub struct ZigbeeSm308 {
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: ZigbeeSm308Poweronbehavior,
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 = "zigbeesm308_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 zigbeesm308_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/// samotech:SM308-2CH [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM308-2CH.html)
42///
43/// 
44#[cfg_attr(feature = "debug", derive(Debug))]
45#[cfg_attr(feature = "clone", derive(Clone))]
46#[derive(Deserialize)]
47pub struct ZigbeeSm308D2ch {
48    ///Instantaneous measured electrical current
49    pub current: f64,
50    ///Sum of consumed energy
51    pub energy: f64,
52    ///Link quality (signal strength)
53    pub linkquality: f64,
54    ///Instantaneous measured power
55    pub power: f64,
56    ///Controls the behavior when the device is powered on after power loss
57    pub power_on_behavior_l1: ZigbeeSm308D2chPoweronbehaviorl1,
58    ///Controls the behavior when the device is powered on after power loss
59    pub power_on_behavior_l2: ZigbeeSm308D2chPoweronbehaviorl2,
60    ///Zigbee herdsman description: "On/off state of the switch"
61    ///The string values get converted into boolean with: ON = true and OFF = false
62    #[serde(deserialize_with = "zigbeesm308d2ch_state_l1_deserializer")]
63    pub state_l1: bool,
64    ///Zigbee herdsman description: "On/off state of the switch"
65    ///The string values get converted into boolean with: ON = true and OFF = false
66    #[serde(deserialize_with = "zigbeesm308d2ch_state_l2_deserializer")]
67    pub state_l2: bool,
68    ///Measured electrical potential value
69    pub voltage: f64,
70    /// Optional last_seen type, set as a global zigbee2mqtt setting
71    pub last_seen: Option<LastSeen>,
72    /// Optional elapsed type
73    pub elapsed: Option<u64>,
74}
75/// Deserialize bool from String with custom value mapping
76fn zigbeesm308d2ch_state_l1_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
77where
78    D: Deserializer<'de>,
79{
80    match String::deserialize(deserializer)?.as_ref() {
81        "ON" => Ok(true),
82        "OFF" => Ok(false),
83        other => Err(de::Error::invalid_value(
84            Unexpected::Str(other),
85            &"Value expected was either ON or OFF",
86        )),
87    }
88}
89
90
91/// Deserialize bool from String with custom value mapping
92fn zigbeesm308d2ch_state_l2_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
93where
94    D: Deserializer<'de>,
95{
96    match String::deserialize(deserializer)?.as_ref() {
97        "ON" => Ok(true),
98        "OFF" => Ok(false),
99        other => Err(de::Error::invalid_value(
100            Unexpected::Str(other),
101            &"Value expected was either ON or OFF",
102        )),
103    }
104}
105
106/// samotech:SM308-S [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM308-S.html)
107///
108/// 
109#[cfg_attr(feature = "debug", derive(Debug))]
110#[cfg_attr(feature = "clone", derive(Clone))]
111#[derive(Deserialize)]
112pub struct ZigbeeSm308Ds {
113    ///Link quality (signal strength)
114    pub linkquality: f64,
115    ///Controls the behavior when the device is powered on after power loss
116    pub power_on_behavior: ZigbeeSm308DsPoweronbehavior,
117    ///Zigbee herdsman description: "On/off state of the switch"
118    ///The string values get converted into boolean with: ON = true and OFF = false
119    #[serde(deserialize_with = "zigbeesm308ds_state_deserializer")]
120    pub state: bool,
121    /// Optional last_seen type, set as a global zigbee2mqtt setting
122    pub last_seen: Option<LastSeen>,
123    /// Optional elapsed type
124    pub elapsed: Option<u64>,
125}
126/// Deserialize bool from String with custom value mapping
127fn zigbeesm308ds_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
128where
129    D: Deserializer<'de>,
130{
131    match String::deserialize(deserializer)?.as_ref() {
132        "ON" => Ok(true),
133        "OFF" => Ok(false),
134        other => Err(de::Error::invalid_value(
135            Unexpected::Str(other),
136            &"Value expected was either ON or OFF",
137        )),
138    }
139}
140
141/// samotech:SM309 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM309.html)
142///
143/// 
144#[cfg_attr(feature = "debug", derive(Debug))]
145#[cfg_attr(feature = "clone", derive(Clone))]
146#[derive(Deserialize)]
147pub struct ZigbeeSm309 {
148    ///Brightness of this light
149    pub brightness: f64,
150    ///Link quality (signal strength)
151    pub linkquality: f64,
152    ///Controls the behavior when the device is powered on after power loss
153    pub power_on_behavior: ZigbeeSm309Poweronbehavior,
154    ///Zigbee herdsman description: "On/off state of this light"
155    ///The string values get converted into boolean with: ON = true and OFF = false
156    #[serde(deserialize_with = "zigbeesm309_state_deserializer")]
157    pub state: bool,
158    /// Optional last_seen type, set as a global zigbee2mqtt setting
159    pub last_seen: Option<LastSeen>,
160    /// Optional elapsed type
161    pub elapsed: Option<u64>,
162}
163/// Deserialize bool from String with custom value mapping
164fn zigbeesm309_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
165where
166    D: Deserializer<'de>,
167{
168    match String::deserialize(deserializer)?.as_ref() {
169        "ON" => Ok(true),
170        "OFF" => Ok(false),
171        other => Err(de::Error::invalid_value(
172            Unexpected::Str(other),
173            &"Value expected was either ON or OFF",
174        )),
175    }
176}
177
178/// samotech:SM309-S [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM309-S.html)
179///
180/// 
181#[cfg_attr(feature = "debug", derive(Debug))]
182#[cfg_attr(feature = "clone", derive(Clone))]
183#[derive(Deserialize)]
184pub struct ZigbeeSm309Ds {
185    ///Brightness of this light
186    pub brightness: f64,
187    ///Instantaneous measured electrical current
188    pub current: f64,
189    ///Sum of consumed energy
190    pub energy: f64,
191    ///Link quality (signal strength)
192    pub linkquality: f64,
193    ///Instantaneous measured power
194    pub power: f64,
195    ///Controls the behavior when the device is powered on after power loss
196    pub power_on_behavior: ZigbeeSm309DsPoweronbehavior,
197    ///Zigbee herdsman description: "On/off state of this light"
198    ///The string values get converted into boolean with: ON = true and OFF = false
199    #[serde(deserialize_with = "zigbeesm309ds_state_deserializer")]
200    pub state: bool,
201    ///Measured electrical potential value
202    pub voltage: f64,
203    /// Optional last_seen type, set as a global zigbee2mqtt setting
204    pub last_seen: Option<LastSeen>,
205    /// Optional elapsed type
206    pub elapsed: Option<u64>,
207}
208/// Deserialize bool from String with custom value mapping
209fn zigbeesm309ds_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
210where
211    D: Deserializer<'de>,
212{
213    match String::deserialize(deserializer)?.as_ref() {
214        "ON" => Ok(true),
215        "OFF" => Ok(false),
216        other => Err(de::Error::invalid_value(
217            Unexpected::Str(other),
218            &"Value expected was either ON or OFF",
219        )),
220    }
221}
222
223/// samotech:SM323 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM323.html)
224///
225/// 
226#[cfg_attr(feature = "debug", derive(Debug))]
227#[cfg_attr(feature = "clone", derive(Clone))]
228#[derive(Deserialize)]
229pub struct ZigbeeSm323 {
230    ///Brightness of this light
231    pub brightness: f64,
232    ///Link quality (signal strength)
233    pub linkquality: f64,
234    ///Controls the behavior when the device is powered on after power loss
235    pub power_on_behavior: ZigbeeSm323Poweronbehavior,
236    ///Zigbee herdsman description: "On/off state of this light"
237    ///The string values get converted into boolean with: ON = true and OFF = false
238    #[serde(deserialize_with = "zigbeesm323_state_deserializer")]
239    pub state: bool,
240    /// Optional last_seen type, set as a global zigbee2mqtt setting
241    pub last_seen: Option<LastSeen>,
242    /// Optional elapsed type
243    pub elapsed: Option<u64>,
244}
245/// Deserialize bool from String with custom value mapping
246fn zigbeesm323_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
247where
248    D: Deserializer<'de>,
249{
250    match String::deserialize(deserializer)?.as_ref() {
251        "ON" => Ok(true),
252        "OFF" => Ok(false),
253        other => Err(de::Error::invalid_value(
254            Unexpected::Str(other),
255            &"Value expected was either ON or OFF",
256        )),
257    }
258}
259
260/// samotech:SM324 [zigbee2mqtt link](https://www.zigbee2mqtt.io/devices/SM324.html)
261///
262/// 
263#[cfg_attr(feature = "debug", derive(Debug))]
264#[cfg_attr(feature = "clone", derive(Clone))]
265#[derive(Deserialize)]
266pub struct ZigbeeSm324 {
267    ///Brightness of this light
268    pub brightness: f64,
269    ///Color temperature of this light
270    pub color_temp: f64,
271    ///Color temperature after cold power on of this light
272    pub color_temp_startup: f64,
273    ///Link quality (signal strength)
274    pub linkquality: f64,
275    ///Controls the behavior when the device is powered on after power loss
276    pub power_on_behavior: ZigbeeSm324Poweronbehavior,
277    ///Zigbee herdsman description: "On/off state of this light"
278    ///The string values get converted into boolean with: ON = true and OFF = false
279    #[serde(deserialize_with = "zigbeesm324_state_deserializer")]
280    pub state: bool,
281    /// Optional last_seen type, set as a global zigbee2mqtt setting
282    pub last_seen: Option<LastSeen>,
283    /// Optional elapsed type
284    pub elapsed: Option<u64>,
285}
286/// Deserialize bool from String with custom value mapping
287fn zigbeesm324_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
288where
289    D: Deserializer<'de>,
290{
291    match String::deserialize(deserializer)?.as_ref() {
292        "ON" => Ok(true),
293        "OFF" => Ok(false),
294        other => Err(de::Error::invalid_value(
295            Unexpected::Str(other),
296            &"Value expected was either ON or OFF",
297        )),
298    }
299}
300
301
302#[cfg_attr(feature = "debug", derive(Debug))]
303#[cfg_attr(feature = "clone", derive(Clone))]
304#[derive(Deserialize, PartialEq)]
305pub enum ZigbeeSm308D2chPoweronbehaviorl1 {
306    #[serde(rename = "off")]
307    Off,
308    #[serde(rename = "on")]
309    On,
310    #[serde(rename = "previous")]
311    Previous,
312}
313#[cfg_attr(feature = "debug", derive(Debug))]
314#[cfg_attr(feature = "clone", derive(Clone))]
315#[derive(Deserialize, PartialEq)]
316pub enum ZigbeeSm308D2chPoweronbehaviorl2 {
317    #[serde(rename = "off")]
318    Off,
319    #[serde(rename = "on")]
320    On,
321    #[serde(rename = "previous")]
322    Previous,
323}
324#[cfg_attr(feature = "debug", derive(Debug))]
325#[cfg_attr(feature = "clone", derive(Clone))]
326#[derive(Deserialize, PartialEq)]
327pub enum ZigbeeSm308DsPoweronbehavior {
328    #[serde(rename = "off")]
329    Off,
330    #[serde(rename = "on")]
331    On,
332    #[serde(rename = "previous")]
333    Previous,
334    #[serde(rename = "toggle")]
335    Toggle,
336}
337#[cfg_attr(feature = "debug", derive(Debug))]
338#[cfg_attr(feature = "clone", derive(Clone))]
339#[derive(Deserialize, PartialEq)]
340pub enum ZigbeeSm308Poweronbehavior {
341    #[serde(rename = "off")]
342    Off,
343    #[serde(rename = "on")]
344    On,
345    #[serde(rename = "previous")]
346    Previous,
347    #[serde(rename = "toggle")]
348    Toggle,
349}
350#[cfg_attr(feature = "debug", derive(Debug))]
351#[cfg_attr(feature = "clone", derive(Clone))]
352#[derive(Deserialize, PartialEq)]
353pub enum ZigbeeSm309DsPoweronbehavior {
354    #[serde(rename = "off")]
355    Off,
356    #[serde(rename = "on")]
357    On,
358    #[serde(rename = "previous")]
359    Previous,
360    #[serde(rename = "toggle")]
361    Toggle,
362}
363#[cfg_attr(feature = "debug", derive(Debug))]
364#[cfg_attr(feature = "clone", derive(Clone))]
365#[derive(Deserialize, PartialEq)]
366pub enum ZigbeeSm309Poweronbehavior {
367    #[serde(rename = "off")]
368    Off,
369    #[serde(rename = "on")]
370    On,
371    #[serde(rename = "previous")]
372    Previous,
373    #[serde(rename = "toggle")]
374    Toggle,
375}
376#[cfg_attr(feature = "debug", derive(Debug))]
377#[cfg_attr(feature = "clone", derive(Clone))]
378#[derive(Deserialize, PartialEq)]
379pub enum ZigbeeSm323Poweronbehavior {
380    #[serde(rename = "off")]
381    Off,
382    #[serde(rename = "on")]
383    On,
384    #[serde(rename = "previous")]
385    Previous,
386    #[serde(rename = "toggle")]
387    Toggle,
388}
389#[cfg_attr(feature = "debug", derive(Debug))]
390#[cfg_attr(feature = "clone", derive(Clone))]
391#[derive(Deserialize, PartialEq)]
392pub enum ZigbeeSm324Poweronbehavior {
393    #[serde(rename = "off")]
394    Off,
395    #[serde(rename = "on")]
396    On,
397    #[serde(rename = "previous")]
398    Previous,
399    #[serde(rename = "toggle")]
400    Toggle,
401}
402#[cfg(all(feature = "last_seen_epoch", feature = "last_seen_iso_8601"))]
403compile_error!{"Feature last_seen epoch and iso_8601 are mutually exclusive and cannot be enabled together.
404This was done because it is a global setting in zigbee2mqtt and therefor can't see a reason both would be enabled.
405If you have a any reason to have both ways enabled please submit an issue to https://gitlab.com/seam345/zigbee2mqtt-types/-/issues"}