objc2-home-kit 0.3.2

Bindings to the HomeKit framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// Represent an accessory in the home.
    ///
    ///
    /// This class represents an accessory in the home. There is a one to
    /// one relationship between a physical accessory and an object of this
    /// class. An accessory is composed of one or more services.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmaccessory?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct HMAccessory;
);

unsafe impl Send for HMAccessory {}

unsafe impl Sync for HMAccessory {}

extern_conformance!(
    unsafe impl NSObjectProtocol for HMAccessory {}
);

impl HMAccessory {
    extern_methods!(
        /// The name of the accessory.
        ///
        ///
        /// Returns the accessory's name that is associated with HomeKit. The initial value is the name
        /// provided by the accessory information service of the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub unsafe fn name(&self) -> Retained<NSString>;

        /// A unique identifier for the accessory.
        ///
        ///
        /// Use uniqueIdentifier to obtain the identifier for this object.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "No longer supported."]
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifier(&self) -> Retained<NSUUID>;

        /// A unique identifier for the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(uniqueIdentifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn uniqueIdentifier(&self) -> Retained<NSUUID>;

        /// Delegate object that receives updates on the state of the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn HMAccessoryDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn HMAccessoryDelegate>>,
        );

        /// TRUE if the accessory is currently reachable, FALSE otherwise.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(isReachable))]
        #[unsafe(method_family = none)]
        pub unsafe fn isReachable(&self) -> bool;

        /// This property indicates whether this accessory is behind a bridge. If it is TRUE,
        /// the accessory cannot be removed from the home directly. Only the bridge that owns
        /// this accessory can be removed and removing the bridge will remove this accessory
        /// from the home.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(isBridged))]
        #[unsafe(method_family = none)]
        pub unsafe fn isBridged(&self) -> bool;

        /// If this accessory is a bridge, this property is an array of NSUUID objects that,
        /// each of which represents the 'uniqueIdentifier' of the accessory vended by the bridge.
        ///
        ///
        /// Use uniqueIdentifiersForBridgedAccessories to obtain the identifiers for the
        /// bridged accessories.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "No longer supported."]
        #[unsafe(method(identifiersForBridgedAccessories))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifiersForBridgedAccessories(&self) -> Option<Retained<NSArray<NSUUID>>>;

        /// If this accessory is a bridge, this property is an array of NSUUID objects that,
        /// each of which represents the 'uniqueIdentifier' of the accessory vended by the bridge.
        ///
        ///
        /// An accessory can be standalone, a bridge, or hosted behind a bridge.
        /// - A standalone accessory would have its 'bridged' property set to FALSE and
        /// its 'uniqueIdentifiersForBridgedAccessories' property set to nil.
        /// - An accessory that is a bridge would have its 'bridged' property set to FALSE,
        /// but have a non-empty 'uniqueIdentifiersForBridgedAccessories' property.
        /// - An accessory behind a bridge would have its 'bridged' property set to TRUE and
        /// its 'uniqueIdentifiersForBridgedAccessories' property set to nil.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(uniqueIdentifiersForBridgedAccessories))]
        #[unsafe(method_family = none)]
        pub unsafe fn uniqueIdentifiersForBridgedAccessories(
            &self,
        ) -> Option<Retained<NSArray<NSUUID>>>;

        #[cfg(feature = "HMAccessoryCategory")]
        /// Category information for the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(category))]
        #[unsafe(method_family = none)]
        pub unsafe fn category(&self) -> Retained<HMAccessoryCategory>;

        #[cfg(feature = "HMRoom")]
        /// Room containing the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(room))]
        #[unsafe(method_family = none)]
        pub unsafe fn room(&self) -> Option<Retained<HMRoom>>;

        #[cfg(feature = "HMService")]
        /// Array of HMService objects that represent all the services provided by the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(services))]
        #[unsafe(method_family = none)]
        pub unsafe fn services(&self) -> Retained<NSArray<HMService>>;

        #[cfg(feature = "HMAccessoryProfile")]
        /// Accessory profiles of the receiver.
        #[unsafe(method(profiles))]
        #[unsafe(method_family = none)]
        pub unsafe fn profiles(&self) -> Retained<NSArray<HMAccessoryProfile>>;

        /// TRUE if the accessory is blocked, FALSE otherwise.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(isBlocked))]
        #[unsafe(method_family = none)]
        pub unsafe fn isBlocked(&self) -> bool;

        /// Model of the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(model))]
        #[unsafe(method_family = none)]
        pub unsafe fn model(&self) -> Option<Retained<NSString>>;

        /// Manufacturer of the accessory.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(manufacturer))]
        #[unsafe(method_family = none)]
        pub unsafe fn manufacturer(&self) -> Option<Retained<NSString>>;

        /// Accessory's firmware version.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(firmwareVersion))]
        #[unsafe(method_family = none)]
        pub unsafe fn firmwareVersion(&self) -> Option<Retained<NSString>>;

        /// Indicates if the accessory supports the identify action.
        #[unsafe(method(supportsIdentify))]
        #[unsafe(method_family = none)]
        pub unsafe fn supportsIdentify(&self) -> bool;

        /// The node identifier used to identify the device on Apple’s Matter fabric.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(matterNodeID))]
        #[unsafe(method_family = none)]
        pub unsafe fn matterNodeID(&self) -> Option<Retained<NSNumber>>;

        #[cfg(feature = "block2")]
        /// This method is used to change the name of the accessory.
        ///
        ///
        /// Parameter `name`: New name for the accessory.
        ///
        ///
        /// The new name is stored in HomeKit and not on the accessory.
        ///
        ///
        /// Parameter `completion`: Block that is invoked once the request is processed.
        /// The NSError provides more information on the status of the request, error
        /// will be nil on success.
        #[unsafe(method(updateName:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateName_completionHandler(
            &self,
            name: &NSString,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// This method is used to have an accessory identify itself.
        ///
        ///
        /// Parameter `completion`: Block that is invoked once the request is processed.
        /// The NSError provides more information on the status of the request, error
        /// will be nil on success.
        #[unsafe(method(identifyWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifyWithCompletionHandler(
            &self,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[deprecated = "HMAccessory objects are created by their parent container objects. Directly creating them is not supported."]
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl HMAccessory {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// This defines the protocol for a delegate to receive updates about
    /// different aspects of an accessory
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmaccessorydelegate?language=objc)
    pub unsafe trait HMAccessoryDelegate: NSObjectProtocol + Send + Sync {
        /// Informs the delegate when the name of the accessory is modified.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        #[optional]
        #[unsafe(method(accessoryDidUpdateName:))]
        #[unsafe(method_family = none)]
        unsafe fn accessoryDidUpdateName(&self, accessory: &HMAccessory);

        #[cfg(feature = "HMService")]
        /// Informs the delegate when the name of a service is modified.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        ///
        ///
        /// Parameter `service`: Service whose name was modified.
        #[optional]
        #[unsafe(method(accessory:didUpdateNameForService:))]
        #[unsafe(method_family = none)]
        unsafe fn accessory_didUpdateNameForService(
            &self,
            accessory: &HMAccessory,
            service: &HMService,
        );

        #[cfg(feature = "HMService")]
        /// Informs the delegate when the associated service type of a service is modified.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        ///
        ///
        /// Parameter `service`: Service whose associated service type was modified.
        #[optional]
        #[unsafe(method(accessory:didUpdateAssociatedServiceTypeForService:))]
        #[unsafe(method_family = none)]
        unsafe fn accessory_didUpdateAssociatedServiceTypeForService(
            &self,
            accessory: &HMAccessory,
            service: &HMService,
        );

        /// Informs the delegate when the services on the accessory have been dynamically updated.
        /// The services discovered are accessible via the 'services' property of the accessory.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        #[optional]
        #[unsafe(method(accessoryDidUpdateServices:))]
        #[unsafe(method_family = none)]
        unsafe fn accessoryDidUpdateServices(&self, accessory: &HMAccessory);

        #[cfg(feature = "HMAccessoryProfile")]
        /// Informs the delegate when a profile is added to an accessory.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        ///
        /// Parameter `profile`: The added profile.
        #[optional]
        #[unsafe(method(accessory:didAddProfile:))]
        #[unsafe(method_family = none)]
        unsafe fn accessory_didAddProfile(
            &self,
            accessory: &HMAccessory,
            profile: &HMAccessoryProfile,
        );

        #[cfg(feature = "HMAccessoryProfile")]
        /// Informs the delegate when a profile is removed from an accessory.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        ///
        /// Parameter `profile`: The removed profile.
        #[optional]
        #[unsafe(method(accessory:didRemoveProfile:))]
        #[unsafe(method_family = none)]
        unsafe fn accessory_didRemoveProfile(
            &self,
            accessory: &HMAccessory,
            profile: &HMAccessoryProfile,
        );

        /// Informs the delegate when the reachability of the accessory changes.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        #[optional]
        #[unsafe(method(accessoryDidUpdateReachability:))]
        #[unsafe(method_family = none)]
        unsafe fn accessoryDidUpdateReachability(&self, accessory: &HMAccessory);

        #[cfg(all(feature = "HMCharacteristic", feature = "HMService"))]
        /// Informs the delegate of a change in value of a characteristic.
        ///
        ///
        /// Parameter `accessory`: Sender of this message
        ///
        ///
        /// Parameter `service`: HMService that contains the characteristic whose value was modified.
        ///
        ///
        /// Parameter `characteristic`: The characteristic whose value was changed.
        #[optional]
        #[unsafe(method(accessory:service:didUpdateValueForCharacteristic:))]
        #[unsafe(method_family = none)]
        unsafe fn accessory_service_didUpdateValueForCharacteristic(
            &self,
            accessory: &HMAccessory,
            service: &HMService,
            characteristic: &HMCharacteristic,
        );

        /// Informs the delegate when firmwareVersion has been changed for an accessory.
        ///
        ///
        /// Parameter `accessory`: Sender of the message.
        ///
        ///
        /// Parameter `firmwareVersion`: The newly updated firmwareVersion.
        #[optional]
        #[unsafe(method(accessory:didUpdateFirmwareVersion:))]
        #[unsafe(method_family = none)]
        unsafe fn accessory_didUpdateFirmwareVersion(
            &self,
            accessory: &HMAccessory,
            firmware_version: &NSString,
        );
    }
);