Skip to main content

hap_model/
generated.rs

1// @generated by `cargo xtask codegen-hap-types` from xtask/model/hap-types.json.
2// Do not edit by hand. Re-run the codegen command to regenerate.
3
4#![allow(clippy::match_same_arms)]
5
6#[allow(unused_imports)]
7use crate::format::CharFormat;
8use crate::uuid::Uuid;
9
10/// HAP-defined ServiceType (generated). `Unknown` carries any non-HAP UUID.
11#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12#[non_exhaustive]
13pub enum ServiceType {
14    /// HAP short type "3E".
15    AccessoryInformation,
16    /// HAP short type "A2".
17    ProtocolInformation,
18    /// HAP short type "43".
19    LightBulb,
20    /// HAP short type "49".
21    Switch,
22    /// HAP short type "47".
23    Outlet,
24    /// HAP short type "40".
25    Fan,
26    /// HAP short type "4A".
27    Thermostat,
28    /// HAP short type "8A".
29    TemperatureSensor,
30    /// HAP short type "82".
31    HumiditySensor,
32    /// HAP short type "85".
33    MotionSensor,
34    /// HAP short type "80".
35    ContactSensor,
36    /// HAP short type "41".
37    GarageDoorOpener,
38    /// HAP short type "45".
39    LockMechanism,
40    /// HAP short type "96".
41    Battery,
42    /// A type not in the generated table.
43    Unknown(Uuid),
44}
45
46impl ServiceType {
47    /// Map a parsed [`Uuid`] to its named variant, or `Unknown`.
48    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    /// The canonical [`Uuid`] for this type.
69    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/// HAP-defined CharacteristicType (generated). `Unknown` carries any non-HAP UUID.
119#[derive(Debug, Clone, PartialEq, Eq, Hash)]
120#[non_exhaustive]
121pub enum CharacteristicType {
122    /// HAP short type "14".
123    Identify,
124    /// HAP short type "20".
125    Manufacturer,
126    /// HAP short type "21".
127    Model,
128    /// HAP short type "23".
129    Name,
130    /// HAP short type "30".
131    SerialNumber,
132    /// HAP short type "52".
133    FirmwareRevision,
134    /// HAP short type "25".
135    On,
136    /// HAP short type "8".
137    Brightness,
138    /// HAP short type "13".
139    Hue,
140    /// HAP short type "2F".
141    Saturation,
142    /// HAP short type "CE".
143    ColorTemperature,
144    /// HAP short type "11".
145    CurrentTemperature,
146    /// HAP short type "35".
147    TargetTemperature,
148    /// HAP short type "10".
149    CurrentRelativeHumidity,
150    /// HAP short type "22".
151    MotionDetected,
152    /// HAP short type "6A".
153    ContactSensorState,
154    /// HAP short type "1D".
155    LockCurrentState,
156    /// HAP short type "1E".
157    LockTargetState,
158    /// HAP short type "68".
159    BatteryLevel,
160    /// HAP short type "79".
161    StatusLowBattery,
162    /// HAP short type "26".
163    OutletInUse,
164    /// A type not in the generated table.
165    Unknown(Uuid),
166}
167
168impl CharacteristicType {
169    /// Map a parsed [`Uuid`] to its named variant, or `Unknown`.
170    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    /// The canonical [`Uuid`] for this type.
198    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    /// The HAP default value format for this characteristic, if known.
268    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}