hap-nodejs 1.0.0-alpha.23 → 1.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/BridgedCore.d.ts +2 -0
  2. package/dist/BridgedCore.d.ts.map +1 -0
  3. package/dist/BridgedCore.js +42 -0
  4. package/dist/BridgedCore.js.map +1 -0
  5. package/dist/Core.d.ts +2 -0
  6. package/dist/Core.d.ts.map +1 -0
  7. package/dist/Core.js +49 -0
  8. package/dist/Core.js.map +1 -0
  9. package/dist/accessories/AirConditioner_accessory.js +24 -24
  10. package/dist/accessories/AirConditioner_accessory.js.map +1 -1
  11. package/dist/accessories/AppleTVRemote_accessory.js +23 -23
  12. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
  13. package/dist/accessories/Camera_accessory.js +292 -373
  14. package/dist/accessories/Camera_accessory.js.map +1 -1
  15. package/dist/accessories/Fan_accessory.js +15 -21
  16. package/dist/accessories/Fan_accessory.js.map +1 -1
  17. package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
  18. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
  19. package/dist/accessories/Light-AdaptiveLighting_accessory.js +26 -26
  20. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
  21. package/dist/accessories/Light_accessory.js +45 -48
  22. package/dist/accessories/Light_accessory.js.map +1 -1
  23. package/dist/accessories/Lock_accessory.js +11 -11
  24. package/dist/accessories/Lock_accessory.js.map +1 -1
  25. package/dist/accessories/MotionSensor_accessory.js +8 -8
  26. package/dist/accessories/MotionSensor_accessory.js.map +1 -1
  27. package/dist/accessories/Outlet_accessory.js +10 -10
  28. package/dist/accessories/Outlet_accessory.js.map +1 -1
  29. package/dist/accessories/SmartSpeaker_accessory.js +11 -11
  30. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
  31. package/dist/accessories/Sprinkler_accessory.js +19 -19
  32. package/dist/accessories/Sprinkler_accessory.js.map +1 -1
  33. package/dist/accessories/TV_accessory.js +17 -17
  34. package/dist/accessories/TV_accessory.js.map +1 -1
  35. package/dist/accessories/TemperatureSensor_accessory.js +6 -6
  36. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
  37. package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
  38. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
  39. package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
  40. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
  41. package/dist/accessories/gstreamer-audioProducer.js +36 -47
  42. package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
  43. package/dist/accessories/types.js +2 -2
  44. package/dist/accessories/types.js.map +1 -1
  45. package/dist/index.js +5 -5
  46. package/dist/index.js.map +1 -1
  47. package/dist/lib/Accessory.js +779 -1087
  48. package/dist/lib/Accessory.js.map +1 -1
  49. package/dist/lib/AccessoryLoader.js +40 -40
  50. package/dist/lib/AccessoryLoader.js.map +1 -1
  51. package/dist/lib/Advertiser.js +392 -524
  52. package/dist/lib/Advertiser.js.map +1 -1
  53. package/dist/lib/Bridge.js +6 -10
  54. package/dist/lib/Bridge.js.map +1 -1
  55. package/dist/lib/Characteristic.js +1393 -497
  56. package/dist/lib/Characteristic.js.map +1 -1
  57. package/dist/lib/HAPServer.js +215 -265
  58. package/dist/lib/HAPServer.js.map +1 -1
  59. package/dist/lib/Service.js +486 -322
  60. package/dist/lib/Service.js.map +1 -1
  61. package/dist/lib/camera/Camera.js +14 -14
  62. package/dist/lib/camera/Camera.js.map +1 -1
  63. package/dist/lib/camera/RTPProxy.js +112 -104
  64. package/dist/lib/camera/RTPProxy.js.map +1 -1
  65. package/dist/lib/camera/RTPStreamManagement.js +284 -257
  66. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  67. package/dist/lib/camera/RecordingManagement.js +318 -381
  68. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  69. package/dist/lib/camera/index.js +1 -1
  70. package/dist/lib/controller/AdaptiveLightingController.js +198 -209
  71. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  72. package/dist/lib/controller/CameraController.js +190 -249
  73. package/dist/lib/controller/CameraController.js.map +1 -1
  74. package/dist/lib/controller/DoorbellController.js +38 -39
  75. package/dist/lib/controller/DoorbellController.js.map +1 -1
  76. package/dist/lib/controller/RemoteController.js +343 -401
  77. package/dist/lib/controller/RemoteController.js.map +1 -1
  78. package/dist/lib/controller/index.js +1 -1
  79. package/dist/lib/datastream/DataStreamManagement.js +56 -57
  80. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  81. package/dist/lib/datastream/DataStreamParser.js +259 -304
  82. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  83. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  84. package/dist/lib/datastream/DataStreamServer.js +252 -269
  85. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  86. package/dist/lib/datastream/index.js +1 -1
  87. package/dist/lib/definitions/CharacteristicDefinitions.js +1984 -2708
  88. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  89. package/dist/lib/definitions/ServiceDefinitions.js +818 -1035
  90. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  91. package/dist/lib/definitions/generate-definitions.js +383 -679
  92. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  93. package/dist/lib/definitions/generator-configuration.js +29 -29
  94. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  95. package/dist/lib/definitions/index.js +1 -1
  96. package/dist/lib/model/AccessoryInfo.js +101 -136
  97. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  98. package/dist/lib/model/ControllerStorage.js +86 -89
  99. package/dist/lib/model/ControllerStorage.js.map +1 -1
  100. package/dist/lib/model/HAPStorage.js +15 -16
  101. package/dist/lib/model/HAPStorage.js.map +1 -1
  102. package/dist/lib/model/IdentifierCache.js +49 -49
  103. package/dist/lib/model/IdentifierCache.js.map +1 -1
  104. package/dist/lib/tv/AccessControlManagement.js +40 -44
  105. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  106. package/dist/lib/util/checkName.d.ts +2 -1
  107. package/dist/lib/util/checkName.d.ts.map +1 -1
  108. package/dist/lib/util/checkName.js +5 -10
  109. package/dist/lib/util/checkName.js.map +1 -1
  110. package/dist/lib/util/clone.js +5 -27
  111. package/dist/lib/util/clone.js.map +1 -1
  112. package/dist/lib/util/color-utils.js +8 -12
  113. package/dist/lib/util/color-utils.js.map +1 -1
  114. package/dist/lib/util/eventedhttp.js +290 -387
  115. package/dist/lib/util/eventedhttp.js.map +1 -1
  116. package/dist/lib/util/hapCrypto.js +31 -32
  117. package/dist/lib/util/hapCrypto.js.map +1 -1
  118. package/dist/lib/util/hapStatusError.js +9 -12
  119. package/dist/lib/util/hapStatusError.js.map +1 -1
  120. package/dist/lib/util/net-utils.js +32 -53
  121. package/dist/lib/util/net-utils.js.map +1 -1
  122. package/dist/lib/util/once.js +3 -8
  123. package/dist/lib/util/once.js.map +1 -1
  124. package/dist/lib/util/promise-utils.js +8 -13
  125. package/dist/lib/util/promise-utils.js.map +1 -1
  126. package/dist/lib/util/request-util.js +2 -3
  127. package/dist/lib/util/request-util.js.map +1 -1
  128. package/dist/lib/util/time.js +5 -5
  129. package/dist/lib/util/time.js.map +1 -1
  130. package/dist/lib/util/tlv.js +57 -75
  131. package/dist/lib/util/tlv.js.map +1 -1
  132. package/dist/lib/util/uuid.js +15 -19
  133. package/dist/lib/util/uuid.js.map +1 -1
  134. package/package.json +2 -2
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Characteristic = exports.CharacteristicEventTypes = exports.ChangeReason = exports.Access = exports.Perms = exports.Units = exports.Formats = void 0;
4
- var tslib_1 = require("tslib");
5
- var assert_1 = tslib_1.__importDefault(require("assert"));
6
- var debug_1 = tslib_1.__importDefault(require("debug"));
7
- var events_1 = require("events");
8
- var HAPServer_1 = require("./HAPServer");
9
- var clone_1 = require("./util/clone");
10
- var hapStatusError_1 = require("./util/hapStatusError");
11
- var once_1 = require("./util/once");
12
- var request_util_1 = require("./util/request-util");
13
- var uuid_1 = require("./util/uuid");
14
- var checkName_1 = require("./util/checkName");
15
- var debug = (0, debug_1.default)("HAP-NodeJS:Characteristic");
4
+ const tslib_1 = require("tslib");
5
+ const assert_1 = tslib_1.__importDefault(require("assert"));
6
+ const debug_1 = tslib_1.__importDefault(require("debug"));
7
+ const events_1 = require("events");
8
+ const HAPServer_1 = require("./HAPServer");
9
+ const clone_1 = require("./util/clone");
10
+ const hapStatusError_1 = require("./util/hapStatusError");
11
+ const once_1 = require("./util/once");
12
+ const request_util_1 = require("./util/request-util");
13
+ const uuid_1 = require("./util/uuid");
14
+ const checkName_1 = require("./util/checkName");
15
+ const debug = (0, debug_1.default)("HAP-NodeJS:Characteristic");
16
16
  /**
17
17
  * @group Characteristic
18
18
  */
@@ -182,88 +182,50 @@ var CharacteristicEventTypes;
182
182
  /**
183
183
  * @group Characteristic
184
184
  */
185
- var ValidValuesIterable = /** @class */ (function () {
186
- function ValidValuesIterable(props) {
185
+ class ValidValuesIterable {
186
+ props;
187
+ constructor(props) {
187
188
  (0, assert_1.default)((0, request_util_1.isNumericFormat)(props.format), "Cannot instantiate valid values iterable when format is not numeric. Found " + props.format);
188
189
  this.props = props;
189
190
  }
190
- ValidValuesIterable.prototype[Symbol.iterator] = function () {
191
- var _a, _b, value, e_1_1, min, max, stepValue, i;
192
- var e_1, _c;
193
- return tslib_1.__generator(this, function (_d) {
194
- switch (_d.label) {
195
- case 0:
196
- if (!this.props.validValues) return [3 /*break*/, 9];
197
- _d.label = 1;
198
- case 1:
199
- _d.trys.push([1, 6, 7, 8]);
200
- _a = tslib_1.__values(this.props.validValues), _b = _a.next();
201
- _d.label = 2;
202
- case 2:
203
- if (!!_b.done) return [3 /*break*/, 5];
204
- value = _b.value;
205
- return [4 /*yield*/, value];
206
- case 3:
207
- _d.sent();
208
- _d.label = 4;
209
- case 4:
210
- _b = _a.next();
211
- return [3 /*break*/, 2];
212
- case 5: return [3 /*break*/, 8];
213
- case 6:
214
- e_1_1 = _d.sent();
215
- e_1 = { error: e_1_1 };
216
- return [3 /*break*/, 8];
217
- case 7:
218
- try {
219
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
220
- }
221
- finally { if (e_1) throw e_1.error; }
222
- return [7 /*endfinally*/];
223
- case 8: return [3 /*break*/, 13];
224
- case 9:
225
- min = 0;
226
- max = void 0;
227
- stepValue = 1;
228
- if (this.props.validValueRanges) {
229
- min = this.props.validValueRanges[0];
230
- max = this.props.validValueRanges[1];
231
- }
232
- else if (this.props.minValue != null && this.props.maxValue != null) {
233
- min = this.props.minValue;
234
- max = this.props.maxValue;
235
- if (this.props.minStep != null) {
236
- stepValue = this.props.minStep;
237
- }
238
- }
239
- else if ((0, request_util_1.isUnsignedNumericFormat)(this.props.format)) {
240
- max = (0, request_util_1.numericUpperBound)(this.props.format);
241
- }
242
- else {
243
- throw new Error("Could not find valid iterator strategy for props: " + JSON.stringify(this.props));
244
- }
245
- i = min;
246
- _d.label = 10;
247
- case 10:
248
- if (!(i <= max)) return [3 /*break*/, 13];
249
- return [4 /*yield*/, i];
250
- case 11:
251
- _d.sent();
252
- _d.label = 12;
253
- case 12:
254
- i += stepValue;
255
- return [3 /*break*/, 10];
256
- case 13: return [2 /*return*/];
191
+ *[Symbol.iterator]() {
192
+ if (this.props.validValues) {
193
+ for (const value of this.props.validValues) {
194
+ yield value;
257
195
  }
258
- });
259
- };
260
- return ValidValuesIterable;
261
- }());
262
- var numberPattern = /^-?\d+$/;
196
+ }
197
+ else {
198
+ let min = 0; // default is zero for all the uint types
199
+ let max;
200
+ let stepValue = 1;
201
+ if (this.props.validValueRanges) {
202
+ min = this.props.validValueRanges[0];
203
+ max = this.props.validValueRanges[1];
204
+ }
205
+ else if (this.props.minValue != null && this.props.maxValue != null) {
206
+ min = this.props.minValue;
207
+ max = this.props.maxValue;
208
+ if (this.props.minStep != null) {
209
+ stepValue = this.props.minStep;
210
+ }
211
+ }
212
+ else if ((0, request_util_1.isUnsignedNumericFormat)(this.props.format)) {
213
+ max = (0, request_util_1.numericUpperBound)(this.props.format);
214
+ }
215
+ else {
216
+ throw new Error("Could not find valid iterator strategy for props: " + JSON.stringify(this.props));
217
+ }
218
+ for (let i = min; i <= max; i += stepValue) {
219
+ yield i;
220
+ }
221
+ }
222
+ }
223
+ }
224
+ const numberPattern = /^-?\d+$/;
263
225
  function extractHAPStatusFromError(error) {
264
- var errorValue = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
226
+ let errorValue = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
265
227
  if (numberPattern.test(error.message)) {
266
- var value = parseInt(error.message, 10);
228
+ const value = parseInt(error.message, 10);
267
229
  if ((0, HAPServer_1.IsKnownHAPStatusError)(value)) {
268
230
  errorValue = value;
269
231
  }
@@ -305,30 +267,1028 @@ function minWithUndefined(a, b) {
305
267
  * @group Characteristic
306
268
  */
307
269
  // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
308
- var Characteristic = /** @class */ (function (_super) {
309
- tslib_1.__extends(Characteristic, _super);
310
- function Characteristic(displayName, UUID, props) {
311
- var _this = _super.call(this) || this;
312
- _this.iid = null;
313
- _this.value = null;
314
- /**
315
- * @deprecated replaced by {@link statusCode}
316
- * @private
317
- */
318
- _this.status = null;
319
- /**
320
- * @private
321
- */
322
- _this.statusCode = 0 /* HAPStatus.SUCCESS */;
323
- _this.subscriptions = 0;
324
- _this.displayName = displayName;
325
- _this.UUID = UUID;
326
- _this.props = {
270
+ class Characteristic extends events_1.EventEmitter {
271
+ /**
272
+ * @deprecated Please use the Formats const enum above.
273
+ */
274
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
275
+ static Formats = Formats;
276
+ /**
277
+ * @deprecated Please use the Units const enum above.
278
+ */
279
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
280
+ static Units = Units;
281
+ /**
282
+ * @deprecated Please use the Perms const enum above.
283
+ */
284
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
285
+ static Perms = Perms;
286
+ // Pattern below is for automatic detection of the section of defined characteristics. Used by the generator
287
+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
288
+ /**
289
+ * @group Characteristic Definitions
290
+ */
291
+ static AccessCodeControlPoint;
292
+ /**
293
+ * @group Characteristic Definitions
294
+ */
295
+ static AccessCodeSupportedConfiguration;
296
+ /**
297
+ * @group Characteristic Definitions
298
+ */
299
+ static AccessControlLevel;
300
+ /**
301
+ * @group Characteristic Definitions
302
+ */
303
+ static AccessoryFlags;
304
+ /**
305
+ * @group Characteristic Definitions
306
+ */
307
+ static AccessoryIdentifier;
308
+ /**
309
+ * @group Characteristic Definitions
310
+ */
311
+ static Active;
312
+ /**
313
+ * @group Characteristic Definitions
314
+ */
315
+ static ActiveIdentifier;
316
+ /**
317
+ * @group Characteristic Definitions
318
+ */
319
+ static ActivityInterval;
320
+ /**
321
+ * @group Characteristic Definitions
322
+ */
323
+ static AdministratorOnlyAccess;
324
+ /**
325
+ * @group Characteristic Definitions
326
+ */
327
+ static AirParticulateDensity;
328
+ /**
329
+ * @group Characteristic Definitions
330
+ */
331
+ static AirParticulateSize;
332
+ /**
333
+ * @group Characteristic Definitions
334
+ */
335
+ static AirPlayEnable;
336
+ /**
337
+ * @group Characteristic Definitions
338
+ */
339
+ static AirQuality;
340
+ /**
341
+ * @group Characteristic Definitions
342
+ */
343
+ static AppMatchingIdentifier;
344
+ /**
345
+ * @group Characteristic Definitions
346
+ */
347
+ static AssetUpdateReadiness;
348
+ /**
349
+ * @group Characteristic Definitions
350
+ */
351
+ static AudioFeedback;
352
+ /**
353
+ * @group Characteristic Definitions
354
+ */
355
+ static BatteryLevel;
356
+ /**
357
+ * @group Characteristic Definitions
358
+ */
359
+ static Brightness;
360
+ /**
361
+ * @group Characteristic Definitions
362
+ */
363
+ static ButtonEvent;
364
+ /**
365
+ * @group Characteristic Definitions
366
+ */
367
+ static CameraOperatingModeIndicator;
368
+ /**
369
+ * @group Characteristic Definitions
370
+ */
371
+ static CarbonDioxideDetected;
372
+ /**
373
+ * @group Characteristic Definitions
374
+ */
375
+ static CarbonDioxideLevel;
376
+ /**
377
+ * @group Characteristic Definitions
378
+ */
379
+ static CarbonDioxidePeakLevel;
380
+ /**
381
+ * @group Characteristic Definitions
382
+ */
383
+ static CarbonMonoxideDetected;
384
+ /**
385
+ * @group Characteristic Definitions
386
+ */
387
+ static CarbonMonoxideLevel;
388
+ /**
389
+ * @group Characteristic Definitions
390
+ */
391
+ static CarbonMonoxidePeakLevel;
392
+ /**
393
+ * @group Characteristic Definitions
394
+ */
395
+ static CCAEnergyDetectThreshold;
396
+ /**
397
+ * @group Characteristic Definitions
398
+ */
399
+ static CCASignalDetectThreshold;
400
+ /**
401
+ * @group Characteristic Definitions
402
+ */
403
+ static CharacteristicValueActiveTransitionCount;
404
+ /**
405
+ * @group Characteristic Definitions
406
+ */
407
+ static CharacteristicValueTransitionControl;
408
+ /**
409
+ * @group Characteristic Definitions
410
+ */
411
+ static ChargingState;
412
+ /**
413
+ * @group Characteristic Definitions
414
+ */
415
+ static ClosedCaptions;
416
+ /**
417
+ * @group Characteristic Definitions
418
+ */
419
+ static ColorTemperature;
420
+ /**
421
+ * @group Characteristic Definitions
422
+ */
423
+ static ConfigurationState;
424
+ /**
425
+ * @group Characteristic Definitions
426
+ */
427
+ static ConfiguredName;
428
+ /**
429
+ * @group Characteristic Definitions
430
+ */
431
+ static ContactSensorState;
432
+ /**
433
+ * @group Characteristic Definitions
434
+ */
435
+ static CoolingThresholdTemperature;
436
+ /**
437
+ * @group Characteristic Definitions
438
+ */
439
+ static CryptoHash;
440
+ /**
441
+ * @group Characteristic Definitions
442
+ */
443
+ static CurrentAirPurifierState;
444
+ /**
445
+ * @group Characteristic Definitions
446
+ */
447
+ static CurrentAmbientLightLevel;
448
+ /**
449
+ * @group Characteristic Definitions
450
+ */
451
+ static CurrentDoorState;
452
+ /**
453
+ * @group Characteristic Definitions
454
+ */
455
+ static CurrentFanState;
456
+ /**
457
+ * @group Characteristic Definitions
458
+ */
459
+ static CurrentHeaterCoolerState;
460
+ /**
461
+ * @group Characteristic Definitions
462
+ */
463
+ static CurrentHeatingCoolingState;
464
+ /**
465
+ * @group Characteristic Definitions
466
+ */
467
+ static CurrentHorizontalTiltAngle;
468
+ /**
469
+ * @group Characteristic Definitions
470
+ */
471
+ static CurrentHumidifierDehumidifierState;
472
+ /**
473
+ * @group Characteristic Definitions
474
+ */
475
+ static CurrentMediaState;
476
+ /**
477
+ * @group Characteristic Definitions
478
+ */
479
+ static CurrentPosition;
480
+ /**
481
+ * @group Characteristic Definitions
482
+ */
483
+ static CurrentRelativeHumidity;
484
+ /**
485
+ * @group Characteristic Definitions
486
+ */
487
+ static CurrentSlatState;
488
+ /**
489
+ * @group Characteristic Definitions
490
+ */
491
+ static CurrentTemperature;
492
+ /**
493
+ * @group Characteristic Definitions
494
+ */
495
+ static CurrentTiltAngle;
496
+ /**
497
+ * @group Characteristic Definitions
498
+ */
499
+ static CurrentTransport;
500
+ /**
501
+ * @group Characteristic Definitions
502
+ */
503
+ static CurrentVerticalTiltAngle;
504
+ /**
505
+ * @group Characteristic Definitions
506
+ */
507
+ static CurrentVisibilityState;
508
+ /**
509
+ * @group Characteristic Definitions
510
+ */
511
+ static DataStreamHAPTransport;
512
+ /**
513
+ * @group Characteristic Definitions
514
+ */
515
+ static DataStreamHAPTransportInterrupt;
516
+ /**
517
+ * @group Characteristic Definitions
518
+ */
519
+ static DiagonalFieldOfView;
520
+ /**
521
+ * @group Characteristic Definitions
522
+ */
523
+ static DigitalZoom;
524
+ /**
525
+ * @group Characteristic Definitions
526
+ */
527
+ static DisplayOrder;
528
+ /**
529
+ * @group Characteristic Definitions
530
+ */
531
+ static EventRetransmissionMaximum;
532
+ /**
533
+ * @group Characteristic Definitions
534
+ */
535
+ static EventSnapshotsActive;
536
+ /**
537
+ * @group Characteristic Definitions
538
+ */
539
+ static EventTransmissionCounters;
540
+ /**
541
+ * @group Characteristic Definitions
542
+ */
543
+ static FilterChangeIndication;
544
+ /**
545
+ * @group Characteristic Definitions
546
+ */
547
+ static FilterLifeLevel;
548
+ /**
549
+ * @group Characteristic Definitions
550
+ */
551
+ static FirmwareRevision;
552
+ /**
553
+ * @group Characteristic Definitions
554
+ */
555
+ static FirmwareUpdateReadiness;
556
+ /**
557
+ * @group Characteristic Definitions
558
+ */
559
+ static FirmwareUpdateStatus;
560
+ /**
561
+ * @group Characteristic Definitions
562
+ */
563
+ static HardwareFinish;
564
+ /**
565
+ * @group Characteristic Definitions
566
+ */
567
+ static HardwareRevision;
568
+ /**
569
+ * @group Characteristic Definitions
570
+ */
571
+ static HeartBeat;
572
+ /**
573
+ * @group Characteristic Definitions
574
+ */
575
+ static HeatingThresholdTemperature;
576
+ /**
577
+ * @group Characteristic Definitions
578
+ */
579
+ static HoldPosition;
580
+ /**
581
+ * @group Characteristic Definitions
582
+ */
583
+ static HomeKitCameraActive;
584
+ /**
585
+ * @group Characteristic Definitions
586
+ */
587
+ static Hue;
588
+ /**
589
+ * @group Characteristic Definitions
590
+ */
591
+ static Identifier;
592
+ /**
593
+ * @group Characteristic Definitions
594
+ */
595
+ static Identify;
596
+ /**
597
+ * @group Characteristic Definitions
598
+ */
599
+ static ImageMirroring;
600
+ /**
601
+ * @group Characteristic Definitions
602
+ */
603
+ static ImageRotation;
604
+ /**
605
+ * @group Characteristic Definitions
606
+ */
607
+ static InputDeviceType;
608
+ /**
609
+ * @group Characteristic Definitions
610
+ */
611
+ static InputSourceType;
612
+ /**
613
+ * @group Characteristic Definitions
614
+ */
615
+ static InUse;
616
+ /**
617
+ * @group Characteristic Definitions
618
+ */
619
+ static IsConfigured;
620
+ /**
621
+ * @group Characteristic Definitions
622
+ */
623
+ static LeakDetected;
624
+ /**
625
+ * @group Characteristic Definitions
626
+ */
627
+ static ListPairings;
628
+ /**
629
+ * @group Characteristic Definitions
630
+ */
631
+ static LockControlPoint;
632
+ /**
633
+ * @group Characteristic Definitions
634
+ */
635
+ static LockCurrentState;
636
+ /**
637
+ * @group Characteristic Definitions
638
+ */
639
+ static LockLastKnownAction;
640
+ /**
641
+ * @group Characteristic Definitions
642
+ */
643
+ static LockManagementAutoSecurityTimeout;
644
+ /**
645
+ * @group Characteristic Definitions
646
+ */
647
+ static LockPhysicalControls;
648
+ /**
649
+ * @group Characteristic Definitions
650
+ */
651
+ static LockTargetState;
652
+ /**
653
+ * @group Characteristic Definitions
654
+ */
655
+ static Logs;
656
+ /**
657
+ * @group Characteristic Definitions
658
+ */
659
+ static MACRetransmissionMaximum;
660
+ /**
661
+ * @group Characteristic Definitions
662
+ */
663
+ static MACTransmissionCounters;
664
+ /**
665
+ * @group Characteristic Definitions
666
+ */
667
+ static ManagedNetworkEnable;
668
+ /**
669
+ * @group Characteristic Definitions
670
+ */
671
+ static ManuallyDisabled;
672
+ /**
673
+ * @group Characteristic Definitions
674
+ */
675
+ static Manufacturer;
676
+ /**
677
+ * @group Characteristic Definitions
678
+ */
679
+ static MatterFirmwareRevisionNumber;
680
+ /**
681
+ * @group Characteristic Definitions
682
+ */
683
+ static MatterFirmwareUpdateStatus;
684
+ /**
685
+ * @group Characteristic Definitions
686
+ */
687
+ static MaximumTransmitPower;
688
+ /**
689
+ * @group Characteristic Definitions
690
+ */
691
+ static MetricsBufferFullState;
692
+ /**
693
+ * @group Characteristic Definitions
694
+ */
695
+ static Model;
696
+ /**
697
+ * @group Characteristic Definitions
698
+ */
699
+ static MotionDetected;
700
+ /**
701
+ * @group Characteristic Definitions
702
+ */
703
+ static MultifunctionButton;
704
+ /**
705
+ * @group Characteristic Definitions
706
+ */
707
+ static Mute;
708
+ /**
709
+ * @group Characteristic Definitions
710
+ */
711
+ static Name;
712
+ /**
713
+ * @group Characteristic Definitions
714
+ */
715
+ static NetworkAccessViolationControl;
716
+ /**
717
+ * @group Characteristic Definitions
718
+ */
719
+ static NetworkClientProfileControl;
720
+ /**
721
+ * @group Characteristic Definitions
722
+ */
723
+ static NetworkClientStatusControl;
724
+ /**
725
+ * @group Characteristic Definitions
726
+ */
727
+ static NFCAccessControlPoint;
728
+ /**
729
+ * @group Characteristic Definitions
730
+ */
731
+ static NFCAccessSupportedConfiguration;
732
+ /**
733
+ * @group Characteristic Definitions
734
+ */
735
+ static NightVision;
736
+ /**
737
+ * @group Characteristic Definitions
738
+ */
739
+ static NitrogenDioxideDensity;
740
+ /**
741
+ * @group Characteristic Definitions
742
+ */
743
+ static ObstructionDetected;
744
+ /**
745
+ * @group Characteristic Definitions
746
+ */
747
+ static OccupancyDetected;
748
+ /**
749
+ * @group Characteristic Definitions
750
+ */
751
+ static On;
752
+ /**
753
+ * @group Characteristic Definitions
754
+ */
755
+ static OperatingStateResponse;
756
+ /**
757
+ * @group Characteristic Definitions
758
+ */
759
+ static OpticalZoom;
760
+ /**
761
+ * @group Characteristic Definitions
762
+ */
763
+ static OutletInUse;
764
+ /**
765
+ * @group Characteristic Definitions
766
+ */
767
+ static OzoneDensity;
768
+ /**
769
+ * @group Characteristic Definitions
770
+ */
771
+ static PairingFeatures;
772
+ /**
773
+ * @group Characteristic Definitions
774
+ */
775
+ static PairSetup;
776
+ /**
777
+ * @group Characteristic Definitions
778
+ */
779
+ static PairVerify;
780
+ /**
781
+ * @group Characteristic Definitions
782
+ */
783
+ static PasswordSetting;
784
+ /**
785
+ * @group Characteristic Definitions
786
+ */
787
+ static PeriodicSnapshotsActive;
788
+ /**
789
+ * @group Characteristic Definitions
790
+ */
791
+ static PictureMode;
792
+ /**
793
+ * @group Characteristic Definitions
794
+ */
795
+ static Ping;
796
+ /**
797
+ * @group Characteristic Definitions
798
+ */
799
+ static PM10Density;
800
+ /**
801
+ * @group Characteristic Definitions
802
+ */
803
+ static PM2_5Density;
804
+ /**
805
+ * @group Characteristic Definitions
806
+ */
807
+ static PositionState;
808
+ /**
809
+ * @group Characteristic Definitions
810
+ */
811
+ static PowerModeSelection;
812
+ /**
813
+ * @group Characteristic Definitions
814
+ */
815
+ static ProductData;
816
+ /**
817
+ * @group Characteristic Definitions
818
+ */
819
+ static ProgrammableSwitchEvent;
820
+ /**
821
+ * @group Characteristic Definitions
822
+ */
823
+ static ProgrammableSwitchOutputState;
824
+ /**
825
+ * @group Characteristic Definitions
826
+ */
827
+ static ProgramMode;
828
+ /**
829
+ * @group Characteristic Definitions
830
+ */
831
+ static ReceivedSignalStrengthIndication;
832
+ /**
833
+ * @group Characteristic Definitions
834
+ */
835
+ static ReceiverSensitivity;
836
+ /**
837
+ * @group Characteristic Definitions
838
+ */
839
+ static RecordingAudioActive;
840
+ /**
841
+ * @group Characteristic Definitions
842
+ */
843
+ static RelativeHumidityDehumidifierThreshold;
844
+ /**
845
+ * @group Characteristic Definitions
846
+ */
847
+ static RelativeHumidityHumidifierThreshold;
848
+ /**
849
+ * @group Characteristic Definitions
850
+ */
851
+ static RemainingDuration;
852
+ /**
853
+ * @group Characteristic Definitions
854
+ */
855
+ static RemoteKey;
856
+ /**
857
+ * @group Characteristic Definitions
858
+ */
859
+ static ResetFilterIndication;
860
+ /**
861
+ * @group Characteristic Definitions
862
+ */
863
+ static RotationDirection;
864
+ /**
865
+ * @group Characteristic Definitions
866
+ */
867
+ static RotationSpeed;
868
+ /**
869
+ * @group Characteristic Definitions
870
+ */
871
+ static RouterStatus;
872
+ /**
873
+ * @group Characteristic Definitions
874
+ */
875
+ static Saturation;
876
+ /**
877
+ * @group Characteristic Definitions
878
+ */
879
+ static SecuritySystemAlarmType;
880
+ /**
881
+ * @group Characteristic Definitions
882
+ */
883
+ static SecuritySystemCurrentState;
884
+ /**
885
+ * @group Characteristic Definitions
886
+ */
887
+ static SecuritySystemTargetState;
888
+ /**
889
+ * @group Characteristic Definitions
890
+ */
891
+ static SelectedAudioStreamConfiguration;
892
+ /**
893
+ * @group Characteristic Definitions
894
+ */
895
+ static SelectedCameraRecordingConfiguration;
896
+ /**
897
+ * @group Characteristic Definitions
898
+ */
899
+ static SelectedDiagnosticsModes;
900
+ /**
901
+ * @group Characteristic Definitions
902
+ */
903
+ static SelectedRTPStreamConfiguration;
904
+ /**
905
+ * @group Characteristic Definitions
906
+ */
907
+ static SelectedSleepConfiguration;
908
+ /**
909
+ * @group Characteristic Definitions
910
+ */
911
+ static SerialNumber;
912
+ /**
913
+ * @group Characteristic Definitions
914
+ */
915
+ static ServiceLabelIndex;
916
+ /**
917
+ * @group Characteristic Definitions
918
+ */
919
+ static ServiceLabelNamespace;
920
+ /**
921
+ * @group Characteristic Definitions
922
+ */
923
+ static SetDuration;
924
+ /**
925
+ * @group Characteristic Definitions
926
+ */
927
+ static SetupDataStreamTransport;
928
+ /**
929
+ * @group Characteristic Definitions
930
+ */
931
+ static SetupEndpoints;
932
+ /**
933
+ * @group Characteristic Definitions
934
+ */
935
+ static SetupTransferTransport;
936
+ /**
937
+ * @group Characteristic Definitions
938
+ */
939
+ static SignalToNoiseRatio;
940
+ /**
941
+ * @group Characteristic Definitions
942
+ */
943
+ static SiriEnable;
944
+ /**
945
+ * @group Characteristic Definitions
946
+ */
947
+ static SiriEndpointSessionStatus;
948
+ /**
949
+ * @group Characteristic Definitions
950
+ */
951
+ static SiriEngineVersion;
952
+ /**
953
+ * @group Characteristic Definitions
954
+ */
955
+ static SiriInputType;
956
+ /**
957
+ * @group Characteristic Definitions
958
+ */
959
+ static SiriLightOnUse;
960
+ /**
961
+ * @group Characteristic Definitions
962
+ */
963
+ static SiriListening;
964
+ /**
965
+ * @group Characteristic Definitions
966
+ */
967
+ static SiriTouchToUse;
968
+ /**
969
+ * @group Characteristic Definitions
970
+ */
971
+ static SlatType;
972
+ /**
973
+ * @group Characteristic Definitions
974
+ */
975
+ static SleepDiscoveryMode;
976
+ /**
977
+ * @group Characteristic Definitions
978
+ */
979
+ static SleepInterval;
980
+ /**
981
+ * @group Characteristic Definitions
982
+ */
983
+ static SmokeDetected;
984
+ /**
985
+ * @group Characteristic Definitions
986
+ */
987
+ static SoftwareRevision;
988
+ /**
989
+ * @group Characteristic Definitions
990
+ */
991
+ static StagedFirmwareVersion;
992
+ /**
993
+ * @group Characteristic Definitions
994
+ */
995
+ static StatusActive;
996
+ /**
997
+ * @group Characteristic Definitions
998
+ */
999
+ static StatusFault;
1000
+ /**
1001
+ * @group Characteristic Definitions
1002
+ */
1003
+ static StatusJammed;
1004
+ /**
1005
+ * @group Characteristic Definitions
1006
+ */
1007
+ static StatusLowBattery;
1008
+ /**
1009
+ * @group Characteristic Definitions
1010
+ */
1011
+ static StatusTampered;
1012
+ /**
1013
+ * @group Characteristic Definitions
1014
+ */
1015
+ static StreamingStatus;
1016
+ /**
1017
+ * @group Characteristic Definitions
1018
+ */
1019
+ static SulphurDioxideDensity;
1020
+ /**
1021
+ * @group Characteristic Definitions
1022
+ */
1023
+ static SupportedAssetTypes;
1024
+ /**
1025
+ * @group Characteristic Definitions
1026
+ */
1027
+ static SupportedAudioRecordingConfiguration;
1028
+ /**
1029
+ * @group Characteristic Definitions
1030
+ */
1031
+ static SupportedAudioStreamConfiguration;
1032
+ /**
1033
+ * @group Characteristic Definitions
1034
+ */
1035
+ static SupportedCameraRecordingConfiguration;
1036
+ /**
1037
+ * @group Characteristic Definitions
1038
+ */
1039
+ static SupportedCharacteristicValueTransitionConfiguration;
1040
+ /**
1041
+ * @group Characteristic Definitions
1042
+ */
1043
+ static SupportedDataStreamTransportConfiguration;
1044
+ /**
1045
+ * @group Characteristic Definitions
1046
+ */
1047
+ static SupportedDiagnosticsModes;
1048
+ /**
1049
+ * @group Characteristic Definitions
1050
+ */
1051
+ static SupportedDiagnosticsSnapshot;
1052
+ /**
1053
+ * @group Characteristic Definitions
1054
+ */
1055
+ static SupportedFirmwareUpdateConfiguration;
1056
+ /**
1057
+ * @group Characteristic Definitions
1058
+ */
1059
+ static SupportedMetrics;
1060
+ /**
1061
+ * @group Characteristic Definitions
1062
+ */
1063
+ static SupportedRouterConfiguration;
1064
+ /**
1065
+ * @group Characteristic Definitions
1066
+ */
1067
+ static SupportedRTPConfiguration;
1068
+ /**
1069
+ * @group Characteristic Definitions
1070
+ */
1071
+ static SupportedSleepConfiguration;
1072
+ /**
1073
+ * @group Characteristic Definitions
1074
+ */
1075
+ static SupportedTransferTransportConfiguration;
1076
+ /**
1077
+ * @group Characteristic Definitions
1078
+ */
1079
+ static SupportedVideoRecordingConfiguration;
1080
+ /**
1081
+ * @group Characteristic Definitions
1082
+ */
1083
+ static SupportedVideoStreamConfiguration;
1084
+ /**
1085
+ * @group Characteristic Definitions
1086
+ */
1087
+ static SwingMode;
1088
+ /**
1089
+ * @group Characteristic Definitions
1090
+ */
1091
+ static TapType;
1092
+ /**
1093
+ * @group Characteristic Definitions
1094
+ */
1095
+ static TargetAirPurifierState;
1096
+ /**
1097
+ * @group Characteristic Definitions
1098
+ * @deprecated Removed and not used anymore
1099
+ */
1100
+ static TargetAirQuality;
1101
+ /**
1102
+ * @group Characteristic Definitions
1103
+ */
1104
+ static TargetControlList;
1105
+ /**
1106
+ * @group Characteristic Definitions
1107
+ */
1108
+ static TargetControlSupportedConfiguration;
1109
+ /**
1110
+ * @group Characteristic Definitions
1111
+ */
1112
+ static TargetDoorState;
1113
+ /**
1114
+ * @group Characteristic Definitions
1115
+ */
1116
+ static TargetFanState;
1117
+ /**
1118
+ * @group Characteristic Definitions
1119
+ */
1120
+ static TargetHeaterCoolerState;
1121
+ /**
1122
+ * @group Characteristic Definitions
1123
+ */
1124
+ static TargetHeatingCoolingState;
1125
+ /**
1126
+ * @group Characteristic Definitions
1127
+ */
1128
+ static TargetHorizontalTiltAngle;
1129
+ /**
1130
+ * @group Characteristic Definitions
1131
+ */
1132
+ static TargetHumidifierDehumidifierState;
1133
+ /**
1134
+ * @group Characteristic Definitions
1135
+ */
1136
+ static TargetMediaState;
1137
+ /**
1138
+ * @group Characteristic Definitions
1139
+ */
1140
+ static TargetPosition;
1141
+ /**
1142
+ * @group Characteristic Definitions
1143
+ */
1144
+ static TargetRelativeHumidity;
1145
+ /**
1146
+ * @group Characteristic Definitions
1147
+ * @deprecated Removed and not used anymore
1148
+ */
1149
+ static TargetSlatState;
1150
+ /**
1151
+ * @group Characteristic Definitions
1152
+ */
1153
+ static TargetTemperature;
1154
+ /**
1155
+ * @group Characteristic Definitions
1156
+ */
1157
+ static TargetTiltAngle;
1158
+ /**
1159
+ * @group Characteristic Definitions
1160
+ */
1161
+ static TargetVerticalTiltAngle;
1162
+ /**
1163
+ * @group Characteristic Definitions
1164
+ */
1165
+ static TargetVisibilityState;
1166
+ /**
1167
+ * @group Characteristic Definitions
1168
+ */
1169
+ static TemperatureDisplayUnits;
1170
+ /**
1171
+ * @group Characteristic Definitions
1172
+ */
1173
+ static ThirdPartyCameraActive;
1174
+ /**
1175
+ * @group Characteristic Definitions
1176
+ */
1177
+ static ThreadControlPoint;
1178
+ /**
1179
+ * @group Characteristic Definitions
1180
+ */
1181
+ static ThreadNodeCapabilities;
1182
+ /**
1183
+ * @group Characteristic Definitions
1184
+ */
1185
+ static ThreadOpenThreadVersion;
1186
+ /**
1187
+ * @group Characteristic Definitions
1188
+ */
1189
+ static ThreadStatus;
1190
+ /**
1191
+ * @group Characteristic Definitions
1192
+ */
1193
+ static Token;
1194
+ /**
1195
+ * @group Characteristic Definitions
1196
+ */
1197
+ static TransmitPower;
1198
+ /**
1199
+ * @group Characteristic Definitions
1200
+ */
1201
+ static ValveType;
1202
+ /**
1203
+ * @group Characteristic Definitions
1204
+ */
1205
+ static Version;
1206
+ /**
1207
+ * @group Characteristic Definitions
1208
+ */
1209
+ static VideoAnalysisActive;
1210
+ /**
1211
+ * @group Characteristic Definitions
1212
+ */
1213
+ static VOCDensity;
1214
+ /**
1215
+ * @group Characteristic Definitions
1216
+ */
1217
+ static Volume;
1218
+ /**
1219
+ * @group Characteristic Definitions
1220
+ */
1221
+ static VolumeControlType;
1222
+ /**
1223
+ * @group Characteristic Definitions
1224
+ */
1225
+ static VolumeSelector;
1226
+ /**
1227
+ * @group Characteristic Definitions
1228
+ */
1229
+ static WakeConfiguration;
1230
+ /**
1231
+ * @group Characteristic Definitions
1232
+ */
1233
+ static WANConfigurationList;
1234
+ /**
1235
+ * @group Characteristic Definitions
1236
+ */
1237
+ static WANStatusList;
1238
+ /**
1239
+ * @group Characteristic Definitions
1240
+ */
1241
+ static WaterLevel;
1242
+ /**
1243
+ * @group Characteristic Definitions
1244
+ */
1245
+ static WiFiCapabilities;
1246
+ /**
1247
+ * @group Characteristic Definitions
1248
+ */
1249
+ static WiFiConfigurationControl;
1250
+ /**
1251
+ * @group Characteristic Definitions
1252
+ */
1253
+ static WiFiSatelliteStatus;
1254
+ // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1255
+ // NOTICE: when adding/changing properties, remember to possibly adjust the serialize/deserialize functions
1256
+ displayName;
1257
+ UUID;
1258
+ iid = null;
1259
+ value = null;
1260
+ /**
1261
+ * @deprecated replaced by {@link statusCode}
1262
+ * @private
1263
+ */
1264
+ status = null;
1265
+ /**
1266
+ * @private
1267
+ */
1268
+ statusCode = 0 /* HAPStatus.SUCCESS */;
1269
+ props;
1270
+ /**
1271
+ * The {@link Characteristic.onGet} handler
1272
+ */
1273
+ getHandler;
1274
+ /**
1275
+ * The {@link Characteristic.onSet} handler
1276
+ */
1277
+ setHandler;
1278
+ subscriptions = 0;
1279
+ /**
1280
+ * @private
1281
+ */
1282
+ additionalAuthorizationHandler;
1283
+ constructor(displayName, UUID, props) {
1284
+ super();
1285
+ this.displayName = displayName;
1286
+ this.UUID = UUID;
1287
+ this.props = {
327
1288
  format: "int" /* Formats.INT */,
328
1289
  perms: ["ev" /* Perms.NOTIFY */],
329
1290
  };
330
- _this.setProps(props || {}); // ensure sanity checks are called
331
- return _this;
1291
+ this.setProps(props || {}); // ensure sanity checks are called
332
1292
  }
333
1293
  /**
334
1294
  * Accepts a function that will be called to retrieve the current value of a Characteristic.
@@ -343,21 +1303,21 @@ var Characteristic = /** @class */ (function (_super) {
343
1303
  * ```
344
1304
  * @param handler
345
1305
  */
346
- Characteristic.prototype.onGet = function (handler) {
1306
+ onGet(handler) {
347
1307
  if (typeof handler !== "function") {
348
1308
  this.characteristicWarning(".onGet handler must be a function");
349
1309
  return this;
350
1310
  }
351
1311
  this.getHandler = handler;
352
1312
  return this;
353
- };
1313
+ }
354
1314
  /**
355
1315
  * Removes the {@link CharacteristicGetHandler} handler which was configured using {@link onGet}.
356
1316
  */
357
- Characteristic.prototype.removeOnGet = function () {
1317
+ removeOnGet() {
358
1318
  this.getHandler = undefined;
359
1319
  return this;
360
- };
1320
+ }
361
1321
  /**
362
1322
  * Accepts a function that will be called when setting the value of a Characteristic.
363
1323
  * If the characteristic supports {@link Perms.WRITE_RESPONSE} and the request requests a write-response value,
@@ -372,21 +1332,21 @@ var Characteristic = /** @class */ (function (_super) {
372
1332
  * ```
373
1333
  * @param handler
374
1334
  */
375
- Characteristic.prototype.onSet = function (handler) {
1335
+ onSet(handler) {
376
1336
  if (typeof handler !== "function") {
377
1337
  this.characteristicWarning(".onSet handler must be a function");
378
1338
  return this;
379
1339
  }
380
1340
  this.setHandler = handler;
381
1341
  return this;
382
- };
1342
+ }
383
1343
  /**
384
1344
  * Removes the {@link CharacteristicSetHandler} which was configured using {@link onSet}.
385
1345
  */
386
- Characteristic.prototype.removeOnSet = function () {
1346
+ removeOnSet() {
387
1347
  this.setHandler = undefined;
388
1348
  return this;
389
- };
1349
+ }
390
1350
  /**
391
1351
  * Updates the properties of this characteristic.
392
1352
  * Properties passed via the parameter will be set. Any parameter set to null will be deleted.
@@ -394,10 +1354,10 @@ var Characteristic = /** @class */ (function (_super) {
394
1354
  *
395
1355
  * @param props - Partial properties object with the desired updates.
396
1356
  */
397
- Characteristic.prototype.setProps = function (props) {
1357
+ setProps(props) {
398
1358
  (0, assert_1.default)(props, "props cannot be undefined when setting props");
399
1359
  // TODO calling setProps after publish doesn't lead to a increment in the current configuration number
400
- var formatDidChange = false;
1360
+ let formatDidChange = false;
401
1361
  // for every value "null" can be used to reset props, except for required props
402
1362
  if (props.format) {
403
1363
  formatDidChange = this.props.format !== props.format;
@@ -423,7 +1383,7 @@ var Characteristic = /** @class */ (function (_super) {
423
1383
  props.minValue = undefined;
424
1384
  }
425
1385
  else if (typeof props.minValue !== "number" || !Number.isFinite(props.minValue)) {
426
- this.characteristicWarning("Characteristic Property 'minValue' must be a finite number, received \"".concat(props.minValue, "\" (").concat(typeof props.minValue, ")"), "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1386
+ this.characteristicWarning(`Characteristic Property 'minValue' must be a finite number, received "${props.minValue}" (${typeof props.minValue})`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
427
1387
  props.minValue = undefined;
428
1388
  }
429
1389
  else {
@@ -450,7 +1410,7 @@ var Characteristic = /** @class */ (function (_super) {
450
1410
  props.maxValue = undefined;
451
1411
  }
452
1412
  else if (typeof props.maxValue !== "number" || !Number.isFinite(props.maxValue)) {
453
- this.characteristicWarning("Characteristic Property 'maxValue' must be a finite number, received \"".concat(props.maxValue, "\" (").concat(typeof props.maxValue, ")"), "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1413
+ this.characteristicWarning(`Characteristic Property 'maxValue' must be a finite number, received "${props.maxValue}" (${typeof props.maxValue})`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
454
1414
  props.maxValue = undefined;
455
1415
  }
456
1416
  else {
@@ -554,14 +1514,14 @@ var Characteristic = /** @class */ (function (_super) {
554
1514
  // - If the characteristic is marked as erroneous the value is not considered valid anyway, and we must not remove the `statusCode`.
555
1515
  // - Special case for `ProgrammableSwitchEvent` where every change in value is considered an event which would result in ghost button presses
556
1516
  // validateUserInput when called from setProps is intended to clamp value withing allowed range. It is why warnings should not be displayed.
557
- var correctedValue = this.validateUserInput(this.value, "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
1517
+ const correctedValue = this.validateUserInput(this.value, "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
558
1518
  if (correctedValue !== this.value) {
559
1519
  // we don't want to emit a CHANGE event if the value didn't change at all!
560
1520
  this.updateValue(correctedValue);
561
1521
  }
562
1522
  }
563
1523
  return this;
564
- };
1524
+ }
565
1525
  /**
566
1526
  * This method can be used to gain an Iterator to loop over all valid values defined for this characteristic.
567
1527
  *
@@ -590,9 +1550,9 @@ var Characteristic = /** @class */ (function (_super) {
590
1550
  * const validValues = Array.from(characteristic.validValuesIterator());
591
1551
  * ```
592
1552
  */
593
- Characteristic.prototype.validValuesIterator = function () {
1553
+ validValuesIterator() {
594
1554
  return new ValidValuesIterable(this.props);
595
- };
1555
+ }
596
1556
  // noinspection JSUnusedGlobalSymbols
597
1557
  /**
598
1558
  * This method can be used to set up additional authorization for a characteristic.
@@ -610,12 +1570,12 @@ var Characteristic = /** @class */ (function (_super) {
610
1570
  *
611
1571
  * @param handler - Handler called to check additional authorization data.
612
1572
  */
613
- Characteristic.prototype.setupAdditionalAuthorization = function (handler) {
1573
+ setupAdditionalAuthorization(handler) {
614
1574
  if (!this.props.perms.includes("aa" /* Perms.ADDITIONAL_AUTHORIZATION */)) {
615
1575
  this.props.perms.push("aa" /* Perms.ADDITIONAL_AUTHORIZATION */);
616
1576
  }
617
1577
  this.additionalAuthorizationHandler = handler;
618
- };
1578
+ }
619
1579
  /**
620
1580
  * Updates the current value of the characteristic.
621
1581
  *
@@ -625,18 +1585,18 @@ var Characteristic = /** @class */ (function (_super) {
625
1585
  *
626
1586
  * @deprecated
627
1587
  */
628
- Characteristic.prototype.getValue = function (callback, context) {
629
- this.handleGetRequest(undefined, context).then(function (value) {
1588
+ getValue(callback, context) {
1589
+ this.handleGetRequest(undefined, context).then(value => {
630
1590
  if (callback) {
631
1591
  callback(null, value);
632
1592
  }
633
- }, function (reason) {
1593
+ }, reason => {
634
1594
  if (callback) {
635
1595
  callback(reason);
636
1596
  }
637
1597
  });
638
- };
639
- Characteristic.prototype.setValue = function (value, callback, context) {
1598
+ }
1599
+ setValue(value, callback, context) {
640
1600
  if (value instanceof Error) {
641
1601
  this.statusCode = value instanceof hapStatusError_1.HapStatusError ? value.hapStatus : extractHAPStatusFromError(value);
642
1602
  // noinspection JSDeprecatedSymbols
@@ -654,13 +1614,13 @@ var Characteristic = /** @class */ (function (_super) {
654
1614
  value = this.validateUserInput(value);
655
1615
  }
656
1616
  catch (error) {
657
- this.characteristicWarning((error === null || error === void 0 ? void 0 : error.message) + "", "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
1617
+ this.characteristicWarning(error?.message + "", "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
658
1618
  if (callback) {
659
1619
  callback(error);
660
1620
  }
661
1621
  return this;
662
1622
  }
663
- this.handleSetRequest(value, undefined, context).then(function (value) {
1623
+ this.handleSetRequest(value, undefined, context).then(value => {
664
1624
  if (callback) {
665
1625
  if (value) { // possible write response
666
1626
  callback(null, value);
@@ -669,14 +1629,14 @@ var Characteristic = /** @class */ (function (_super) {
669
1629
  callback(null);
670
1630
  }
671
1631
  }
672
- }, function (reason) {
1632
+ }, reason => {
673
1633
  if (callback) {
674
1634
  callback(reason);
675
1635
  }
676
1636
  });
677
1637
  return this;
678
- };
679
- Characteristic.prototype.updateValue = function (value, callback, context) {
1638
+ }
1639
+ updateValue(value, callback, context) {
680
1640
  if (value instanceof Error) {
681
1641
  this.statusCode = value instanceof hapStatusError_1.HapStatusError ? value.hapStatus : extractHAPStatusFromError(value);
682
1642
  // noinspection JSDeprecatedSymbols
@@ -694,7 +1654,7 @@ var Characteristic = /** @class */ (function (_super) {
694
1654
  value = this.validateUserInput(value);
695
1655
  }
696
1656
  catch (error) {
697
- this.characteristicWarning((error === null || error === void 0 ? void 0 : error.message) + "", "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
1657
+ this.characteristicWarning(error?.message + "", "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
698
1658
  if (callback) {
699
1659
  callback();
700
1660
  }
@@ -703,14 +1663,14 @@ var Characteristic = /** @class */ (function (_super) {
703
1663
  this.statusCode = 0 /* HAPStatus.SUCCESS */;
704
1664
  // noinspection JSDeprecatedSymbols
705
1665
  this.status = null;
706
- var oldValue = this.value;
1666
+ const oldValue = this.value;
707
1667
  this.value = value;
708
1668
  if (callback) {
709
1669
  callback();
710
1670
  }
711
1671
  this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: undefined, oldValue: oldValue, newValue: value, reason: "update" /* ChangeReason.UPDATE */, context: context });
712
1672
  return this; // for chaining
713
- };
1673
+ }
714
1674
  /**
715
1675
  * This method acts similarly to {@link updateValue} by setting the current value of the characteristic
716
1676
  * without calling any {@link CharacteristicEventTypes.SET} or {@link onSet} handlers.
@@ -720,16 +1680,16 @@ var Characteristic = /** @class */ (function (_super) {
720
1680
  * @param value - The new value.
721
1681
  * @param context - Passed to the {@link CharacteristicEventTypes.CHANGE} event handler.
722
1682
  */
723
- Characteristic.prototype.sendEventNotification = function (value, context) {
1683
+ sendEventNotification(value, context) {
724
1684
  this.statusCode = 0 /* HAPStatus.SUCCESS */;
725
1685
  // noinspection JSDeprecatedSymbols
726
1686
  this.status = null;
727
1687
  value = this.validateUserInput(value);
728
- var oldValue = this.value;
1688
+ const oldValue = this.value;
729
1689
  this.value = value;
730
1690
  this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: undefined, oldValue: oldValue, newValue: value, reason: "event" /* ChangeReason.EVENT */, context: context });
731
1691
  return this; // for chaining
732
- };
1692
+ }
733
1693
  /**
734
1694
  * Called when a HAP requests wants to know the current value of the characteristic.
735
1695
  *
@@ -737,130 +1697,118 @@ var Characteristic = /** @class */ (function (_super) {
737
1697
  * @param context - Deprecated parameter. There for backwards compatibility.
738
1698
  * @private Used by the Accessory to load the characteristic value
739
1699
  */
740
- Characteristic.prototype.handleGetRequest = function (connection, context) {
741
- return tslib_1.__awaiter(this, void 0, void 0, function () {
742
- var value, oldValue, error_1, hapStatusError;
743
- var _this = this;
744
- return tslib_1.__generator(this, function (_a) {
745
- switch (_a.label) {
746
- case 0:
747
- if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if we are allowed to read from this characteristic
748
- throw -70405 /* HAPStatus.WRITE_ONLY_CHARACTERISTIC */;
749
- }
750
- if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
751
- // special workaround for event only programmable switch event, which must always return null
752
- return [2 /*return*/, null];
753
- }
754
- if (!this.getHandler) return [3 /*break*/, 4];
755
- if (this.listeners("get" /* CharacteristicEventTypes.GET */).length > 0) {
756
- this.characteristicWarning("Ignoring on('get') handler as onGet handler was defined instead");
757
- }
758
- _a.label = 1;
759
- case 1:
760
- _a.trys.push([1, 3, , 4]);
761
- return [4 /*yield*/, this.getHandler(context, connection)];
762
- case 2:
763
- value = _a.sent();
764
- this.statusCode = 0 /* HAPStatus.SUCCESS */;
765
- // noinspection JSDeprecatedSymbols
766
- this.status = null;
767
- try {
768
- value = this.validateUserInput(value);
769
- }
770
- catch (error) {
771
- this.characteristicWarning("An illegal value was supplied by the read handler for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
772
- this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
773
- // noinspection JSDeprecatedSymbols
774
- this.status = error;
775
- return [2 /*return*/, Promise.reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */)];
776
- }
777
- oldValue = this.value;
778
- this.value = value;
779
- if (oldValue !== value) { // emit a change event if necessary
780
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "read" /* ChangeReason.READ */, context: context });
781
- }
782
- return [2 /*return*/, value];
783
- case 3:
784
- error_1 = _a.sent();
785
- if (typeof error_1 === "number") {
786
- hapStatusError = new hapStatusError_1.HapStatusError(error_1);
1700
+ async handleGetRequest(connection, context) {
1701
+ if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if we are allowed to read from this characteristic
1702
+ throw -70405 /* HAPStatus.WRITE_ONLY_CHARACTERISTIC */;
1703
+ }
1704
+ if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
1705
+ // special workaround for event only programmable switch event, which must always return null
1706
+ return null;
1707
+ }
1708
+ if (this.getHandler) {
1709
+ if (this.listeners("get" /* CharacteristicEventTypes.GET */).length > 0) {
1710
+ this.characteristicWarning("Ignoring on('get') handler as onGet handler was defined instead");
1711
+ }
1712
+ try {
1713
+ let value = await this.getHandler(context, connection);
1714
+ this.statusCode = 0 /* HAPStatus.SUCCESS */;
1715
+ // noinspection JSDeprecatedSymbols
1716
+ this.status = null;
1717
+ try {
1718
+ value = this.validateUserInput(value);
1719
+ }
1720
+ catch (error) {
1721
+ this.characteristicWarning(`An illegal value was supplied by the read handler for characteristic: ${error?.message}`, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error?.stack);
1722
+ this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
1723
+ // noinspection JSDeprecatedSymbols
1724
+ this.status = error;
1725
+ return Promise.reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
1726
+ }
1727
+ const oldValue = this.value;
1728
+ this.value = value;
1729
+ if (oldValue !== value) { // emit a change event if necessary
1730
+ this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "read" /* ChangeReason.READ */, context: context });
1731
+ }
1732
+ return value;
1733
+ }
1734
+ catch (error) {
1735
+ if (typeof error === "number") {
1736
+ const hapStatusError = new hapStatusError_1.HapStatusError(error);
1737
+ this.statusCode = hapStatusError.hapStatus;
1738
+ // noinspection JSDeprecatedSymbols
1739
+ this.status = hapStatusError;
1740
+ }
1741
+ else if (error instanceof hapStatusError_1.HapStatusError) {
1742
+ this.statusCode = error.hapStatus;
1743
+ // noinspection JSDeprecatedSymbols
1744
+ this.status = error;
1745
+ }
1746
+ else {
1747
+ this.characteristicWarning(`Unhandled error thrown inside read handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1748
+ this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
1749
+ // noinspection JSDeprecatedSymbols
1750
+ this.status = error;
1751
+ }
1752
+ throw this.statusCode;
1753
+ }
1754
+ }
1755
+ if (this.listeners("get" /* CharacteristicEventTypes.GET */).length === 0) {
1756
+ if (this.statusCode) {
1757
+ throw this.statusCode;
1758
+ }
1759
+ try {
1760
+ return this.validateUserInput(this.value);
1761
+ }
1762
+ catch (error) {
1763
+ this.characteristicWarning(`An illegal value was supplied by setting \`value\` for characteristic: ${error?.message}`, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error?.stack);
1764
+ return Promise.reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
1765
+ }
1766
+ }
1767
+ return new Promise((resolve, reject) => {
1768
+ try {
1769
+ this.emit("get" /* CharacteristicEventTypes.GET */, (0, once_1.once)((status, value) => {
1770
+ if (status) {
1771
+ if (typeof status === "number") {
1772
+ const hapStatusError = new hapStatusError_1.HapStatusError(status);
787
1773
  this.statusCode = hapStatusError.hapStatus;
788
1774
  // noinspection JSDeprecatedSymbols
789
1775
  this.status = hapStatusError;
790
1776
  }
791
- else if (error_1 instanceof hapStatusError_1.HapStatusError) {
792
- this.statusCode = error_1.hapStatus;
1777
+ else if (status instanceof hapStatusError_1.HapStatusError) {
1778
+ this.statusCode = status.hapStatus;
793
1779
  // noinspection JSDeprecatedSymbols
794
- this.status = error_1;
1780
+ this.status = status;
795
1781
  }
796
1782
  else {
797
- this.characteristicWarning("Unhandled error thrown inside read handler for characteristic: ".concat(error_1 === null || error_1 === void 0 ? void 0 : error_1.message), "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error_1 === null || error_1 === void 0 ? void 0 : error_1.stack);
798
- this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
1783
+ debug("[%s] Received error from get handler %s", this.displayName, status.stack);
1784
+ this.statusCode = extractHAPStatusFromError(status);
799
1785
  // noinspection JSDeprecatedSymbols
800
- this.status = error_1;
801
- }
802
- throw this.statusCode;
803
- case 4:
804
- if (this.listeners("get" /* CharacteristicEventTypes.GET */).length === 0) {
805
- if (this.statusCode) {
806
- throw this.statusCode;
807
- }
808
- try {
809
- return [2 /*return*/, this.validateUserInput(this.value)];
810
- }
811
- catch (error) {
812
- this.characteristicWarning("An illegal value was supplied by setting `value` for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
813
- return [2 /*return*/, Promise.reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */)];
814
- }
1786
+ this.status = status;
815
1787
  }
816
- return [2 /*return*/, new Promise(function (resolve, reject) {
817
- try {
818
- _this.emit("get" /* CharacteristicEventTypes.GET */, (0, once_1.once)(function (status, value) {
819
- if (status) {
820
- if (typeof status === "number") {
821
- var hapStatusError = new hapStatusError_1.HapStatusError(status);
822
- _this.statusCode = hapStatusError.hapStatus;
823
- // noinspection JSDeprecatedSymbols
824
- _this.status = hapStatusError;
825
- }
826
- else if (status instanceof hapStatusError_1.HapStatusError) {
827
- _this.statusCode = status.hapStatus;
828
- // noinspection JSDeprecatedSymbols
829
- _this.status = status;
830
- }
831
- else {
832
- debug("[%s] Received error from get handler %s", _this.displayName, status.stack);
833
- _this.statusCode = extractHAPStatusFromError(status);
834
- // noinspection JSDeprecatedSymbols
835
- _this.status = status;
836
- }
837
- reject(_this.statusCode);
838
- return;
839
- }
840
- _this.statusCode = 0 /* HAPStatus.SUCCESS */;
841
- // noinspection JSDeprecatedSymbols
842
- _this.status = null;
843
- value = _this.validateUserInput(value);
844
- var oldValue = _this.value;
845
- _this.value = value;
846
- resolve(value);
847
- if (oldValue !== value) { // emit a change event if necessary
848
- _this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "read" /* ChangeReason.READ */, context: context });
849
- }
850
- }), context, connection);
851
- }
852
- catch (error) {
853
- _this.characteristicWarning("Unhandled error thrown inside read handler for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
854
- _this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
855
- // noinspection JSDeprecatedSymbols
856
- _this.status = error;
857
- reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
858
- }
859
- })];
860
- }
861
- });
1788
+ reject(this.statusCode);
1789
+ return;
1790
+ }
1791
+ this.statusCode = 0 /* HAPStatus.SUCCESS */;
1792
+ // noinspection JSDeprecatedSymbols
1793
+ this.status = null;
1794
+ value = this.validateUserInput(value);
1795
+ const oldValue = this.value;
1796
+ this.value = value;
1797
+ resolve(value);
1798
+ if (oldValue !== value) { // emit a change event if necessary
1799
+ this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "read" /* ChangeReason.READ */, context: context });
1800
+ }
1801
+ }), context, connection);
1802
+ }
1803
+ catch (error) {
1804
+ this.characteristicWarning(`Unhandled error thrown inside read handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1805
+ this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
1806
+ // noinspection JSDeprecatedSymbols
1807
+ this.status = error;
1808
+ reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
1809
+ }
862
1810
  });
863
- };
1811
+ }
864
1812
  /**
865
1813
  * Called when a HAP requests update the current value of the characteristic.
866
1814
  *
@@ -872,162 +1820,147 @@ var Characteristic = /** @class */ (function (_super) {
872
1820
  * write response value is resolved.
873
1821
  * @private
874
1822
  */
875
- Characteristic.prototype.handleSetRequest = function (value, connection, context) {
876
- return tslib_1.__awaiter(this, void 0, void 0, function () {
877
- var oldValue, writeResponse, error_2, hapStatusError;
878
- var _this = this;
879
- return tslib_1.__generator(this, function (_a) {
880
- switch (_a.label) {
881
- case 0:
882
- this.statusCode = 0 /* HAPStatus.SUCCESS */;
883
- // noinspection JSDeprecatedSymbols
884
- this.status = null;
885
- if (connection !== undefined) {
886
- // if connection is undefined, the set "request" comes from the setValue method.
887
- // for setValue a value of "null" is allowed and checked via validateUserInput.
888
- try {
889
- value = this.validateClientSuppliedValue(value);
1823
+ async handleSetRequest(value, connection, context) {
1824
+ this.statusCode = 0 /* HAPStatus.SUCCESS */;
1825
+ // noinspection JSDeprecatedSymbols
1826
+ this.status = null;
1827
+ if (connection !== undefined) {
1828
+ // if connection is undefined, the set "request" comes from the setValue method.
1829
+ // for setValue a value of "null" is allowed and checked via validateUserInput.
1830
+ try {
1831
+ value = this.validateClientSuppliedValue(value);
1832
+ }
1833
+ catch (e) {
1834
+ debug(`[${this.displayName}]`, e.message);
1835
+ return Promise.reject(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
1836
+ }
1837
+ }
1838
+ const oldValue = this.value;
1839
+ if (this.setHandler) {
1840
+ if (this.listeners("set" /* CharacteristicEventTypes.SET */).length > 0) {
1841
+ this.characteristicWarning("Ignoring on('set') handler as onSet handler was defined instead");
1842
+ }
1843
+ try {
1844
+ const writeResponse = await this.setHandler(value, context, connection);
1845
+ this.statusCode = 0 /* HAPStatus.SUCCESS */;
1846
+ // noinspection JSDeprecatedSymbols
1847
+ this.status = null;
1848
+ if (writeResponse != null && this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
1849
+ this.value = this.validateUserInput(writeResponse);
1850
+ return this.value;
1851
+ }
1852
+ else {
1853
+ if (writeResponse != null) {
1854
+ this.characteristicWarning("SET handler returned write response value, though the characteristic doesn't support write response", "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
1855
+ }
1856
+ this.value = value;
1857
+ this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "write" /* ChangeReason.WRITE */, context: context });
1858
+ return;
1859
+ }
1860
+ }
1861
+ catch (error) {
1862
+ if (typeof error === "number") {
1863
+ const hapStatusError = new hapStatusError_1.HapStatusError(error);
1864
+ this.statusCode = hapStatusError.hapStatus;
1865
+ // noinspection JSDeprecatedSymbols
1866
+ this.status = hapStatusError;
1867
+ }
1868
+ else if (error instanceof hapStatusError_1.HapStatusError) {
1869
+ this.statusCode = error.hapStatus;
1870
+ // noinspection JSDeprecatedSymbols
1871
+ this.status = error;
1872
+ }
1873
+ else {
1874
+ this.characteristicWarning(`Unhandled error thrown inside write handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1875
+ this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
1876
+ // noinspection JSDeprecatedSymbols
1877
+ this.status = error;
1878
+ }
1879
+ throw this.statusCode;
1880
+ }
1881
+ }
1882
+ if (this.listeners("set" /* CharacteristicEventTypes.SET */).length === 0) {
1883
+ this.value = value;
1884
+ this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "write" /* ChangeReason.WRITE */, context: context });
1885
+ return Promise.resolve();
1886
+ }
1887
+ else {
1888
+ return new Promise((resolve, reject) => {
1889
+ try {
1890
+ this.emit("set" /* CharacteristicEventTypes.SET */, value, (0, once_1.once)((status, writeResponse) => {
1891
+ if (status) {
1892
+ if (typeof status === "number") {
1893
+ const hapStatusError = new hapStatusError_1.HapStatusError(status);
1894
+ this.statusCode = hapStatusError.hapStatus;
1895
+ // noinspection JSDeprecatedSymbols
1896
+ this.status = hapStatusError;
890
1897
  }
891
- catch (e) {
892
- debug("[".concat(this.displayName, "]"), e.message);
893
- return [2 /*return*/, Promise.reject(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */)];
1898
+ else if (status instanceof hapStatusError_1.HapStatusError) {
1899
+ this.statusCode = status.hapStatus;
1900
+ // noinspection JSDeprecatedSymbols
1901
+ this.status = status;
894
1902
  }
1903
+ else {
1904
+ debug("[%s] Received error from set handler %s", this.displayName, status.stack);
1905
+ this.statusCode = extractHAPStatusFromError(status);
1906
+ // noinspection JSDeprecatedSymbols
1907
+ this.status = status;
1908
+ }
1909
+ reject(this.statusCode);
1910
+ return;
895
1911
  }
896
- oldValue = this.value;
897
- if (!this.setHandler) return [3 /*break*/, 4];
898
- if (this.listeners("set" /* CharacteristicEventTypes.SET */).length > 0) {
899
- this.characteristicWarning("Ignoring on('set') handler as onSet handler was defined instead");
900
- }
901
- _a.label = 1;
902
- case 1:
903
- _a.trys.push([1, 3, , 4]);
904
- return [4 /*yield*/, this.setHandler(value, context, connection)];
905
- case 2:
906
- writeResponse = _a.sent();
907
1912
  this.statusCode = 0 /* HAPStatus.SUCCESS */;
908
1913
  // noinspection JSDeprecatedSymbols
909
1914
  this.status = null;
910
1915
  if (writeResponse != null && this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
1916
+ // support write response simply by letting the implementor pass the response as second argument to the callback
911
1917
  this.value = this.validateUserInput(writeResponse);
912
- return [2 /*return*/, this.value];
1918
+ resolve(this.value);
913
1919
  }
914
1920
  else {
915
1921
  if (writeResponse != null) {
916
1922
  this.characteristicWarning("SET handler returned write response value, though the characteristic doesn't support write response", "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
917
1923
  }
918
1924
  this.value = value;
1925
+ resolve();
919
1926
  this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "write" /* ChangeReason.WRITE */, context: context });
920
- return [2 /*return*/];
921
- }
922
- return [3 /*break*/, 4];
923
- case 3:
924
- error_2 = _a.sent();
925
- if (typeof error_2 === "number") {
926
- hapStatusError = new hapStatusError_1.HapStatusError(error_2);
927
- this.statusCode = hapStatusError.hapStatus;
928
- // noinspection JSDeprecatedSymbols
929
- this.status = hapStatusError;
930
- }
931
- else if (error_2 instanceof hapStatusError_1.HapStatusError) {
932
- this.statusCode = error_2.hapStatus;
933
- // noinspection JSDeprecatedSymbols
934
- this.status = error_2;
935
- }
936
- else {
937
- this.characteristicWarning("Unhandled error thrown inside write handler for characteristic: ".concat(error_2 === null || error_2 === void 0 ? void 0 : error_2.message), "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error_2 === null || error_2 === void 0 ? void 0 : error_2.stack);
938
- this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
939
- // noinspection JSDeprecatedSymbols
940
- this.status = error_2;
941
- }
942
- throw this.statusCode;
943
- case 4:
944
- if (this.listeners("set" /* CharacteristicEventTypes.SET */).length === 0) {
945
- this.value = value;
946
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "write" /* ChangeReason.WRITE */, context: context });
947
- return [2 /*return*/, Promise.resolve()];
948
- }
949
- else {
950
- return [2 /*return*/, new Promise(function (resolve, reject) {
951
- try {
952
- _this.emit("set" /* CharacteristicEventTypes.SET */, value, (0, once_1.once)(function (status, writeResponse) {
953
- if (status) {
954
- if (typeof status === "number") {
955
- var hapStatusError = new hapStatusError_1.HapStatusError(status);
956
- _this.statusCode = hapStatusError.hapStatus;
957
- // noinspection JSDeprecatedSymbols
958
- _this.status = hapStatusError;
959
- }
960
- else if (status instanceof hapStatusError_1.HapStatusError) {
961
- _this.statusCode = status.hapStatus;
962
- // noinspection JSDeprecatedSymbols
963
- _this.status = status;
964
- }
965
- else {
966
- debug("[%s] Received error from set handler %s", _this.displayName, status.stack);
967
- _this.statusCode = extractHAPStatusFromError(status);
968
- // noinspection JSDeprecatedSymbols
969
- _this.status = status;
970
- }
971
- reject(_this.statusCode);
972
- return;
973
- }
974
- _this.statusCode = 0 /* HAPStatus.SUCCESS */;
975
- // noinspection JSDeprecatedSymbols
976
- _this.status = null;
977
- if (writeResponse != null && _this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
978
- // support write response simply by letting the implementor pass the response as second argument to the callback
979
- _this.value = _this.validateUserInput(writeResponse);
980
- resolve(_this.value);
981
- }
982
- else {
983
- if (writeResponse != null) {
984
- _this.characteristicWarning("SET handler returned write response value, though the characteristic doesn't support write response", "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
985
- }
986
- _this.value = value;
987
- resolve();
988
- _this.emit("change" /* CharacteristicEventTypes.CHANGE */, { originator: connection, oldValue: oldValue, newValue: value, reason: "write" /* ChangeReason.WRITE */, context: context });
989
- }
990
- }), context, connection);
991
- }
992
- catch (error) {
993
- _this.characteristicWarning("Unhandled error thrown inside write handler for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
994
- _this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
995
- // noinspection JSDeprecatedSymbols
996
- _this.status = error;
997
- reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
998
- }
999
- })];
1000
1927
  }
1001
- return [2 /*return*/];
1928
+ }), context, connection);
1929
+ }
1930
+ catch (error) {
1931
+ this.characteristicWarning(`Unhandled error thrown inside write handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1932
+ this.statusCode = -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */;
1933
+ // noinspection JSDeprecatedSymbols
1934
+ this.status = error;
1935
+ reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
1002
1936
  }
1003
1937
  });
1004
- });
1005
- };
1938
+ }
1939
+ }
1006
1940
  /**
1007
1941
  * Called once a HomeKit controller subscribes to events of this characteristic.
1008
1942
  * @private
1009
1943
  */
1010
- Characteristic.prototype.subscribe = function () {
1944
+ subscribe() {
1011
1945
  if (this.subscriptions === 0) {
1012
1946
  this.emit("subscribe" /* CharacteristicEventTypes.SUBSCRIBE */);
1013
1947
  }
1014
1948
  this.subscriptions++;
1015
- };
1949
+ }
1016
1950
  /**
1017
1951
  * Called once a HomeKit controller unsubscribe to events of this characteristic or a HomeKit controller
1018
1952
  * which was subscribed to this characteristic disconnects.
1019
1953
  * @private
1020
1954
  */
1021
- Characteristic.prototype.unsubscribe = function () {
1022
- var wasOne = this.subscriptions === 1;
1955
+ unsubscribe() {
1956
+ const wasOne = this.subscriptions === 1;
1023
1957
  this.subscriptions--;
1024
1958
  this.subscriptions = Math.max(this.subscriptions, 0);
1025
1959
  if (wasOne) {
1026
1960
  this.emit("unsubscribe" /* CharacteristicEventTypes.UNSUBSCRIBE */);
1027
1961
  }
1028
- };
1029
- Characteristic.prototype.getDefaultValue = function () {
1030
- var _a;
1962
+ }
1963
+ getDefaultValue() {
1031
1964
  // noinspection JSDeprecatedSymbols
1032
1965
  switch (this.props.format) {
1033
1966
  case "bool" /* Formats.BOOL */:
@@ -1063,7 +1996,7 @@ var Characteristic = /** @class */ (function (_super) {
1063
1996
  case Characteristic.CurrentTemperature.UUID:
1064
1997
  return 0; // some existing integrations expect this to be 0 by default
1065
1998
  default: {
1066
- if (((_a = this.props.validValues) === null || _a === void 0 ? void 0 : _a.length) && typeof this.props.validValues[0] === "number") {
1999
+ if (this.props.validValues?.length && typeof this.props.validValues[0] === "number") {
1067
2000
  return this.props.validValues[0];
1068
2001
  }
1069
2002
  if (typeof this.props.minValue === "number" && Number.isFinite(this.props.minValue)) {
@@ -1075,16 +2008,16 @@ var Characteristic = /** @class */ (function (_super) {
1075
2008
  default:
1076
2009
  return 0;
1077
2010
  }
1078
- };
2011
+ }
1079
2012
  /**
1080
2013
  * Checks if the value received from the HAP request is valid.
1081
2014
  * If returned false the received value is not valid and {@link HAPStatus.INVALID_VALUE_IN_REQUEST}
1082
2015
  * must be returned.
1083
2016
  * @param value - Value supplied by the HomeKit controller
1084
2017
  */
1085
- Characteristic.prototype.validateClientSuppliedValue = function (value) {
2018
+ validateClientSuppliedValue(value) {
1086
2019
  if (value == null) {
1087
- throw new Error("Client supplied invalid value for ".concat(this.props.format, ": ").concat(value));
2020
+ throw new Error(`Client supplied invalid value for ${this.props.format}: ${value}`);
1088
2021
  }
1089
2022
  switch (this.props.format) {
1090
2023
  case "bool" /* Formats.BOOL */: {
@@ -1094,7 +2027,7 @@ var Characteristic = /** @class */ (function (_super) {
1094
2027
  if (typeof value === "number" && (value === 1 || value === 0)) {
1095
2028
  return Boolean(value);
1096
2029
  }
1097
- throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
2030
+ throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
1098
2031
  }
1099
2032
  case "int" /* Formats.INT */:
1100
2033
  case "float" /* Formats.FLOAT */:
@@ -1106,58 +2039,58 @@ var Characteristic = /** @class */ (function (_super) {
1106
2039
  value = value ? 1 : 0;
1107
2040
  }
1108
2041
  if (typeof value !== "number" || !Number.isFinite(value)) {
1109
- throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
2042
+ throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
1110
2043
  }
1111
- var numericMin = maxWithUndefined(this.props.minValue, (0, request_util_1.numericLowerBound)(this.props.format));
1112
- var numericMax = minWithUndefined(this.props.maxValue, (0, request_util_1.numericUpperBound)(this.props.format));
2044
+ const numericMin = maxWithUndefined(this.props.minValue, (0, request_util_1.numericLowerBound)(this.props.format));
2045
+ const numericMax = minWithUndefined(this.props.maxValue, (0, request_util_1.numericUpperBound)(this.props.format));
1113
2046
  if (typeof numericMin === "number" && value < numericMin) {
1114
- throw new Error("Client supplied value of ".concat(value, " is less than the minimum allowed value of ").concat(numericMin));
2047
+ throw new Error(`Client supplied value of ${value} is less than the minimum allowed value of ${numericMin}`);
1115
2048
  }
1116
2049
  if (typeof numericMax === "number" && value > numericMax) {
1117
- throw new Error("Client supplied value of ".concat(value, " is greater than the maximum allowed value of ").concat(numericMax));
2050
+ throw new Error(`Client supplied value of ${value} is greater than the maximum allowed value of ${numericMax}`);
1118
2051
  }
1119
2052
  if (this.props.validValues && !this.props.validValues.includes(value)) {
1120
- throw new Error("Client supplied value of ".concat(value, " is not in ").concat(this.props.validValues.toString()));
2053
+ throw new Error(`Client supplied value of ${value} is not in ${this.props.validValues.toString()}`);
1121
2054
  }
1122
2055
  if (this.props.validValueRanges && this.props.validValueRanges.length === 2) {
1123
2056
  if (value < this.props.validValueRanges[0]) {
1124
- throw new Error("Client supplied value of ".concat(value, " is less than the minimum allowed value of ").concat(this.props.validValueRanges[0]));
2057
+ throw new Error(`Client supplied value of ${value} is less than the minimum allowed value of ${this.props.validValueRanges[0]}`);
1125
2058
  }
1126
2059
  if (value > this.props.validValueRanges[1]) {
1127
- throw new Error("Client supplied value of ".concat(value, " is greater than the maximum allowed value of ").concat(this.props.validValueRanges[1]));
2060
+ throw new Error(`Client supplied value of ${value} is greater than the maximum allowed value of ${this.props.validValueRanges[1]}`);
1128
2061
  }
1129
2062
  }
1130
2063
  return value;
1131
2064
  }
1132
2065
  case "string" /* Formats.STRING */: {
1133
2066
  if (typeof value !== "string") {
1134
- throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
2067
+ throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
1135
2068
  }
1136
- var maxLength = this.props.maxLen != null ? this.props.maxLen : 64; // default is 64; max is 256 which is set in setProps
2069
+ const maxLength = this.props.maxLen != null ? this.props.maxLen : 64; // default is 64; max is 256 which is set in setProps
1137
2070
  if (value.length > maxLength) {
1138
- throw new Error("Client supplied value length of ".concat(value.length, " exceeds maximum length allowed of ").concat(maxLength));
2071
+ throw new Error(`Client supplied value length of ${value.length} exceeds maximum length allowed of ${maxLength}`);
1139
2072
  }
1140
2073
  return value;
1141
2074
  }
1142
2075
  case "data" /* Formats.DATA */: {
1143
2076
  if (typeof value !== "string") {
1144
- throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
2077
+ throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
1145
2078
  }
1146
2079
  // we don't validate base64 here
1147
- var maxLength = this.props.maxDataLen != null ? this.props.maxDataLen : 0x200000; // default is 0x200000
2080
+ const maxLength = this.props.maxDataLen != null ? this.props.maxDataLen : 0x200000; // default is 0x200000
1148
2081
  if (value.length > maxLength) {
1149
- throw new Error("Client supplied value length of ".concat(value.length, " exceeds maximum length allowed of ").concat(maxLength));
2082
+ throw new Error(`Client supplied value length of ${value.length} exceeds maximum length allowed of ${maxLength}`);
1150
2083
  }
1151
2084
  return value;
1152
2085
  }
1153
2086
  case "tlv8" /* Formats.TLV8 */:
1154
2087
  if (typeof value !== "string") {
1155
- throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
2088
+ throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
1156
2089
  }
1157
2090
  return value;
1158
2091
  }
1159
2092
  return value;
1160
- };
2093
+ }
1161
2094
  /**
1162
2095
  * Checks if the value received from the API call is valid.
1163
2096
  * It adjusts the value where it makes sense, prints a warning where values may be rejected with an error
@@ -1166,9 +2099,7 @@ var Characteristic = /** @class */ (function (_super) {
1166
2099
  * @param value - The value received from the API call
1167
2100
  * @param warningType - Optionally defines the warning type to use when raising a {@link CharacteristicEventTypes.CHARACTERISTIC_WARNING}.
1168
2101
  */
1169
- Characteristic.prototype.validateUserInput = function (value, warningType) {
1170
- var _a;
1171
- if (warningType === void 0) { warningType = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */; }
2102
+ validateUserInput(value, warningType = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */) {
1172
2103
  if (value === null) {
1173
2104
  if (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID) { // mirrors the statement in case: Formats.STRING
1174
2105
  this.characteristicWarning("characteristic must have a non null value otherwise HomeKit will reject this accessory, ignoring new value", "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
@@ -1229,12 +2160,12 @@ var Characteristic = /** @class */ (function (_super) {
1229
2160
  value = this.props.format === "float" /* Formats.FLOAT */ ? parseFloat(value) : parseInt(value, 10);
1230
2161
  }
1231
2162
  if (typeof value !== "number" || !Number.isFinite(value)) {
1232
- this.characteristicWarning("characteristic value expected valid finite number and received \"".concat(value, "\" (").concat(typeof value, ")"), warningType);
2163
+ this.characteristicWarning(`characteristic value expected valid finite number and received "${value}" (${typeof value})`, warningType);
1233
2164
  value = typeof this.value === "number" ? this.value : this.props.minValue || 0;
1234
2165
  }
1235
- var numericMin = maxWithUndefined(this.props.minValue, (0, request_util_1.numericLowerBound)(this.props.format));
1236
- var numericMax = minWithUndefined(this.props.maxValue, (0, request_util_1.numericUpperBound)(this.props.format));
1237
- var stepValue = undefined;
2166
+ const numericMin = maxWithUndefined(this.props.minValue, (0, request_util_1.numericLowerBound)(this.props.format));
2167
+ const numericMax = minWithUndefined(this.props.maxValue, (0, request_util_1.numericUpperBound)(this.props.format));
2168
+ let stepValue = undefined;
1238
2169
  if (this.props.format === "float" /* Formats.FLOAT */) {
1239
2170
  stepValue = this.props.minStep;
1240
2171
  }
@@ -1242,28 +2173,30 @@ var Characteristic = /** @class */ (function (_super) {
1242
2173
  stepValue = maxWithUndefined(this.props.minStep, 1);
1243
2174
  }
1244
2175
  if (stepValue != null && stepValue > 0) {
1245
- var minValue = this.props.minValue != null ? this.props.minValue : 0;
2176
+ const minValue = this.props.minValue != null ? this.props.minValue : 0;
1246
2177
  value = stepValue * Math.round((value - minValue) / stepValue) + minValue;
1247
2178
  }
1248
2179
  if (numericMin != null && value < numericMin) {
1249
- this.characteristicWarning("characteristic was supplied illegal value: number ".concat(value, " exceeded minimum of ").concat(numericMin), warningType);
2180
+ this.characteristicWarning(`characteristic was supplied illegal value: number ${value} exceeded minimum of ${numericMin}`, warningType);
1250
2181
  value = numericMin;
1251
2182
  }
1252
2183
  if (numericMax != null && value > numericMax) {
1253
- this.characteristicWarning("characteristic was supplied illegal value: number ".concat(value, " exceeded maximum of ").concat(numericMax), warningType);
2184
+ this.characteristicWarning(`characteristic was supplied illegal value: number ${value} exceeded maximum of ${numericMax}`, warningType);
1254
2185
  value = numericMax;
1255
2186
  }
1256
2187
  if (this.props.validValues && !this.props.validValues.includes(value)) {
1257
- this.characteristicWarning("characteristic value ".concat(value, " is not contained in valid values array"), warningType);
2188
+ this.characteristicWarning(`characteristic value ${value} is not contained in valid values array`, warningType);
1258
2189
  return this.props.validValues.includes(this.value) ? this.value : (this.props.validValues[0] || 0);
1259
2190
  }
1260
2191
  if (this.props.validValueRanges && this.props.validValueRanges.length === 2) {
1261
2192
  if (value < this.props.validValueRanges[0]) {
1262
- this.characteristicWarning("characteristic was supplied illegal value: number ".concat(value, " not contained in valid value range of ").concat(this.props.validValueRanges, ", supplying illegal values will throw errors in the future"), warningType);
2193
+ this.characteristicWarning(`characteristic was supplied illegal value: number ${value} not contained in valid value range of `
2194
+ + `${this.props.validValueRanges}, supplying illegal values will throw errors in the future`, warningType);
1263
2195
  value = this.props.validValueRanges[0];
1264
2196
  }
1265
2197
  else if (value > this.props.validValueRanges[1]) {
1266
- this.characteristicWarning("characteristic was supplied illegal value: number ".concat(value, " not contained in valid value range of ").concat(this.props.validValueRanges, ", supplying illegal values will throw errors in the future"), warningType);
2198
+ this.characteristicWarning(`characteristic was supplied illegal value: number ${value} not contained in valid value range of `
2199
+ + `${this.props.validValueRanges}, supplying illegal values will throw errors in the future`, warningType);
1267
2200
  value = this.props.validValueRanges[1];
1268
2201
  }
1269
2202
  }
@@ -1281,13 +2214,13 @@ var Characteristic = /** @class */ (function (_super) {
1281
2214
  }
1282
2215
  // mirrors the case value = null at the beginning
1283
2216
  if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) {
1284
- this.characteristicWarning("[".concat(this.displayName, "] characteristic must have a length of more than 1 character otherwise")
1285
- + " HomeKit will reject this accessory, ignoring new value ".concat(warningType));
2217
+ this.characteristicWarning(`[${this.displayName}] characteristic must have a length of more than 1 character otherwise`
2218
+ + ` HomeKit will reject this accessory, ignoring new value ${warningType}`);
1286
2219
  return this.value; // just return the current value
1287
2220
  }
1288
- var maxLength = (_a = this.props.maxLen) !== null && _a !== void 0 ? _a : 64; // default is 64 (max is 256 which is set in setProps)
2221
+ const maxLength = this.props.maxLen ?? 64; // default is 64 (max is 256 which is set in setProps)
1289
2222
  if (value.length > maxLength) {
1290
- this.characteristicWarning("characteristic was supplied illegal value: string '".concat(value, "' exceeded max length of ").concat(maxLength), warningType);
2223
+ this.characteristicWarning(`characteristic was supplied illegal value: string '${value}' exceeded max length of ${maxLength}`, warningType);
1291
2224
  value = value.substring(0, maxLength);
1292
2225
  }
1293
2226
  if (value.length > 0 && this.UUID === Characteristic.ConfiguredName.UUID) {
@@ -1317,109 +2250,88 @@ var Characteristic = /** @class */ (function (_super) {
1317
2250
  return this.value;
1318
2251
  }
1319
2252
  return value;
1320
- };
2253
+ }
1321
2254
  /**
1322
2255
  * @private used to assign iid to characteristic
1323
2256
  */
1324
- Characteristic.prototype._assignID = function (identifierCache, accessoryName, serviceUUID, serviceSubtype) {
2257
+ _assignID(identifierCache, accessoryName, serviceUUID, serviceSubtype) {
1325
2258
  // generate our IID based on our UUID
1326
2259
  this.iid = identifierCache.getIID(accessoryName, serviceUUID, serviceSubtype, this.UUID);
1327
- };
1328
- Characteristic.prototype.characteristicWarning = function (message, type, stack) {
1329
- if (type === void 0) { type = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */; }
1330
- if (stack === void 0) { stack = new Error().stack; }
2260
+ }
2261
+ characteristicWarning(message, type = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, stack = new Error().stack) {
1331
2262
  this.emit("characteristic-warning" /* CharacteristicEventTypes.CHARACTERISTIC_WARNING */, type, message, stack);
1332
- };
2263
+ }
1333
2264
  /**
1334
2265
  * @param event
1335
2266
  * @private
1336
2267
  */
1337
- Characteristic.prototype.removeAllListeners = function (event) {
2268
+ removeAllListeners(event) {
1338
2269
  if (!event) {
1339
2270
  this.removeOnGet();
1340
2271
  this.removeOnSet();
1341
2272
  }
1342
- return _super.prototype.removeAllListeners.call(this, event);
1343
- };
2273
+ return super.removeAllListeners(event);
2274
+ }
1344
2275
  /**
1345
2276
  * @param characteristic
1346
2277
  * @private
1347
2278
  */
1348
- Characteristic.prototype.replaceBy = function (characteristic) {
1349
- var _this = this;
2279
+ replaceBy(characteristic) {
1350
2280
  this.props = characteristic.props;
1351
2281
  this.updateValue(characteristic.value);
1352
- var getListeners = characteristic.listeners("get" /* CharacteristicEventTypes.GET */);
2282
+ const getListeners = characteristic.listeners("get" /* CharacteristicEventTypes.GET */);
1353
2283
  if (getListeners.length) {
1354
2284
  // the callback can only be called once, so we remove all old listeners
1355
2285
  this.removeAllListeners("get" /* CharacteristicEventTypes.GET */);
1356
2286
  // @ts-expect-error: force type
1357
- getListeners.forEach(function (listener) { return _this.addListener("get" /* CharacteristicEventTypes.GET */, listener); });
2287
+ getListeners.forEach(listener => this.addListener("get" /* CharacteristicEventTypes.GET */, listener));
1358
2288
  }
1359
2289
  this.removeOnGet();
1360
2290
  if (characteristic.getHandler) {
1361
2291
  this.onGet(characteristic.getHandler);
1362
2292
  }
1363
- var setListeners = characteristic.listeners("set" /* CharacteristicEventTypes.SET */);
2293
+ const setListeners = characteristic.listeners("set" /* CharacteristicEventTypes.SET */);
1364
2294
  if (setListeners.length) {
1365
2295
  // the callback can only be called once, so we remove all old listeners
1366
2296
  this.removeAllListeners("set" /* CharacteristicEventTypes.SET */);
1367
2297
  // @ts-expect-error: force type
1368
- setListeners.forEach(function (listener) { return _this.addListener("set" /* CharacteristicEventTypes.SET */, listener); });
2298
+ setListeners.forEach(listener => this.addListener("set" /* CharacteristicEventTypes.SET */, listener));
1369
2299
  }
1370
2300
  this.removeOnSet();
1371
2301
  if (characteristic.setHandler) {
1372
2302
  this.onSet(characteristic.setHandler);
1373
2303
  }
1374
- };
2304
+ }
1375
2305
  /**
1376
2306
  * Returns a JSON representation of this characteristic suitable for delivering to HAP clients.
1377
2307
  * @private used to generate response to /accessories query
1378
2308
  */
1379
- Characteristic.prototype.toHAP = function (connection_1) {
1380
- return tslib_1.__awaiter(this, arguments, void 0, function (connection, contactGetHandlers) {
1381
- var object, value, _a;
1382
- var _this = this;
1383
- if (contactGetHandlers === void 0) { contactGetHandlers = true; }
1384
- return tslib_1.__generator(this, function (_b) {
1385
- switch (_b.label) {
1386
- case 0:
1387
- object = this.internalHAPRepresentation();
1388
- if (!!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) return [3 /*break*/, 1];
1389
- object.value = undefined;
1390
- return [3 /*break*/, 6];
1391
- case 1:
1392
- if (!(this.UUID === Characteristic.ProgrammableSwitchEvent.UUID)) return [3 /*break*/, 2];
1393
- // special workaround for event only programmable switch event, which must always return null
1394
- object.value = null;
1395
- return [3 /*break*/, 6];
1396
- case 2:
1397
- if (!contactGetHandlers) return [3 /*break*/, 4];
1398
- return [4 /*yield*/, this.handleGetRequest(connection).catch(function () {
1399
- var value = _this.getDefaultValue();
1400
- debug("[%s] Error getting value for characteristic on /accessories request. Returning default value instead: %s", _this.displayName, "".concat(value));
1401
- return value; // use default value
1402
- })];
1403
- case 3:
1404
- _a = _b.sent();
1405
- return [3 /*break*/, 5];
1406
- case 4:
1407
- _a = this.value;
1408
- _b.label = 5;
1409
- case 5:
1410
- value = _a;
1411
- object.value = (0, request_util_1.formatOutgoingCharacteristicValue)(value, this.props);
1412
- _b.label = 6;
1413
- case 6: return [2 /*return*/, object];
1414
- }
1415
- });
1416
- });
1417
- };
2309
+ async toHAP(connection, contactGetHandlers = true) {
2310
+ const object = this.internalHAPRepresentation();
2311
+ if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) {
2312
+ object.value = undefined;
2313
+ }
2314
+ else if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
2315
+ // special workaround for event only programmable switch event, which must always return null
2316
+ object.value = null;
2317
+ }
2318
+ else { // query the current value
2319
+ const value = contactGetHandlers
2320
+ ? await this.handleGetRequest(connection).catch(() => {
2321
+ const value = this.getDefaultValue();
2322
+ debug("[%s] Error getting value for characteristic on /accessories request. Returning default value instead: %s", this.displayName, `${value}`);
2323
+ return value; // use default value
2324
+ })
2325
+ : this.value;
2326
+ object.value = (0, request_util_1.formatOutgoingCharacteristicValue)(value, this.props);
2327
+ }
2328
+ return object;
2329
+ }
1418
2330
  /**
1419
2331
  * Returns a JSON representation of this characteristic without the value.
1420
2332
  * @private used to generate the config hash
1421
2333
  */
1422
- Characteristic.prototype.internalHAPRepresentation = function () {
2334
+ internalHAPRepresentation() {
1423
2335
  (0, assert_1.default)(this.iid, "iid cannot be undefined for characteristic '" + this.displayName + "'");
1424
2336
  // TODO include the value for characteristics of the AccessoryInformation service
1425
2337
  return {
@@ -1438,15 +2350,15 @@ var Characteristic = /** @class */ (function (_super) {
1438
2350
  "valid-values": this.props.validValues,
1439
2351
  "valid-values-range": this.props.validValueRanges,
1440
2352
  };
1441
- };
2353
+ }
1442
2354
  /**
1443
2355
  * Serialize characteristic into json string.
1444
2356
  *
1445
2357
  * @param characteristic - Characteristic object.
1446
2358
  * @private used to store characteristic on disk
1447
2359
  */
1448
- Characteristic.serialize = function (characteristic) {
1449
- var constructorName;
2360
+ static serialize(characteristic) {
2361
+ let constructorName;
1450
2362
  if (characteristic.constructor.name !== "Characteristic") {
1451
2363
  constructorName = characteristic.constructor.name;
1452
2364
  }
@@ -1458,18 +2370,18 @@ var Characteristic = /** @class */ (function (_super) {
1458
2370
  value: characteristic.value,
1459
2371
  props: (0, clone_1.clone)({}, characteristic.props),
1460
2372
  };
1461
- };
2373
+ }
1462
2374
  /**
1463
2375
  * Deserialize characteristic from json string.
1464
2376
  *
1465
2377
  * @param json - Json string representing a characteristic.
1466
2378
  * @private used to recreate characteristic from disk
1467
2379
  */
1468
- Characteristic.deserialize = function (json) {
1469
- var characteristic;
2380
+ static deserialize(json) {
2381
+ let characteristic;
1470
2382
  if (json.constructorName && json.constructorName.charAt(0).toUpperCase() === json.constructorName.charAt(0)
1471
2383
  && Characteristic[json.constructorName]) { // MUST start with uppercase character and must exist on Characteristic object
1472
- var constructor = Characteristic[json.constructorName];
2384
+ const constructor = Characteristic[json.constructorName];
1473
2385
  characteristic = new constructor();
1474
2386
  characteristic.displayName = json.displayName;
1475
2387
  characteristic.setProps(json.props);
@@ -1479,24 +2391,8 @@ var Characteristic = /** @class */ (function (_super) {
1479
2391
  }
1480
2392
  characteristic.value = json.value;
1481
2393
  return characteristic;
1482
- };
1483
- /**
1484
- * @deprecated Please use the Formats const enum above.
1485
- */
1486
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1487
- Characteristic.Formats = Formats;
1488
- /**
1489
- * @deprecated Please use the Units const enum above.
1490
- */
1491
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1492
- Characteristic.Units = Units;
1493
- /**
1494
- * @deprecated Please use the Perms const enum above.
1495
- */
1496
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1497
- Characteristic.Perms = Perms;
1498
- return Characteristic;
1499
- }(events_1.EventEmitter));
2394
+ }
2395
+ }
1500
2396
  exports.Characteristic = Characteristic;
1501
2397
  // We have a cyclic dependency problem. Within this file we have the definitions of "./definitions" as
1502
2398
  // type imports only (in order to define the static properties). Setting those properties is done outside