1#![allow(clippy::match_same_arms)]
5
6#[allow(unused_imports)]
7use crate::format::CharFormat;
8use crate::uuid::Uuid;
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12#[non_exhaustive]
13pub enum ServiceType {
14 AccessoryInformation,
16 ProtocolInformation,
18 LightBulb,
20 Switch,
22 Outlet,
24 Fan,
26 Thermostat,
28 TemperatureSensor,
30 HumiditySensor,
32 MotionSensor,
34 ContactSensor,
36 GarageDoorOpener,
38 LockMechanism,
40 Battery,
42 Unknown(Uuid),
44}
45
46impl ServiceType {
47 pub fn from_uuid(u: &Uuid) -> Self {
49 match u.as_full() {
50 "0000003e-0000-1000-8000-0026bb765291" => Self::AccessoryInformation,
51 "000000a2-0000-1000-8000-0026bb765291" => Self::ProtocolInformation,
52 "00000043-0000-1000-8000-0026bb765291" => Self::LightBulb,
53 "00000049-0000-1000-8000-0026bb765291" => Self::Switch,
54 "00000047-0000-1000-8000-0026bb765291" => Self::Outlet,
55 "00000040-0000-1000-8000-0026bb765291" => Self::Fan,
56 "0000004a-0000-1000-8000-0026bb765291" => Self::Thermostat,
57 "0000008a-0000-1000-8000-0026bb765291" => Self::TemperatureSensor,
58 "00000082-0000-1000-8000-0026bb765291" => Self::HumiditySensor,
59 "00000085-0000-1000-8000-0026bb765291" => Self::MotionSensor,
60 "00000080-0000-1000-8000-0026bb765291" => Self::ContactSensor,
61 "00000041-0000-1000-8000-0026bb765291" => Self::GarageDoorOpener,
62 "00000045-0000-1000-8000-0026bb765291" => Self::LockMechanism,
63 "00000096-0000-1000-8000-0026bb765291" => Self::Battery,
64 _ => Self::Unknown(u.clone()),
65 }
66 }
67
68 pub fn uuid(&self) -> Uuid {
70 match self {
71 Self::AccessoryInformation => {
72 Uuid::from_full_unchecked("0000003e-0000-1000-8000-0026bb765291".to_string())
73 }
74 Self::ProtocolInformation => {
75 Uuid::from_full_unchecked("000000a2-0000-1000-8000-0026bb765291".to_string())
76 }
77 Self::LightBulb => {
78 Uuid::from_full_unchecked("00000043-0000-1000-8000-0026bb765291".to_string())
79 }
80 Self::Switch => {
81 Uuid::from_full_unchecked("00000049-0000-1000-8000-0026bb765291".to_string())
82 }
83 Self::Outlet => {
84 Uuid::from_full_unchecked("00000047-0000-1000-8000-0026bb765291".to_string())
85 }
86 Self::Fan => {
87 Uuid::from_full_unchecked("00000040-0000-1000-8000-0026bb765291".to_string())
88 }
89 Self::Thermostat => {
90 Uuid::from_full_unchecked("0000004a-0000-1000-8000-0026bb765291".to_string())
91 }
92 Self::TemperatureSensor => {
93 Uuid::from_full_unchecked("0000008a-0000-1000-8000-0026bb765291".to_string())
94 }
95 Self::HumiditySensor => {
96 Uuid::from_full_unchecked("00000082-0000-1000-8000-0026bb765291".to_string())
97 }
98 Self::MotionSensor => {
99 Uuid::from_full_unchecked("00000085-0000-1000-8000-0026bb765291".to_string())
100 }
101 Self::ContactSensor => {
102 Uuid::from_full_unchecked("00000080-0000-1000-8000-0026bb765291".to_string())
103 }
104 Self::GarageDoorOpener => {
105 Uuid::from_full_unchecked("00000041-0000-1000-8000-0026bb765291".to_string())
106 }
107 Self::LockMechanism => {
108 Uuid::from_full_unchecked("00000045-0000-1000-8000-0026bb765291".to_string())
109 }
110 Self::Battery => {
111 Uuid::from_full_unchecked("00000096-0000-1000-8000-0026bb765291".to_string())
112 }
113 Self::Unknown(u) => u.clone(),
114 }
115 }
116}
117
118#[derive(Debug, Clone, PartialEq, Eq, Hash)]
120#[non_exhaustive]
121pub enum CharacteristicType {
122 Identify,
124 Manufacturer,
126 Model,
128 Name,
130 SerialNumber,
132 FirmwareRevision,
134 On,
136 Brightness,
138 Hue,
140 Saturation,
142 ColorTemperature,
144 CurrentTemperature,
146 TargetTemperature,
148 CurrentRelativeHumidity,
150 MotionDetected,
152 ContactSensorState,
154 LockCurrentState,
156 LockTargetState,
158 BatteryLevel,
160 StatusLowBattery,
162 OutletInUse,
164 Unknown(Uuid),
166}
167
168impl CharacteristicType {
169 pub fn from_uuid(u: &Uuid) -> Self {
171 match u.as_full() {
172 "00000014-0000-1000-8000-0026bb765291" => Self::Identify,
173 "00000020-0000-1000-8000-0026bb765291" => Self::Manufacturer,
174 "00000021-0000-1000-8000-0026bb765291" => Self::Model,
175 "00000023-0000-1000-8000-0026bb765291" => Self::Name,
176 "00000030-0000-1000-8000-0026bb765291" => Self::SerialNumber,
177 "00000052-0000-1000-8000-0026bb765291" => Self::FirmwareRevision,
178 "00000025-0000-1000-8000-0026bb765291" => Self::On,
179 "00000008-0000-1000-8000-0026bb765291" => Self::Brightness,
180 "00000013-0000-1000-8000-0026bb765291" => Self::Hue,
181 "0000002f-0000-1000-8000-0026bb765291" => Self::Saturation,
182 "000000ce-0000-1000-8000-0026bb765291" => Self::ColorTemperature,
183 "00000011-0000-1000-8000-0026bb765291" => Self::CurrentTemperature,
184 "00000035-0000-1000-8000-0026bb765291" => Self::TargetTemperature,
185 "00000010-0000-1000-8000-0026bb765291" => Self::CurrentRelativeHumidity,
186 "00000022-0000-1000-8000-0026bb765291" => Self::MotionDetected,
187 "0000006a-0000-1000-8000-0026bb765291" => Self::ContactSensorState,
188 "0000001d-0000-1000-8000-0026bb765291" => Self::LockCurrentState,
189 "0000001e-0000-1000-8000-0026bb765291" => Self::LockTargetState,
190 "00000068-0000-1000-8000-0026bb765291" => Self::BatteryLevel,
191 "00000079-0000-1000-8000-0026bb765291" => Self::StatusLowBattery,
192 "00000026-0000-1000-8000-0026bb765291" => Self::OutletInUse,
193 _ => Self::Unknown(u.clone()),
194 }
195 }
196
197 pub fn uuid(&self) -> Uuid {
199 match self {
200 Self::Identify => {
201 Uuid::from_full_unchecked("00000014-0000-1000-8000-0026bb765291".to_string())
202 }
203 Self::Manufacturer => {
204 Uuid::from_full_unchecked("00000020-0000-1000-8000-0026bb765291".to_string())
205 }
206 Self::Model => {
207 Uuid::from_full_unchecked("00000021-0000-1000-8000-0026bb765291".to_string())
208 }
209 Self::Name => {
210 Uuid::from_full_unchecked("00000023-0000-1000-8000-0026bb765291".to_string())
211 }
212 Self::SerialNumber => {
213 Uuid::from_full_unchecked("00000030-0000-1000-8000-0026bb765291".to_string())
214 }
215 Self::FirmwareRevision => {
216 Uuid::from_full_unchecked("00000052-0000-1000-8000-0026bb765291".to_string())
217 }
218 Self::On => {
219 Uuid::from_full_unchecked("00000025-0000-1000-8000-0026bb765291".to_string())
220 }
221 Self::Brightness => {
222 Uuid::from_full_unchecked("00000008-0000-1000-8000-0026bb765291".to_string())
223 }
224 Self::Hue => {
225 Uuid::from_full_unchecked("00000013-0000-1000-8000-0026bb765291".to_string())
226 }
227 Self::Saturation => {
228 Uuid::from_full_unchecked("0000002f-0000-1000-8000-0026bb765291".to_string())
229 }
230 Self::ColorTemperature => {
231 Uuid::from_full_unchecked("000000ce-0000-1000-8000-0026bb765291".to_string())
232 }
233 Self::CurrentTemperature => {
234 Uuid::from_full_unchecked("00000011-0000-1000-8000-0026bb765291".to_string())
235 }
236 Self::TargetTemperature => {
237 Uuid::from_full_unchecked("00000035-0000-1000-8000-0026bb765291".to_string())
238 }
239 Self::CurrentRelativeHumidity => {
240 Uuid::from_full_unchecked("00000010-0000-1000-8000-0026bb765291".to_string())
241 }
242 Self::MotionDetected => {
243 Uuid::from_full_unchecked("00000022-0000-1000-8000-0026bb765291".to_string())
244 }
245 Self::ContactSensorState => {
246 Uuid::from_full_unchecked("0000006a-0000-1000-8000-0026bb765291".to_string())
247 }
248 Self::LockCurrentState => {
249 Uuid::from_full_unchecked("0000001d-0000-1000-8000-0026bb765291".to_string())
250 }
251 Self::LockTargetState => {
252 Uuid::from_full_unchecked("0000001e-0000-1000-8000-0026bb765291".to_string())
253 }
254 Self::BatteryLevel => {
255 Uuid::from_full_unchecked("00000068-0000-1000-8000-0026bb765291".to_string())
256 }
257 Self::StatusLowBattery => {
258 Uuid::from_full_unchecked("00000079-0000-1000-8000-0026bb765291".to_string())
259 }
260 Self::OutletInUse => {
261 Uuid::from_full_unchecked("00000026-0000-1000-8000-0026bb765291".to_string())
262 }
263 Self::Unknown(u) => u.clone(),
264 }
265 }
266
267 pub fn default_format(&self) -> Option<CharFormat> {
269 match self {
270 Self::Identify => Some(CharFormat::Bool),
271 Self::Manufacturer => Some(CharFormat::String),
272 Self::Model => Some(CharFormat::String),
273 Self::Name => Some(CharFormat::String),
274 Self::SerialNumber => Some(CharFormat::String),
275 Self::FirmwareRevision => Some(CharFormat::String),
276 Self::On => Some(CharFormat::Bool),
277 Self::Brightness => Some(CharFormat::Int),
278 Self::Hue => Some(CharFormat::Float),
279 Self::Saturation => Some(CharFormat::Float),
280 Self::ColorTemperature => Some(CharFormat::Uint32),
281 Self::CurrentTemperature => Some(CharFormat::Float),
282 Self::TargetTemperature => Some(CharFormat::Float),
283 Self::CurrentRelativeHumidity => Some(CharFormat::Float),
284 Self::MotionDetected => Some(CharFormat::Bool),
285 Self::ContactSensorState => Some(CharFormat::Uint8),
286 Self::LockCurrentState => Some(CharFormat::Uint8),
287 Self::LockTargetState => Some(CharFormat::Uint8),
288 Self::BatteryLevel => Some(CharFormat::Uint8),
289 Self::StatusLowBattery => Some(CharFormat::Uint8),
290 Self::OutletInUse => Some(CharFormat::Bool),
291 _ => None,
292 }
293 }
294}