use serde::Deserialize;
use serde::de::Unexpected;
use serde::de;
use serde::Deserializer;
use zigbee2mqtt_types_base_types::LastSeen;
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize)]
pub struct ZigbeeSpDps1D02 {
pub linkquality: f64,
pub power_on_behavior: ZigbeeSpDps1D02Poweronbehavior,
#[serde(deserialize_with = "zigbeespdps1d02_state_deserializer")]
pub state: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeespdps1d02_state_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
match String::deserialize(deserializer)?.as_ref() {
"ON" => Ok(true),
"OFF" => Ok(false),
other => Err(de::Error::invalid_value(
Unexpected::Str(other),
&"Value expected was either ON or OFF",
)),
}
}
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize)]
pub struct ZigbeeSpDps2D02 {
pub linkquality: f64,
#[serde(deserialize_with = "zigbeespdps2d02_state_left_deserializer")]
pub state_left: bool,
#[serde(deserialize_with = "zigbeespdps2d02_state_right_deserializer")]
pub state_right: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeespdps2d02_state_left_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
match String::deserialize(deserializer)?.as_ref() {
"ON" => Ok(true),
"OFF" => Ok(false),
other => Err(de::Error::invalid_value(
Unexpected::Str(other),
&"Value expected was either ON or OFF",
)),
}
}
fn zigbeespdps2d02_state_right_deserializer<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
match String::deserialize(deserializer)?.as_ref() {
"ON" => Ok(true),
"OFF" => Ok(false),
other => Err(de::Error::invalid_value(
Unexpected::Str(other),
&"Value expected was either ON or OFF",
)),
}
}
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize, PartialEq)]
pub enum ZigbeeSpDps1D02Poweronbehavior {
#[serde(rename = "off")]
Off,
#[serde(rename = "on")]
On,
#[serde(rename = "previous")]
Previous,
#[serde(rename = "toggle")]
Toggle,
}
#[cfg(all(feature = "last_seen_epoch", feature = "last_seen_iso_8601"))]
compile_error!{"Feature last_seen epoch and iso_8601 are mutually exclusive and cannot be enabled together.
This was done because it is a global setting in zigbee2mqtt and therefor can't see a reason both would be enabled.
If you have a any reason to have both ways enabled please submit an issue to https://gitlab.com/seam345/zigbee2mqtt-types/-/issues"}