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 ZigbeeTi0001 {
pub linkquality: f64,
#[serde(deserialize_with = "zigbeeti0001_state_bottom_left_deserializer")]
pub state_bottom_left: bool,
#[serde(deserialize_with = "zigbeeti0001_state_bottom_right_deserializer")]
pub state_bottom_right: bool,
#[serde(deserialize_with = "zigbeeti0001_state_left_deserializer")]
pub state_left: bool,
#[serde(deserialize_with = "zigbeeti0001_state_right_deserializer")]
pub state_right: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeeti0001_state_bottom_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 zigbeeti0001_state_bottom_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",
)),
}
}
fn zigbeeti0001_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 zigbeeti0001_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)]
pub struct ZigbeeTi0001Dcover {
pub linkquality: f64,
pub position: f64,
pub state: ZigbeeTi0001DcoverState,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize)]
pub struct ZigbeeTi0001DcurtainDswitch {
pub linkquality: f64,
#[serde(deserialize_with = "zigbeeti0001dcurtaindswitch_state_left_deserializer")]
pub state_left: bool,
#[serde(deserialize_with = "zigbeeti0001dcurtaindswitch_state_right_deserializer")]
pub state_right: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeeti0001dcurtaindswitch_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 zigbeeti0001dcurtaindswitch_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)]
pub struct ZigbeeTi0001Ddimmer {
pub brightness: f64,
pub linkquality: f64,
#[serde(deserialize_with = "zigbeeti0001ddimmer_state_deserializer")]
pub state: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeeti0001ddimmer_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 ZigbeeTi0001Dpir {
pub linkquality: f64,
pub occupancy: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize)]
pub struct ZigbeeTi0001Dsocket {
pub linkquality: f64,
pub power_on_behavior: ZigbeeTi0001DsocketPoweronbehavior,
#[serde(deserialize_with = "zigbeeti0001dsocket_state_deserializer")]
pub state: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeeti0001dsocket_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 ZigbeeTi0001Dswitch {
pub linkquality: f64,
pub power_on_behavior: ZigbeeTi0001DswitchPoweronbehavior,
#[serde(deserialize_with = "zigbeeti0001dswitch_state_deserializer")]
pub state: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeeti0001dswitch_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 ZigbeeTi0001DswitchD2gang {
pub linkquality: f64,
#[serde(deserialize_with = "zigbeeti0001dswitchd2gang_state_left_deserializer")]
pub state_left: bool,
#[serde(deserialize_with = "zigbeeti0001dswitchd2gang_state_right_deserializer")]
pub state_right: bool,
pub last_seen: Option<LastSeen>,
pub elapsed: Option<u64>,
}
fn zigbeeti0001dswitchd2gang_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 zigbeeti0001dswitchd2gang_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 ZigbeeTi0001DcoverState {
#[serde(rename = "CLOSE")]
Close,
#[serde(rename = "OPEN")]
Open,
#[serde(rename = "STOP")]
Stop,
}
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize, PartialEq)]
pub enum ZigbeeTi0001DsocketPoweronbehavior {
#[serde(rename = "off")]
Off,
#[serde(rename = "on")]
On,
#[serde(rename = "previous")]
Previous,
#[serde(rename = "toggle")]
Toggle,
}
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "clone", derive(Clone))]
#[derive(Deserialize, PartialEq)]
pub enum ZigbeeTi0001DswitchPoweronbehavior {
#[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"}