#![allow(clippy::match_same_arms)]
#[allow(unused_imports)]
use crate::format::CharFormat;
use crate::uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ServiceType {
AccessoryInformation,
ProtocolInformation,
LightBulb,
Switch,
Outlet,
Fan,
Thermostat,
TemperatureSensor,
HumiditySensor,
MotionSensor,
ContactSensor,
GarageDoorOpener,
LockMechanism,
Battery,
Unknown(Uuid),
}
impl ServiceType {
pub fn from_uuid(u: &Uuid) -> Self {
match u.as_full() {
"0000003e-0000-1000-8000-0026bb765291" => Self::AccessoryInformation,
"000000a2-0000-1000-8000-0026bb765291" => Self::ProtocolInformation,
"00000043-0000-1000-8000-0026bb765291" => Self::LightBulb,
"00000049-0000-1000-8000-0026bb765291" => Self::Switch,
"00000047-0000-1000-8000-0026bb765291" => Self::Outlet,
"00000040-0000-1000-8000-0026bb765291" => Self::Fan,
"0000004a-0000-1000-8000-0026bb765291" => Self::Thermostat,
"0000008a-0000-1000-8000-0026bb765291" => Self::TemperatureSensor,
"00000082-0000-1000-8000-0026bb765291" => Self::HumiditySensor,
"00000085-0000-1000-8000-0026bb765291" => Self::MotionSensor,
"00000080-0000-1000-8000-0026bb765291" => Self::ContactSensor,
"00000041-0000-1000-8000-0026bb765291" => Self::GarageDoorOpener,
"00000045-0000-1000-8000-0026bb765291" => Self::LockMechanism,
"00000096-0000-1000-8000-0026bb765291" => Self::Battery,
_ => Self::Unknown(u.clone()),
}
}
pub fn uuid(&self) -> Uuid {
match self {
Self::AccessoryInformation => {
Uuid::from_full_unchecked("0000003e-0000-1000-8000-0026bb765291".to_string())
}
Self::ProtocolInformation => {
Uuid::from_full_unchecked("000000a2-0000-1000-8000-0026bb765291".to_string())
}
Self::LightBulb => {
Uuid::from_full_unchecked("00000043-0000-1000-8000-0026bb765291".to_string())
}
Self::Switch => {
Uuid::from_full_unchecked("00000049-0000-1000-8000-0026bb765291".to_string())
}
Self::Outlet => {
Uuid::from_full_unchecked("00000047-0000-1000-8000-0026bb765291".to_string())
}
Self::Fan => {
Uuid::from_full_unchecked("00000040-0000-1000-8000-0026bb765291".to_string())
}
Self::Thermostat => {
Uuid::from_full_unchecked("0000004a-0000-1000-8000-0026bb765291".to_string())
}
Self::TemperatureSensor => {
Uuid::from_full_unchecked("0000008a-0000-1000-8000-0026bb765291".to_string())
}
Self::HumiditySensor => {
Uuid::from_full_unchecked("00000082-0000-1000-8000-0026bb765291".to_string())
}
Self::MotionSensor => {
Uuid::from_full_unchecked("00000085-0000-1000-8000-0026bb765291".to_string())
}
Self::ContactSensor => {
Uuid::from_full_unchecked("00000080-0000-1000-8000-0026bb765291".to_string())
}
Self::GarageDoorOpener => {
Uuid::from_full_unchecked("00000041-0000-1000-8000-0026bb765291".to_string())
}
Self::LockMechanism => {
Uuid::from_full_unchecked("00000045-0000-1000-8000-0026bb765291".to_string())
}
Self::Battery => {
Uuid::from_full_unchecked("00000096-0000-1000-8000-0026bb765291".to_string())
}
Self::Unknown(u) => u.clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CharacteristicType {
Identify,
Manufacturer,
Model,
Name,
SerialNumber,
FirmwareRevision,
On,
Brightness,
Hue,
Saturation,
ColorTemperature,
CurrentTemperature,
TargetTemperature,
CurrentRelativeHumidity,
MotionDetected,
ContactSensorState,
LockCurrentState,
LockTargetState,
BatteryLevel,
StatusLowBattery,
OutletInUse,
Unknown(Uuid),
}
impl CharacteristicType {
pub fn from_uuid(u: &Uuid) -> Self {
match u.as_full() {
"00000014-0000-1000-8000-0026bb765291" => Self::Identify,
"00000020-0000-1000-8000-0026bb765291" => Self::Manufacturer,
"00000021-0000-1000-8000-0026bb765291" => Self::Model,
"00000023-0000-1000-8000-0026bb765291" => Self::Name,
"00000030-0000-1000-8000-0026bb765291" => Self::SerialNumber,
"00000052-0000-1000-8000-0026bb765291" => Self::FirmwareRevision,
"00000025-0000-1000-8000-0026bb765291" => Self::On,
"00000008-0000-1000-8000-0026bb765291" => Self::Brightness,
"00000013-0000-1000-8000-0026bb765291" => Self::Hue,
"0000002f-0000-1000-8000-0026bb765291" => Self::Saturation,
"000000ce-0000-1000-8000-0026bb765291" => Self::ColorTemperature,
"00000011-0000-1000-8000-0026bb765291" => Self::CurrentTemperature,
"00000035-0000-1000-8000-0026bb765291" => Self::TargetTemperature,
"00000010-0000-1000-8000-0026bb765291" => Self::CurrentRelativeHumidity,
"00000022-0000-1000-8000-0026bb765291" => Self::MotionDetected,
"0000006a-0000-1000-8000-0026bb765291" => Self::ContactSensorState,
"0000001d-0000-1000-8000-0026bb765291" => Self::LockCurrentState,
"0000001e-0000-1000-8000-0026bb765291" => Self::LockTargetState,
"00000068-0000-1000-8000-0026bb765291" => Self::BatteryLevel,
"00000079-0000-1000-8000-0026bb765291" => Self::StatusLowBattery,
"00000026-0000-1000-8000-0026bb765291" => Self::OutletInUse,
_ => Self::Unknown(u.clone()),
}
}
pub fn uuid(&self) -> Uuid {
match self {
Self::Identify => {
Uuid::from_full_unchecked("00000014-0000-1000-8000-0026bb765291".to_string())
}
Self::Manufacturer => {
Uuid::from_full_unchecked("00000020-0000-1000-8000-0026bb765291".to_string())
}
Self::Model => {
Uuid::from_full_unchecked("00000021-0000-1000-8000-0026bb765291".to_string())
}
Self::Name => {
Uuid::from_full_unchecked("00000023-0000-1000-8000-0026bb765291".to_string())
}
Self::SerialNumber => {
Uuid::from_full_unchecked("00000030-0000-1000-8000-0026bb765291".to_string())
}
Self::FirmwareRevision => {
Uuid::from_full_unchecked("00000052-0000-1000-8000-0026bb765291".to_string())
}
Self::On => {
Uuid::from_full_unchecked("00000025-0000-1000-8000-0026bb765291".to_string())
}
Self::Brightness => {
Uuid::from_full_unchecked("00000008-0000-1000-8000-0026bb765291".to_string())
}
Self::Hue => {
Uuid::from_full_unchecked("00000013-0000-1000-8000-0026bb765291".to_string())
}
Self::Saturation => {
Uuid::from_full_unchecked("0000002f-0000-1000-8000-0026bb765291".to_string())
}
Self::ColorTemperature => {
Uuid::from_full_unchecked("000000ce-0000-1000-8000-0026bb765291".to_string())
}
Self::CurrentTemperature => {
Uuid::from_full_unchecked("00000011-0000-1000-8000-0026bb765291".to_string())
}
Self::TargetTemperature => {
Uuid::from_full_unchecked("00000035-0000-1000-8000-0026bb765291".to_string())
}
Self::CurrentRelativeHumidity => {
Uuid::from_full_unchecked("00000010-0000-1000-8000-0026bb765291".to_string())
}
Self::MotionDetected => {
Uuid::from_full_unchecked("00000022-0000-1000-8000-0026bb765291".to_string())
}
Self::ContactSensorState => {
Uuid::from_full_unchecked("0000006a-0000-1000-8000-0026bb765291".to_string())
}
Self::LockCurrentState => {
Uuid::from_full_unchecked("0000001d-0000-1000-8000-0026bb765291".to_string())
}
Self::LockTargetState => {
Uuid::from_full_unchecked("0000001e-0000-1000-8000-0026bb765291".to_string())
}
Self::BatteryLevel => {
Uuid::from_full_unchecked("00000068-0000-1000-8000-0026bb765291".to_string())
}
Self::StatusLowBattery => {
Uuid::from_full_unchecked("00000079-0000-1000-8000-0026bb765291".to_string())
}
Self::OutletInUse => {
Uuid::from_full_unchecked("00000026-0000-1000-8000-0026bb765291".to_string())
}
Self::Unknown(u) => u.clone(),
}
}
pub fn default_format(&self) -> Option<CharFormat> {
match self {
Self::Identify => Some(CharFormat::Bool),
Self::Manufacturer => Some(CharFormat::String),
Self::Model => Some(CharFormat::String),
Self::Name => Some(CharFormat::String),
Self::SerialNumber => Some(CharFormat::String),
Self::FirmwareRevision => Some(CharFormat::String),
Self::On => Some(CharFormat::Bool),
Self::Brightness => Some(CharFormat::Int),
Self::Hue => Some(CharFormat::Float),
Self::Saturation => Some(CharFormat::Float),
Self::ColorTemperature => Some(CharFormat::Uint32),
Self::CurrentTemperature => Some(CharFormat::Float),
Self::TargetTemperature => Some(CharFormat::Float),
Self::CurrentRelativeHumidity => Some(CharFormat::Float),
Self::MotionDetected => Some(CharFormat::Bool),
Self::ContactSensorState => Some(CharFormat::Uint8),
Self::LockCurrentState => Some(CharFormat::Uint8),
Self::LockTargetState => Some(CharFormat::Uint8),
Self::BatteryLevel => Some(CharFormat::Uint8),
Self::StatusLowBattery => Some(CharFormat::Uint8),
Self::OutletInUse => Some(CharFormat::Bool),
_ => None,
}
}
}