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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
//! 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 "C" {
    /// Specifies the key path for a characteristic in a NSPredicate
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmcharacteristickeypath?language=objc)
    pub static HMCharacteristicKeyPath: &'static NSString;
}

extern "C" {
    /// Specifies the key path for a characteristic value in a NSPredicate
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmcharacteristicvaluekeypath?language=objc)
    pub static HMCharacteristicValueKeyPath: &'static NSString;
}

extern "C" {
    /// Specifies the key path for a presence event in a NSPredicate
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmpresencekeypath?language=objc)
    pub static HMPresenceKeyPath: &'static NSString;
}

extern_class!(
    /// Triggers based on events.
    ///
    ///
    /// This class represents a trigger that is based on events.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmeventtrigger?language=objc)
    #[unsafe(super(HMTrigger, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "HMTrigger")]
    pub struct HMEventTrigger;
);

#[cfg(feature = "HMTrigger")]
unsafe impl Send for HMEventTrigger {}

#[cfg(feature = "HMTrigger")]
unsafe impl Sync for HMEventTrigger {}

#[cfg(feature = "HMTrigger")]
extern_conformance!(
    unsafe impl NSObjectProtocol for HMEventTrigger {}
);

#[cfg(feature = "HMTrigger")]
impl HMEventTrigger {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(feature = "HMEvent")]
        /// Initializes a new event trigger object.
        ///
        ///
        /// Parameter `name`: Name of the event trigger.
        ///
        ///
        /// Parameter `events`: Array of events that can trigger the evaluation of the trigger. Note: The trigger will
        /// be evaluated if any one of the events is true.
        ///
        ///
        /// Parameter `predicate`: The predicate to evaluate before executing any of the actions sets associated to this
        /// event.
        ///
        ///
        /// Returns: Instance object representing the event trigger.
        #[unsafe(method(initWithName:events:predicate:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_events_predicate(
            this: Allocated<Self>,
            name: &NSString,
            events: &NSArray<HMEvent>,
            predicate: Option<&NSPredicate>,
        ) -> Retained<Self>;

        #[cfg(feature = "HMEvent")]
        /// Initializes a new event trigger object.
        ///
        ///
        /// Parameter `name`: Name of the event trigger.
        ///
        ///
        /// Parameter `events`: Array of events that can trigger the evaluation of the trigger. Note: The trigger will
        /// be evaluated if any one of the events is true.
        ///
        ///
        /// Parameter `endEvents`: Array of end events that can trigger the restoration to the state before the scene was run.
        ///
        ///
        /// Parameter `recurrences`: Specifies the days of the week when the trigger is to be evaluated. Only the 'weekday' property
        /// is honored in NSDateComponents.
        ///
        ///
        /// Parameter `predicate`: The predicate to evaluate before executing any of the actions sets associated to this
        /// event.
        ///
        ///
        /// Returns: Instance object representing the event trigger.
        #[unsafe(method(initWithName:events:endEvents:recurrences:predicate:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_events_endEvents_recurrences_predicate(
            this: Allocated<Self>,
            name: &NSString,
            events: &NSArray<HMEvent>,
            end_events: Option<&NSArray<HMEvent>>,
            recurrences: Option<&NSArray<NSDateComponents>>,
            predicate: Option<&NSPredicate>,
        ) -> Retained<Self>;

        #[cfg(feature = "HMEvent")]
        /// The events associated with the trigger.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(events))]
        #[unsafe(method_family = none)]
        pub unsafe fn events(&self) -> Retained<NSArray<HMEvent>>;

        #[cfg(feature = "HMEvent")]
        /// The events that correspond to executing the restore of the scene before the trigger was executed.
        /// E.g. Execute the scene for 10 mins and restore original state is achieved by specifying a corresponding
        /// HMDurationEvent in the list of endEvents.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(endEvents))]
        #[unsafe(method_family = none)]
        pub unsafe fn endEvents(&self) -> Retained<NSArray<HMEvent>>;

        /// The predicate to evaluate before executing the action sets associated with the trigger.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(predicate))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicate(&self) -> Option<Retained<NSPredicate>>;

        /// recurrences Specifies the recurrences for when the trigger is evaluated. This only supports days of the week.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(recurrences))]
        #[unsafe(method_family = none)]
        pub unsafe fn recurrences(&self) -> Option<Retained<NSArray<NSDateComponents>>>;

        /// Specifies whether this trigger is executed only once after which the trigger is disabled.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(executeOnce))]
        #[unsafe(method_family = none)]
        pub unsafe fn executeOnce(&self) -> bool;

        #[cfg(feature = "HMEventTriggerActivationState")]
        /// Specifies the current activation state of the trigger.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(triggerActivationState))]
        #[unsafe(method_family = none)]
        pub unsafe fn triggerActivationState(&self) -> HMEventTriggerActivationState;

        #[cfg(all(feature = "HMEvent", feature = "block2"))]
        /// Adds a new event to the event trigger.
        ///
        ///
        /// Parameter `event`: Event to add to the event trigger.
        ///
        ///
        /// 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.
        #[deprecated = "Use updateEvents:completionHandler: instead"]
        #[unsafe(method(addEvent:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addEvent_completionHandler(
            &self,
            event: &HMEvent,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "HMEvent", feature = "block2"))]
        /// Removes the specified event from the event trigger.
        ///
        ///
        /// Parameter `event`: Event to remove from the event trigger.
        ///
        ///
        /// 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.
        #[deprecated = "Use updateEvents:completionHandler: instead"]
        #[unsafe(method(removeEvent:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeEvent_completionHandler(
            &self,
            event: &HMEvent,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "HMEvent", feature = "block2"))]
        /// Updates the set of events in the event trigger.
        ///
        ///
        /// Parameter `events`: Events to update in the event trigger
        ///
        ///
        /// 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(updateEvents:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateEvents_completionHandler(
            &self,
            events: &NSArray<HMEvent>,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "HMEvent", feature = "block2"))]
        /// Updates the set of events in the event trigger.
        ///
        ///
        /// Parameter `endEvents`: Events to update in the event trigger
        ///
        ///
        /// 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(updateEndEvents:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateEndEvents_completionHandler(
            &self,
            end_events: &NSArray<HMEvent>,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// This method replaces the predicate used to evaluate execution of the action sets associated with the trigger.
        ///
        ///
        /// Parameter `predicate`: The new predicate for the event trigger.
        ///
        ///
        /// 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(updatePredicate:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updatePredicate_completionHandler(
            &self,
            predicate: Option<&NSPredicate>,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// This method replaces the recurrences which secifies the days of the week when the trigger is to be evaluated.
        ///
        ///
        /// Parameter `recurrences`: The new recurrences for the event trigger.
        ///
        ///
        /// 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(updateRecurrences:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateRecurrences_completionHandler(
            &self,
            recurrences: Option<&NSArray<NSDateComponents>>,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// This method is used to update whether the event trigger repeats or not.
        ///
        ///
        /// Parameter `executeOnce`: Specifies whether the event trigger is repeated or not.
        ///
        ///
        /// 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(updateExecuteOnce:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateExecuteOnce_completionHandler(
            &self,
            execute_once: bool,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );
    );
}

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

/// NSPredicate.
#[cfg(feature = "HMTrigger")]
impl HMEventTrigger {
    extern_methods!(
        /// Creates a predicate that will evaluate whether the event occurred before a significant event.
        ///
        ///
        /// Parameter `significantEvent`: The significant event to compare against.
        /// The valid values are: HMSignificantEventSunrise and HMSignificantEventSunset.
        ///
        ///
        /// Parameter `offset`: An offset from the time of the signficant event. To specify an offset before the significant event, the
        /// properties of the NSDateComponents must be negative value. e.g. To specify 30 mins before sunset, the
        /// 'minute' property must be set to -30.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[deprecated = "Use predicateForEvaluatingTriggerOccurringBeforeSignificantEvent: instead"]
        #[unsafe(method(predicateForEvaluatingTriggerOccurringBeforeSignificantEvent:applyingOffset:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringBeforeSignificantEvent_applyingOffset(
            significant_event: &NSString,
            offset: Option<&NSDateComponents>,
        ) -> Retained<NSPredicate>;

        #[cfg(all(
            feature = "HMEvent",
            feature = "HMSignificantTimeEvent",
            feature = "HMTimeEvent"
        ))]
        /// Creates a predicate that will evaluate whether the event occurred before a significant event.
        ///
        ///
        /// Parameter `significantEvent`: The significant event to compare against.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringBeforeSignificantEvent:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringBeforeSignificantEvent(
            significant_event: &HMSignificantTimeEvent,
        ) -> Retained<NSPredicate>;

        /// Creates a predicate that will evaluate whether the event occurred after a significant event.
        ///
        ///
        /// Parameter `significantEvent`: The significant event to compare against.
        /// The valid values are: HMSignificantEventSunrise and HMSignificantEventSunset.
        ///
        ///
        /// Parameter `offset`: An offset from the time of the signficant event. To specify an offset after the significant event, the
        /// properties of the NSDateComponents must be positive value. e.g. To specify 30 mins after sunset, the
        /// 'minute' property must be set to 30.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[deprecated = "Use predicateForEvaluatingTriggerOccurringAfterSignificantEvent: instead"]
        #[unsafe(method(predicateForEvaluatingTriggerOccurringAfterSignificantEvent:applyingOffset:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringAfterSignificantEvent_applyingOffset(
            significant_event: &NSString,
            offset: Option<&NSDateComponents>,
        ) -> Retained<NSPredicate>;

        #[cfg(all(
            feature = "HMEvent",
            feature = "HMSignificantTimeEvent",
            feature = "HMTimeEvent"
        ))]
        /// Creates a predicate that will evaluate whether the event occurred after a significant event.
        ///
        ///
        /// Parameter `significantEvent`: The significant event to compare against.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringAfterSignificantEvent:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringAfterSignificantEvent(
            significant_event: &HMSignificantTimeEvent,
        ) -> Retained<NSPredicate>;

        #[cfg(all(
            feature = "HMEvent",
            feature = "HMSignificantTimeEvent",
            feature = "HMTimeEvent"
        ))]
        /// Creates a predicate that will evaluate whether the event occurred between two significant events.
        ///
        ///
        /// Parameter `firstSignificantEvent`: The first significant event.
        ///
        ///
        /// Parameter `secondSignificantEvent`: The second significant event.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringBetweenSignificantEvent:secondSignificantEvent:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringBetweenSignificantEvent_secondSignificantEvent(
            first_significant_event: &HMSignificantTimeEvent,
            second_significant_event: &HMSignificantTimeEvent,
        ) -> Retained<NSPredicate>;

        /// Creates a predicate that will evaluate whether the event occurred before the time specified.
        ///
        ///
        /// Parameter `dateComponents`: Date components representing the time to compare against when the event occurs.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringBeforeDateWithComponents:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringBeforeDateWithComponents(
            date_components: &NSDateComponents,
        ) -> Retained<NSPredicate>;

        /// Creates a predicate that will evaluate whether the event occurred at the time specified.
        ///
        ///
        /// Parameter `dateComponents`: Date components representing the time to compare against when the event occurs.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringOnDateWithComponents:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringOnDateWithComponents(
            date_components: &NSDateComponents,
        ) -> Retained<NSPredicate>;

        /// Creates a predicate that will evaluate whether the event occurred at or after the time specified.
        ///
        ///
        /// Parameter `dateComponents`: Date components representing the time to compare against when the event occurs.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringAfterDateWithComponents:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringAfterDateWithComponents(
            date_components: &NSDateComponents,
        ) -> Retained<NSPredicate>;

        /// Creates a predicate that will evaluate whether the event occurred between two times.
        ///
        ///
        /// Parameter `firstDateComponents`: The first date component.
        ///
        ///
        /// Parameter `secondDateWithComponents`: The second date component.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerOccurringBetweenDateWithComponents:secondDateWithComponents:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerOccurringBetweenDateWithComponents_secondDateWithComponents(
            first_date_components: &NSDateComponents,
            second_date_with_components: &NSDateComponents,
        ) -> Retained<NSPredicate>;

        #[cfg(feature = "HMCharacteristic")]
        /// Creates a predicate that will evaluate whether a characteristic value is related to the specified value.
        ///
        ///
        /// Parameter `characteristic`: The characteristic that is evaluated as part of the predicate.
        ///
        ///
        /// Parameter `operatorType`: The relation between the characteristic and the target value.
        /// This can be either Less Than, Greater Than, Less Than or Equal, Greater Than or Equal, Equal, or Not Equal.
        /// Anything else will cause an exception to be thrown.
        ///
        ///
        /// Parameter `value`: The value of the characteristic to compare when evaluating the predicate.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        ///
        /// # Safety
        ///
        /// `value` should be of the correct type.
        #[unsafe(method(predicateForEvaluatingTriggerWithCharacteristic:relatedBy:toValue:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerWithCharacteristic_relatedBy_toValue(
            characteristic: &HMCharacteristic,
            operator_type: NSPredicateOperatorType,
            value: &AnyObject,
        ) -> Retained<NSPredicate>;

        #[cfg(all(feature = "HMEvent", feature = "HMPresenceEvent"))]
        /// Creates a predicate that will evaluate based on the presence event.
        ///
        ///
        /// Parameter `presenceEvent`: The presenceEvent that is evaluated as part of the predicate.
        ///
        ///
        /// Returns: Predicate object representing a condition to evaluate before executing the action set.
        #[unsafe(method(predicateForEvaluatingTriggerWithPresence:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predicateForEvaluatingTriggerWithPresence(
            presence_event: &HMPresenceEvent,
        ) -> Retained<NSPredicate>;
    );
}