/
Characteristic.ts
2287 lines (2120 loc) · 87.6 KB
/
Characteristic.ts
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import assert from "assert";
import createDebug from "debug";
import { EventEmitter } from "events";
import { CharacteristicJsonObject } from "../internal-types";
import { CharacteristicValue, Nullable, VoidCallback } from "../types";
import { CharacteristicWarningType } from "./Accessory";
import {
AccessCodeControlPoint,
AccessCodeSupportedConfiguration,
AccessControlLevel,
AccessoryFlags,
AccessoryIdentifier,
Active,
ActiveIdentifier,
ActivityInterval,
AdministratorOnlyAccess,
AirParticulateDensity,
AirParticulateSize,
AirPlayEnable,
AirQuality,
AppMatchingIdentifier,
AssetUpdateReadiness,
AudioFeedback,
BatteryLevel,
Brightness,
ButtonEvent,
CameraOperatingModeIndicator,
CarbonDioxideDetected,
CarbonDioxideLevel,
CarbonDioxidePeakLevel,
CarbonMonoxideDetected,
CarbonMonoxideLevel,
CarbonMonoxidePeakLevel,
Category,
CCAEnergyDetectThreshold,
CCASignalDetectThreshold,
CharacteristicValueActiveTransitionCount,
CharacteristicValueTransitionControl,
ChargingState,
ClosedCaptions,
ColorTemperature,
ConfigurationState,
ConfigureBridgedAccessory,
ConfigureBridgedAccessoryStatus,
ConfiguredName,
ContactSensorState,
CoolingThresholdTemperature,
CurrentAirPurifierState,
CurrentAmbientLightLevel,
CurrentDoorState,
CurrentFanState,
CurrentHeaterCoolerState,
CurrentHeatingCoolingState,
CurrentHorizontalTiltAngle,
CurrentHumidifierDehumidifierState,
CurrentMediaState,
CurrentPosition,
CurrentRelativeHumidity,
CurrentSlatState,
CurrentTemperature,
CurrentTiltAngle,
CurrentTime,
CurrentTransport,
CurrentVerticalTiltAngle,
CurrentVisibilityState,
DataStreamHAPTransport,
DataStreamHAPTransportInterrupt,
DayoftheWeek,
DiagonalFieldOfView,
DigitalZoom,
DiscoverBridgedAccessories,
DiscoveredBridgedAccessories,
DisplayOrder,
EventRetransmissionMaximum,
EventSnapshotsActive,
EventTransmissionCounters,
FilterChangeIndication,
FilterLifeLevel,
FirmwareRevision,
FirmwareUpdateReadiness,
FirmwareUpdateStatus,
HardwareFinish,
HardwareRevision,
HeartBeat,
HeatingThresholdTemperature,
HoldPosition,
HomeKitCameraActive,
Hue,
Identifier,
Identify,
ImageMirroring,
ImageRotation,
InputDeviceType,
InputSourceType,
InUse,
IsConfigured,
LeakDetected,
LinkQuality,
ListPairings,
LockControlPoint,
LockCurrentState,
LockLastKnownAction,
LockManagementAutoSecurityTimeout,
LockPhysicalControls,
LockTargetState,
Logs,
MACRetransmissionMaximum,
MACTransmissionCounters,
ManagedNetworkEnable,
ManuallyDisabled,
Manufacturer,
MaximumTransmitPower,
Model,
MotionDetected,
MultifunctionButton,
Mute,
Name,
NetworkAccessViolationControl,
NetworkClientProfileControl,
NetworkClientStatusControl,
NFCAccessControlPoint,
NFCAccessSupportedConfiguration,
NightVision,
NitrogenDioxideDensity,
ObstructionDetected,
OccupancyDetected,
On,
OperatingStateResponse,
OpticalZoom,
OutletInUse,
OzoneDensity,
PairingFeatures,
PairSetup,
PairVerify,
PasswordSetting,
PeriodicSnapshotsActive,
PictureMode,
Ping,
PM10Density,
PM2_5Density,
PositionState,
PowerModeSelection,
ProductData,
ProgrammableSwitchEvent,
ProgrammableSwitchOutputState,
ProgramMode,
Reachable,
ReceivedSignalStrengthIndication,
ReceiverSensitivity,
RecordingAudioActive,
RelativeHumidityDehumidifierThreshold,
RelativeHumidityHumidifierThreshold,
RelayControlPoint,
RelayEnabled,
RelayState,
RemainingDuration,
RemoteKey,
ResetFilterIndication,
RotationDirection,
RotationSpeed,
RouterStatus,
Saturation,
SecuritySystemAlarmType,
SecuritySystemCurrentState,
SecuritySystemTargetState,
SelectedAudioStreamConfiguration,
SelectedCameraRecordingConfiguration,
SelectedDiagnosticsModes,
SelectedRTPStreamConfiguration,
SerialNumber,
ServiceLabelIndex,
ServiceLabelNamespace,
SetDuration,
SetupDataStreamTransport,
SetupEndpoints,
SetupTransferTransport,
SignalToNoiseRatio,
SiriEnable,
SiriEndpointSessionStatus,
SiriEngineVersion,
SiriInputType,
SiriLightOnUse,
SiriListening,
SiriTouchToUse,
SlatType,
SleepDiscoveryMode,
SleepInterval,
SmokeDetected,
SoftwareRevision,
StagedFirmwareVersion,
StatusActive,
StatusFault,
StatusJammed,
StatusLowBattery,
StatusTampered,
StreamingStatus,
SulphurDioxideDensity,
SupportedAssetTypes,
SupportedAudioRecordingConfiguration,
SupportedAudioStreamConfiguration,
SupportedCameraRecordingConfiguration,
SupportedCharacteristicValueTransitionConfiguration,
SupportedDataStreamTransportConfiguration,
SupportedDiagnosticsModes,
SupportedDiagnosticsSnapshot,
SupportedFirmwareUpdateConfiguration,
SupportedRouterConfiguration,
SupportedRTPConfiguration,
SupportedTransferTransportConfiguration,
SupportedVideoRecordingConfiguration,
SupportedVideoStreamConfiguration,
SwingMode,
TargetAirPurifierState,
TargetAirQuality,
TargetControlList,
TargetControlSupportedConfiguration,
TargetDoorState,
TargetFanState,
TargetHeaterCoolerState,
TargetHeatingCoolingState,
TargetHorizontalTiltAngle,
TargetHumidifierDehumidifierState,
TargetMediaState,
TargetPosition,
TargetRelativeHumidity,
TargetSlatState,
TargetTemperature,
TargetTiltAngle,
TargetVerticalTiltAngle,
TargetVisibilityState,
TemperatureDisplayUnits,
ThirdPartyCameraActive,
ThreadControlPoint,
ThreadNodeCapabilities,
ThreadOpenThreadVersion,
ThreadStatus,
TimeUpdate,
TransmitPower,
TunnelConnectionTimeout,
TunneledAccessoryAdvertising,
TunneledAccessoryConnected,
TunneledAccessoryStateNumber,
ValveType,
Version,
VideoAnalysisActive,
VOCDensity,
Volume,
VolumeControlType,
VolumeSelector,
WakeConfiguration,
WANConfigurationList,
WANStatusList,
WaterLevel,
WiFiCapabilities,
WiFiConfigurationControl,
WiFiSatelliteStatus,
} from "./definitions";
import { HAPStatus, IsKnownHAPStatusError } from "./HAPServer";
import { IdentifierCache } from "./model/IdentifierCache";
import { clone } from "./util/clone";
import { HAPConnection } from "./util/eventedhttp";
import { HapStatusError } from "./util/hapStatusError";
import { once } from "./util/once";
import {
formatOutgoingCharacteristicValue,
isIntegerNumericFormat,
isNumericFormat,
isUnsignedNumericFormat,
numericLowerBound,
numericUpperBound,
} from "./util/request-util";
import { BASE_UUID, toShortForm } from "./util/uuid";
const debug = createDebug("HAP-NodeJS:Characteristic");
export const enum Formats {
BOOL = "bool",
/**
* Signed 32-bit integer
*/
INT = "int", // signed 32-bit int
/**
* Signed 64-bit floating point
*/
FLOAT = "float",
/**
* String encoded in utf8
*/
STRING = "string",
/**
* Unsigned 8-bit integer.
*/
UINT8 = "uint8",
/**
* Unsigned 16-bit integer.
*/
UINT16 = "uint16",
/**
* Unsigned 32-bit integer.
*/
UINT32 = "uint32",
/**
* Unsigned 64-bit integer.
*/
UINT64 = "uint64",
/**
* Data is base64 encoded string.
*/
DATA = "data",
/**
* Base64 encoded tlv8 string.
*/
TLV8 = "tlv8",
/**
* @deprecated Not contained in the HAP spec
*/
ARRAY = "array",
/**
* @deprecated Not contained in the HAP spec
*/
DICTIONARY = "dict",
}
export const enum Units {
/**
* Celsius is the only temperature unit in the HomeKit Accessory Protocol.
* Unit conversion is always done on the client side e.g. on the iPhone in the Home App depending on
* the configured unit on the device itself.
*/
CELSIUS = "celsius",
PERCENTAGE = "percentage",
ARC_DEGREE = "arcdegrees",
LUX = "lux",
SECONDS = "seconds",
}
export const enum Perms {
// noinspection JSUnusedGlobalSymbols
/**
* @deprecated replaced by {@link PAIRED_READ}. Kept for backwards compatibility.
*/
READ = "pr",
/**
* @deprecated replaced by {@link PAIRED_WRITE}. Kept for backwards compatibility.
*/
WRITE = "pw",
PAIRED_READ = "pr",
PAIRED_WRITE = "pw",
NOTIFY = "ev",
EVENTS = "ev",
ADDITIONAL_AUTHORIZATION = "aa",
TIMED_WRITE = "tw",
HIDDEN = "hd",
WRITE_RESPONSE = "wr",
}
export interface CharacteristicProps {
format: Formats | string;
perms: Perms[];
unit?: Units | string;
description?: string;
/**
* Defines the minimum value for a numeric characteristic
*/
minValue?: number;
/**
* Defines the maximum value for a numeric characteristic
*/
maxValue?: number;
minStep?: number;
/**
* Maximum number of characters when format is {@link Formats.STRING}.
* Default is 64 characters. Maximum allowed is 256 characters.
*/
maxLen?: number;
/**
* Maximum number of characters when format is {@link Formats.DATA}.
* Default is 2097152 characters.
*/
maxDataLen?: number;
/**
* Defines a array of valid values to be used for the characteristic.
*/
validValues?: number[];
/**
* Two element array where the first value specifies the lowest valid value and
* the second element specifies the highest valid value.
*/
validValueRanges?: [min: number, max: number];
adminOnlyAccess?: Access[];
}
export const enum Access {
READ = 0x00,
WRITE = 0x01,
NOTIFY = 0x02
}
export type CharacteristicChange = {
originator?: HAPConnection,
newValue: Nullable<CharacteristicValue>;
oldValue: Nullable<CharacteristicValue>;
reason: ChangeReason,
context?: CharacteristicContext;
};
export const enum ChangeReason {
/**
* Reason used when HomeKit writes a value or the API user calls {@link Characteristic.setValue}.
*/
WRITE = "write",
/**
* Reason used when the API user calls the method {@link Characteristic.updateValue}.
*/
UPDATE = "update",
/**
* Used when when HomeKit reads a value or the API user calls the deprecated method {@link Characteristic.getValue}.
*/
READ = "read",
/**
* Used when call to {@link Characteristic.sendEventNotification} was made.
*/
EVENT = "event",
}
/**
* This format for a context object can be used to pass to any characteristic write operation.
* It can contain additional information used by the internal event handlers of hap-nodejs.
* The context object can be combined with any custom data for own use.
*/
export interface CharacteristicOperationContext {
/**
* If set to true for any characteristic write operation
* the Accessory won't send any event notifications to HomeKit controllers
* for that particular change.
*/
omitEventUpdate?: boolean;
}
/**
* @private
*/
export interface SerializedCharacteristic {
displayName: string,
UUID: string,
eventOnlyCharacteristic: boolean,
constructorName?: string,
value: Nullable<CharacteristicValue>,
props: CharacteristicProps,
}
export const enum CharacteristicEventTypes {
/**
* This event is thrown when a HomeKit controller wants to read the current value of the characteristic.
* The event handler should call the supplied callback as fast as possible.
*
* HAP-NodeJS will complain about slow running get handlers after 3 seconds and terminate the request after 10 seconds.
*/
GET = "get",
/**
* This event is thrown when a HomeKit controller wants to write a new value to the characteristic.
* The event handler should call the supplied callback as fast as possible.
*
* HAP-NodeJS will complain about slow running set handlers after 3 seconds and terminate the request after 10 seconds.
*/
SET = "set",
/**
* Emitted after a new value is set for the characteristic.
* The new value can be set via a request by a HomeKit controller or via an API call.
*/
CHANGE = "change",
/**
* @private
*/
SUBSCRIBE = "subscribe",
/**
* @private
*/
UNSUBSCRIBE = "unsubscribe",
/**
* @private
*/
CHARACTERISTIC_WARNING = "characteristic-warning",
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type CharacteristicContext = any
export type CharacteristicGetCallback = (status?: HAPStatus | null | Error, value?: Nullable<CharacteristicValue>) => void;
export type CharacteristicSetCallback = (error?: HAPStatus | null | Error, writeResponse?: Nullable<CharacteristicValue>) => void;
export type CharacteristicGetHandler = (context: CharacteristicContext, connection?: HAPConnection)
=> Promise<Nullable<CharacteristicValue>> | Nullable<CharacteristicValue>;
export type CharacteristicSetHandler = (value: CharacteristicValue, context: CharacteristicContext, connection?: HAPConnection)
=> Promise<Nullable<CharacteristicValue> | void> | Nullable<CharacteristicValue> | void;
export type AdditionalAuthorizationHandler = (additionalAuthorizationData: string | undefined) => boolean;
export declare interface Characteristic {
on(event: "get", listener: (callback: CharacteristicGetCallback, context: CharacteristicContext, connection?: HAPConnection) => void): this;
on(
event: "set",
listener: (value: CharacteristicValue, callback: CharacteristicSetCallback, context: CharacteristicContext, connection?: HAPConnection) => void
): this
on(event: "change", listener: (change: CharacteristicChange) => void): this;
/**
* @private
*/
on(event: "subscribe", listener: VoidCallback): this;
/**
* @private
*/
on(event: "unsubscribe", listener: VoidCallback): this;
/**
* @private
*/
on(event: "characteristic-warning", listener: (type: CharacteristicWarningType, message: string, stack?: string) => void): this;
/**
* @private
*/
emit(event: "get", callback: CharacteristicGetCallback, context: CharacteristicContext, connection?: HAPConnection): boolean;
/**
* @private
*/
emit(event: "set", value: CharacteristicValue, callback: CharacteristicSetCallback, context: CharacteristicContext, connection?: HAPConnection): boolean;
/**
* @private
*/
emit(event: "change", change: CharacteristicChange): boolean;
/**
* @private
*/
emit(event: "subscribe"): boolean;
/**
* @private
*/
emit(event: "unsubscribe"): boolean;
/**
* @private
*/
emit(event: "characteristic-warning", type: CharacteristicWarningType, message: string, stack?: string): boolean;
}
class ValidValuesIterable implements Iterable<number> {
private readonly props: CharacteristicProps;
constructor(props: CharacteristicProps) {
assert(isNumericFormat(props.format), "Cannot instantiate valid values iterable when format is not numeric. Found " + props.format);
this.props = props;
}
*[Symbol.iterator](): Iterator<number> {
if (this.props.validValues) {
for (const value of this.props.validValues) {
yield value;
}
} else {
let min = 0; // default is zero for all the uint types
let max: number;
let stepValue = 1;
if (this.props.validValueRanges) {
min = this.props.validValueRanges[0];
max = this.props.validValueRanges[1];
} else if (this.props.minValue != null && this.props.maxValue != null) {
min = this.props.minValue;
max = this.props.maxValue;
if (this.props.minStep != null) {
stepValue = this.props.minStep;
}
} else if (isUnsignedNumericFormat(this.props.format)) {
max = numericUpperBound(this.props.format);
} else {
throw new Error("Could not find valid iterator strategy for props: " + JSON.stringify(this.props));
}
for (let i = min; i <= max; i += stepValue) {
yield i;
}
}
}
}
const numberPattern = /^-?\d+$/;
function extractHAPStatusFromError(error: Error) {
let errorValue = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
if (numberPattern.test(error.message)) {
const value = parseInt(error.message, 10);
if (IsKnownHAPStatusError(value)) {
errorValue = value;
}
}
return errorValue;
}
function maxWithUndefined(a?: number, b?: number): number | undefined {
if (a == null) {
return b;
} else if (b == null) {
return a;
} else {
return Math.max(a, b);
}
}
function minWithUndefined(a?: number, b?: number): number | undefined {
if (a == null) {
return b;
} else if (b == null) {
return a;
} else {
return Math.min(a, b);
}
}
/**
* Characteristic represents a particular typed variable that can be assigned to a Service. For instance, a
* "Hue" Characteristic might store a 'float' value of type 'arcdegrees'. You could add the Hue Characteristic
* to a {@link Service} in order to store that value. A particular Characteristic is distinguished from others by its
* UUID. HomeKit provides a set of known Characteristic UUIDs defined in HomeKit.ts along with a
* corresponding concrete subclass.
*
* You can also define custom Characteristics by providing your own UUID. Custom Characteristics can be added
* to any native or custom Services, but Siri will likely not be able to work with these.
*/
export class Characteristic extends EventEmitter {
/**
* @deprecated Please use the Formats const enum above.
*/
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
static Formats = Formats;
/**
* @deprecated Please use the Units const enum above.
*/
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
static Units = Units;
/**
* @deprecated Please use the Perms const enum above.
*/
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
static Perms = Perms;
// Pattern below is for automatic detection of the section of defined characteristics. Used by the generator
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
public static AccessCodeControlPoint: typeof AccessCodeControlPoint;
public static AccessCodeSupportedConfiguration: typeof AccessCodeSupportedConfiguration;
public static AccessControlLevel: typeof AccessControlLevel;
public static AccessoryFlags: typeof AccessoryFlags;
public static AccessoryIdentifier: typeof AccessoryIdentifier;
public static Active: typeof Active;
public static ActiveIdentifier: typeof ActiveIdentifier;
public static ActivityInterval: typeof ActivityInterval;
public static AdministratorOnlyAccess: typeof AdministratorOnlyAccess;
public static AirParticulateDensity: typeof AirParticulateDensity;
public static AirParticulateSize: typeof AirParticulateSize;
public static AirPlayEnable: typeof AirPlayEnable;
public static AirQuality: typeof AirQuality;
public static AppMatchingIdentifier: typeof AppMatchingIdentifier;
public static AssetUpdateReadiness: typeof AssetUpdateReadiness;
public static AudioFeedback: typeof AudioFeedback;
public static BatteryLevel: typeof BatteryLevel;
public static Brightness: typeof Brightness;
public static ButtonEvent: typeof ButtonEvent;
public static CameraOperatingModeIndicator: typeof CameraOperatingModeIndicator;
public static CarbonDioxideDetected: typeof CarbonDioxideDetected;
public static CarbonDioxideLevel: typeof CarbonDioxideLevel;
public static CarbonDioxidePeakLevel: typeof CarbonDioxidePeakLevel;
public static CarbonMonoxideDetected: typeof CarbonMonoxideDetected;
public static CarbonMonoxideLevel: typeof CarbonMonoxideLevel;
public static CarbonMonoxidePeakLevel: typeof CarbonMonoxidePeakLevel;
/**
* @deprecated Removed and not used anymore
*/
public static Category: typeof Category;
public static CCAEnergyDetectThreshold: typeof CCAEnergyDetectThreshold;
public static CCASignalDetectThreshold: typeof CCASignalDetectThreshold;
public static CharacteristicValueActiveTransitionCount: typeof CharacteristicValueActiveTransitionCount;
public static CharacteristicValueTransitionControl: typeof CharacteristicValueTransitionControl;
public static ChargingState: typeof ChargingState;
public static ClosedCaptions: typeof ClosedCaptions;
public static ColorTemperature: typeof ColorTemperature;
public static ConfigurationState: typeof ConfigurationState;
/**
* @deprecated Removed and not used anymore
*/
public static ConfigureBridgedAccessory: typeof ConfigureBridgedAccessory;
/**
* @deprecated Removed and not used anymore
*/
public static ConfigureBridgedAccessoryStatus: typeof ConfigureBridgedAccessoryStatus;
public static ConfiguredName: typeof ConfiguredName;
public static ContactSensorState: typeof ContactSensorState;
public static CoolingThresholdTemperature: typeof CoolingThresholdTemperature;
public static CurrentAirPurifierState: typeof CurrentAirPurifierState;
public static CurrentAmbientLightLevel: typeof CurrentAmbientLightLevel;
public static CurrentDoorState: typeof CurrentDoorState;
public static CurrentFanState: typeof CurrentFanState;
public static CurrentHeaterCoolerState: typeof CurrentHeaterCoolerState;
public static CurrentHeatingCoolingState: typeof CurrentHeatingCoolingState;
public static CurrentHorizontalTiltAngle: typeof CurrentHorizontalTiltAngle;
public static CurrentHumidifierDehumidifierState: typeof CurrentHumidifierDehumidifierState;
public static CurrentMediaState: typeof CurrentMediaState;
public static CurrentPosition: typeof CurrentPosition;
public static CurrentRelativeHumidity: typeof CurrentRelativeHumidity;
public static CurrentSlatState: typeof CurrentSlatState;
public static CurrentTemperature: typeof CurrentTemperature;
public static CurrentTiltAngle: typeof CurrentTiltAngle;
/**
* @deprecated Removed and not used anymore
*/
public static CurrentTime: typeof CurrentTime;
public static CurrentTransport: typeof CurrentTransport;
public static CurrentVerticalTiltAngle: typeof CurrentVerticalTiltAngle;
public static CurrentVisibilityState: typeof CurrentVisibilityState;
public static DataStreamHAPTransport: typeof DataStreamHAPTransport;
public static DataStreamHAPTransportInterrupt: typeof DataStreamHAPTransportInterrupt;
/**
* @deprecated Removed and not used anymore
*/
public static DayoftheWeek: typeof DayoftheWeek;
public static DiagonalFieldOfView: typeof DiagonalFieldOfView;
public static DigitalZoom: typeof DigitalZoom;
/**
* @deprecated Removed and not used anymore
*/
public static DiscoverBridgedAccessories: typeof DiscoverBridgedAccessories;
/**
* @deprecated Removed and not used anymore
*/
public static DiscoveredBridgedAccessories: typeof DiscoveredBridgedAccessories;
public static DisplayOrder: typeof DisplayOrder;
public static EventRetransmissionMaximum: typeof EventRetransmissionMaximum;
public static EventSnapshotsActive: typeof EventSnapshotsActive;
public static EventTransmissionCounters: typeof EventTransmissionCounters;
public static FilterChangeIndication: typeof FilterChangeIndication;
public static FilterLifeLevel: typeof FilterLifeLevel;
public static FirmwareRevision: typeof FirmwareRevision;
public static FirmwareUpdateReadiness: typeof FirmwareUpdateReadiness;
public static FirmwareUpdateStatus: typeof FirmwareUpdateStatus;
public static HardwareFinish: typeof HardwareFinish;
public static HardwareRevision: typeof HardwareRevision;
public static HeartBeat: typeof HeartBeat;
public static HeatingThresholdTemperature: typeof HeatingThresholdTemperature;
public static HoldPosition: typeof HoldPosition;
public static HomeKitCameraActive: typeof HomeKitCameraActive;
public static Hue: typeof Hue;
public static Identifier: typeof Identifier;
public static Identify: typeof Identify;
public static ImageMirroring: typeof ImageMirroring;
public static ImageRotation: typeof ImageRotation;
public static InputDeviceType: typeof InputDeviceType;
public static InputSourceType: typeof InputSourceType;
public static InUse: typeof InUse;
public static IsConfigured: typeof IsConfigured;
public static LeakDetected: typeof LeakDetected;
/**
* @deprecated Removed and not used anymore
*/
public static LinkQuality: typeof LinkQuality;
public static ListPairings: typeof ListPairings;
public static LockControlPoint: typeof LockControlPoint;
public static LockCurrentState: typeof LockCurrentState;
public static LockLastKnownAction: typeof LockLastKnownAction;
public static LockManagementAutoSecurityTimeout: typeof LockManagementAutoSecurityTimeout;
public static LockPhysicalControls: typeof LockPhysicalControls;
public static LockTargetState: typeof LockTargetState;
public static Logs: typeof Logs;
public static MACRetransmissionMaximum: typeof MACRetransmissionMaximum;
public static MACTransmissionCounters: typeof MACTransmissionCounters;
public static ManagedNetworkEnable: typeof ManagedNetworkEnable;
public static ManuallyDisabled: typeof ManuallyDisabled;
public static Manufacturer: typeof Manufacturer;
public static MaximumTransmitPower: typeof MaximumTransmitPower;
public static Model: typeof Model;
public static MotionDetected: typeof MotionDetected;
public static MultifunctionButton: typeof MultifunctionButton;
public static Mute: typeof Mute;
public static Name: typeof Name;
public static NetworkAccessViolationControl: typeof NetworkAccessViolationControl;
public static NetworkClientProfileControl: typeof NetworkClientProfileControl;
public static NetworkClientStatusControl: typeof NetworkClientStatusControl;
public static NFCAccessControlPoint: typeof NFCAccessControlPoint;
public static NFCAccessSupportedConfiguration: typeof NFCAccessSupportedConfiguration;
public static NightVision: typeof NightVision;
public static NitrogenDioxideDensity: typeof NitrogenDioxideDensity;
public static ObstructionDetected: typeof ObstructionDetected;
public static OccupancyDetected: typeof OccupancyDetected;
public static On: typeof On;
public static OperatingStateResponse: typeof OperatingStateResponse;
public static OpticalZoom: typeof OpticalZoom;
public static OutletInUse: typeof OutletInUse;
public static OzoneDensity: typeof OzoneDensity;
public static PairingFeatures: typeof PairingFeatures;
public static PairSetup: typeof PairSetup;
public static PairVerify: typeof PairVerify;
public static PasswordSetting: typeof PasswordSetting;
public static PeriodicSnapshotsActive: typeof PeriodicSnapshotsActive;
public static PictureMode: typeof PictureMode;
public static Ping: typeof Ping;
public static PM10Density: typeof PM10Density;
public static PM2_5Density: typeof PM2_5Density;
public static PositionState: typeof PositionState;
public static PowerModeSelection: typeof PowerModeSelection;
public static ProductData: typeof ProductData;
public static ProgrammableSwitchEvent: typeof ProgrammableSwitchEvent;
public static ProgrammableSwitchOutputState: typeof ProgrammableSwitchOutputState;
public static ProgramMode: typeof ProgramMode;
/**
* @deprecated Removed and not used anymore
*/
public static Reachable: typeof Reachable;
public static ReceivedSignalStrengthIndication: typeof ReceivedSignalStrengthIndication;
public static ReceiverSensitivity: typeof ReceiverSensitivity;
public static RecordingAudioActive: typeof RecordingAudioActive;
public static RelativeHumidityDehumidifierThreshold: typeof RelativeHumidityDehumidifierThreshold;
public static RelativeHumidityHumidifierThreshold: typeof RelativeHumidityHumidifierThreshold;
public static RelayControlPoint: typeof RelayControlPoint;
public static RelayEnabled: typeof RelayEnabled;
public static RelayState: typeof RelayState;
public static RemainingDuration: typeof RemainingDuration;
public static RemoteKey: typeof RemoteKey;
public static ResetFilterIndication: typeof ResetFilterIndication;
public static RotationDirection: typeof RotationDirection;
public static RotationSpeed: typeof RotationSpeed;
public static RouterStatus: typeof RouterStatus;
public static Saturation: typeof Saturation;
public static SecuritySystemAlarmType: typeof SecuritySystemAlarmType;
public static SecuritySystemCurrentState: typeof SecuritySystemCurrentState;
public static SecuritySystemTargetState: typeof SecuritySystemTargetState;
public static SelectedAudioStreamConfiguration: typeof SelectedAudioStreamConfiguration;
public static SelectedCameraRecordingConfiguration: typeof SelectedCameraRecordingConfiguration;
public static SelectedDiagnosticsModes: typeof SelectedDiagnosticsModes;
public static SelectedRTPStreamConfiguration: typeof SelectedRTPStreamConfiguration;
public static SerialNumber: typeof SerialNumber;
public static ServiceLabelIndex: typeof ServiceLabelIndex;
public static ServiceLabelNamespace: typeof ServiceLabelNamespace;
public static SetDuration: typeof SetDuration;
public static SetupDataStreamTransport: typeof SetupDataStreamTransport;
public static SetupEndpoints: typeof SetupEndpoints;
public static SetupTransferTransport: typeof SetupTransferTransport;
public static SignalToNoiseRatio: typeof SignalToNoiseRatio;
public static SiriEnable: typeof SiriEnable;
public static SiriEndpointSessionStatus: typeof SiriEndpointSessionStatus;
public static SiriEngineVersion: typeof SiriEngineVersion;
public static SiriInputType: typeof SiriInputType;
public static SiriLightOnUse: typeof SiriLightOnUse;
public static SiriListening: typeof SiriListening;
public static SiriTouchToUse: typeof SiriTouchToUse;
public static SlatType: typeof SlatType;
public static SleepDiscoveryMode: typeof SleepDiscoveryMode;
public static SleepInterval: typeof SleepInterval;
public static SmokeDetected: typeof SmokeDetected;
public static SoftwareRevision: typeof SoftwareRevision;
public static StagedFirmwareVersion: typeof StagedFirmwareVersion;
public static StatusActive: typeof StatusActive;
public static StatusFault: typeof StatusFault;
public static StatusJammed: typeof StatusJammed;
public static StatusLowBattery: typeof StatusLowBattery;
public static StatusTampered: typeof StatusTampered;
public static StreamingStatus: typeof StreamingStatus;
public static SulphurDioxideDensity: typeof SulphurDioxideDensity;
public static SupportedAssetTypes: typeof SupportedAssetTypes;
public static SupportedAudioRecordingConfiguration: typeof SupportedAudioRecordingConfiguration;
public static SupportedAudioStreamConfiguration: typeof SupportedAudioStreamConfiguration;
public static SupportedCameraRecordingConfiguration: typeof SupportedCameraRecordingConfiguration;
public static SupportedCharacteristicValueTransitionConfiguration: typeof SupportedCharacteristicValueTransitionConfiguration;
public static SupportedDataStreamTransportConfiguration: typeof SupportedDataStreamTransportConfiguration;
public static SupportedDiagnosticsModes: typeof SupportedDiagnosticsModes;
public static SupportedDiagnosticsSnapshot: typeof SupportedDiagnosticsSnapshot;
public static SupportedFirmwareUpdateConfiguration: typeof SupportedFirmwareUpdateConfiguration;
public static SupportedRouterConfiguration: typeof SupportedRouterConfiguration;
public static SupportedRTPConfiguration: typeof SupportedRTPConfiguration;
public static SupportedTransferTransportConfiguration: typeof SupportedTransferTransportConfiguration;
public static SupportedVideoRecordingConfiguration: typeof SupportedVideoRecordingConfiguration;
public static SupportedVideoStreamConfiguration: typeof SupportedVideoStreamConfiguration;
public static SwingMode: typeof SwingMode;
public static TargetAirPurifierState: typeof TargetAirPurifierState;
/**
* @deprecated Removed and not used anymore
*/
public static TargetAirQuality: typeof TargetAirQuality;
public static TargetControlList: typeof TargetControlList;
public static TargetControlSupportedConfiguration: typeof TargetControlSupportedConfiguration;
public static TargetDoorState: typeof TargetDoorState;
public static TargetFanState: typeof TargetFanState;
public static TargetHeaterCoolerState: typeof TargetHeaterCoolerState;
public static TargetHeatingCoolingState: typeof TargetHeatingCoolingState;
public static TargetHorizontalTiltAngle: typeof TargetHorizontalTiltAngle;
public static TargetHumidifierDehumidifierState: typeof TargetHumidifierDehumidifierState;
public static TargetMediaState: typeof TargetMediaState;
public static TargetPosition: typeof TargetPosition;
public static TargetRelativeHumidity: typeof TargetRelativeHumidity;
/**
* @deprecated Removed and not used anymore
*/
public static TargetSlatState: typeof TargetSlatState;
public static TargetTemperature: typeof TargetTemperature;
public static TargetTiltAngle: typeof TargetTiltAngle;
public static TargetVerticalTiltAngle: typeof TargetVerticalTiltAngle;
public static TargetVisibilityState: typeof TargetVisibilityState;
public static TemperatureDisplayUnits: typeof TemperatureDisplayUnits;
public static ThirdPartyCameraActive: typeof ThirdPartyCameraActive;
public static ThreadControlPoint: typeof ThreadControlPoint;
public static ThreadNodeCapabilities: typeof ThreadNodeCapabilities;
public static ThreadOpenThreadVersion: typeof ThreadOpenThreadVersion;
public static ThreadStatus: typeof ThreadStatus;
/**
* @deprecated Removed and not used anymore
*/
public static TimeUpdate: typeof TimeUpdate;
public static TransmitPower: typeof TransmitPower;
public static TunnelConnectionTimeout: typeof TunnelConnectionTimeout;
public static TunneledAccessoryAdvertising: typeof TunneledAccessoryAdvertising;
public static TunneledAccessoryConnected: typeof TunneledAccessoryConnected;
public static TunneledAccessoryStateNumber: typeof TunneledAccessoryStateNumber;
public static ValveType: typeof ValveType;
public static Version: typeof Version;
public static VideoAnalysisActive: typeof VideoAnalysisActive;
public static VOCDensity: typeof VOCDensity;
public static Volume: typeof Volume;
public static VolumeControlType: typeof VolumeControlType;
public static VolumeSelector: typeof VolumeSelector;
public static WakeConfiguration: typeof WakeConfiguration;
public static WANConfigurationList: typeof WANConfigurationList;
public static WANStatusList: typeof WANStatusList;
public static WaterLevel: typeof WaterLevel;
public static WiFiCapabilities: typeof WiFiCapabilities;
public static WiFiConfigurationControl: typeof WiFiConfigurationControl;
public static WiFiSatelliteStatus: typeof WiFiSatelliteStatus;
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// NOTICE: when adding/changing properties, remember to possibly adjust the serialize/deserialize functions
public displayName: string;
public UUID: string;
iid: Nullable<number> = null;
value: Nullable<CharacteristicValue> = null;
/**
* @deprecated replaced by {@link statusCode}
* @private
*/
status: Nullable<Error> = null;
/**
* @private
*/
statusCode: HAPStatus = HAPStatus.SUCCESS;
props: CharacteristicProps;
/**
* The {@link onGet} handler
*/
private getHandler?: CharacteristicGetHandler;
/**
* The {@link onSet} handler
*/
private setHandler?: CharacteristicSetHandler;
private subscriptions = 0;
/**
* @private
*/
additionalAuthorizationHandler?: AdditionalAuthorizationHandler;
public constructor(displayName: string, UUID: string, props: CharacteristicProps) {
super();
this.displayName = displayName;
this.UUID = UUID;
this.props = { // some weird defaults (with legacy constructor props was optional)
format: Formats.INT,
perms: [Perms.NOTIFY],
};
this.setProps(props || {}); // ensure sanity checks are called
}
/**
* Accepts a function that will be called to retrieve the current value of a Characteristic.
* The function must return a valid Characteristic value for the Characteristic type.
* May optionally return a promise.
*
* @example
* ```ts
* Characteristic.onGet(async () => {
* return true;
* });
* ```
* @param handler
*/
public onGet(handler: CharacteristicGetHandler): Characteristic {
if (typeof handler !== "function") {
this.characteristicWarning(".onGet handler must be a function");