hap-nodejs 0.10.0-beta.0 → 0.10.0-beta.12

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 (213) hide show
  1. package/@types/bonjour-hap.d.ts +4 -3
  2. package/@types/simple-plist.d.ts +2 -1
  3. package/README.md +1 -1
  4. package/dist/BridgedCore.js +7 -6
  5. package/dist/BridgedCore.js.map +1 -1
  6. package/dist/Core.js +14 -12
  7. package/dist/Core.js.map +1 -1
  8. package/dist/accessories/AirConditioner_accessory.js +9 -9
  9. package/dist/accessories/AirConditioner_accessory.js.map +1 -1
  10. package/dist/accessories/AppleTVRemote_accessory.js +17 -16
  11. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
  12. package/dist/accessories/Camera_accessory.js +415 -36
  13. package/dist/accessories/Camera_accessory.js.map +1 -1
  14. package/dist/accessories/Fan_accessory.js +10 -15
  15. package/dist/accessories/Fan_accessory.js.map +1 -1
  16. package/dist/accessories/GarageDoorOpener_accessory.js +7 -8
  17. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
  18. package/dist/accessories/Light-AdaptiveLighting_accessory.js +3 -4
  19. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
  20. package/dist/accessories/Light_accessory.js +23 -14
  21. package/dist/accessories/Light_accessory.js.map +1 -1
  22. package/dist/accessories/Lock_accessory.js +7 -8
  23. package/dist/accessories/Lock_accessory.js.map +1 -1
  24. package/dist/accessories/MotionSensor_accessory.js +5 -6
  25. package/dist/accessories/MotionSensor_accessory.js.map +1 -1
  26. package/dist/accessories/Outlet_accessory.js +5 -6
  27. package/dist/accessories/Outlet_accessory.js.map +1 -1
  28. package/dist/accessories/SmartSpeaker_accessory.js +6 -6
  29. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
  30. package/dist/accessories/Sprinkler_accessory.js +12 -13
  31. package/dist/accessories/Sprinkler_accessory.js.map +1 -1
  32. package/dist/accessories/TV_accessory.js +4 -5
  33. package/dist/accessories/TV_accessory.js.map +1 -1
  34. package/dist/accessories/TemperatureSensor_accessory.js +5 -6
  35. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
  36. package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
  37. package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
  38. package/dist/accessories/Wi-FiRouter_accessory.js +7 -8
  39. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
  40. package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
  41. package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
  42. package/dist/accessories/Wi-FiSatellite_accessory.js +6 -7
  43. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
  44. package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
  45. package/dist/accessories/gstreamer-audioProducer.js +21 -22
  46. package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
  47. package/dist/index.d.ts +27 -22
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +35 -24
  50. package/dist/index.js.map +1 -1
  51. package/dist/internal-types.d.ts +2 -0
  52. package/dist/internal-types.d.ts.map +1 -1
  53. package/dist/internal-types.js.map +1 -1
  54. package/dist/lib/Accessory.d.ts +38 -17
  55. package/dist/lib/Accessory.d.ts.map +1 -1
  56. package/dist/lib/Accessory.js +345 -273
  57. package/dist/lib/Accessory.js.map +1 -1
  58. package/dist/lib/AccessoryLoader.d.ts +10 -10
  59. package/dist/lib/AccessoryLoader.d.ts.map +1 -1
  60. package/dist/lib/AccessoryLoader.js +109 -99
  61. package/dist/lib/AccessoryLoader.js.map +1 -1
  62. package/dist/lib/Advertiser.d.ts +26 -6
  63. package/dist/lib/Advertiser.d.ts.map +1 -1
  64. package/dist/lib/Advertiser.js +242 -29
  65. package/dist/lib/Advertiser.js.map +1 -1
  66. package/dist/lib/Bridge.d.ts +1 -1
  67. package/dist/lib/Bridge.d.ts.map +1 -1
  68. package/dist/lib/Bridge.js +1 -1
  69. package/dist/lib/Bridge.js.map +1 -1
  70. package/dist/lib/Characteristic.d.ts +36 -23
  71. package/dist/lib/Characteristic.d.ts.map +1 -1
  72. package/dist/lib/Characteristic.js +148 -145
  73. package/dist/lib/Characteristic.js.map +1 -1
  74. package/dist/lib/HAPServer.d.ts +2 -2
  75. package/dist/lib/HAPServer.d.ts.map +1 -1
  76. package/dist/lib/HAPServer.js +43 -39
  77. package/dist/lib/HAPServer.js.map +1 -1
  78. package/dist/lib/Service.d.ts +8 -4
  79. package/dist/lib/Service.d.ts.map +1 -1
  80. package/dist/lib/Service.js +51 -47
  81. package/dist/lib/Service.js.map +1 -1
  82. package/dist/lib/camera/Camera.d.ts +2 -2
  83. package/dist/lib/camera/Camera.d.ts.map +1 -1
  84. package/dist/lib/camera/Camera.js +3 -3
  85. package/dist/lib/camera/Camera.js.map +1 -1
  86. package/dist/lib/camera/RTPProxy.d.ts +19 -19
  87. package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
  88. package/dist/lib/camera/RTPProxy.js +230 -208
  89. package/dist/lib/camera/RTPProxy.js.map +1 -1
  90. package/dist/lib/camera/RTPStreamManagement.d.ts +46 -10
  91. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
  92. package/dist/lib/camera/RTPStreamManagement.js +124 -49
  93. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  94. package/dist/lib/camera/RecordingManagement.d.ts +267 -0
  95. package/dist/lib/camera/RecordingManagement.d.ts.map +1 -0
  96. package/dist/lib/camera/RecordingManagement.js +750 -0
  97. package/dist/lib/camera/RecordingManagement.js.map +1 -0
  98. package/dist/lib/camera/index.d.ts +4 -3
  99. package/dist/lib/camera/index.d.ts.map +1 -1
  100. package/dist/lib/camera/index.js +4 -3
  101. package/dist/lib/camera/index.js.map +1 -1
  102. package/dist/lib/controller/AdaptiveLightingController.d.ts +9 -9
  103. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
  104. package/dist/lib/controller/AdaptiveLightingController.js +37 -31
  105. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  106. package/dist/lib/controller/CameraController.d.ts +254 -7
  107. package/dist/lib/controller/CameraController.d.ts.map +1 -1
  108. package/dist/lib/controller/CameraController.js +382 -35
  109. package/dist/lib/controller/CameraController.js.map +1 -1
  110. package/dist/lib/controller/Controller.d.ts +3 -3
  111. package/dist/lib/controller/Controller.d.ts.map +1 -1
  112. package/dist/lib/controller/Controller.js.map +1 -1
  113. package/dist/lib/controller/DoorbellController.d.ts +43 -1
  114. package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
  115. package/dist/lib/controller/DoorbellController.js +64 -12
  116. package/dist/lib/controller/DoorbellController.js.map +1 -1
  117. package/dist/lib/controller/RemoteController.d.ts +4 -4
  118. package/dist/lib/controller/RemoteController.d.ts.map +1 -1
  119. package/dist/lib/controller/RemoteController.js +79 -69
  120. package/dist/lib/controller/RemoteController.js.map +1 -1
  121. package/dist/lib/controller/index.d.ts +4 -4
  122. package/dist/lib/controller/index.js +5 -5
  123. package/dist/lib/controller/index.js.map +1 -1
  124. package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
  125. package/dist/lib/datastream/DataStreamManagement.js +12 -11
  126. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  127. package/dist/lib/datastream/DataStreamParser.d.ts +24 -24
  128. package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
  129. package/dist/lib/datastream/DataStreamParser.js +31 -22
  130. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  131. package/dist/lib/datastream/DataStreamServer.d.ts +24 -5
  132. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  133. package/dist/lib/datastream/DataStreamServer.js +109 -68
  134. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  135. package/dist/lib/datastream/index.d.ts +3 -3
  136. package/dist/lib/datastream/index.js +3 -3
  137. package/dist/lib/datastream/index.js.map +1 -1
  138. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +84 -0
  139. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
  140. package/dist/lib/definitions/CharacteristicDefinitions.js +471 -243
  141. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  142. package/dist/lib/definitions/ServiceDefinitions.d.ts +28 -0
  143. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
  144. package/dist/lib/definitions/ServiceDefinitions.js +158 -74
  145. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  146. package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
  147. package/dist/lib/definitions/generate-definitions.js +76 -72
  148. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  149. package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
  150. package/dist/lib/definitions/generator-configuration.js +34 -16
  151. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  152. package/dist/lib/definitions/index.js +2 -2
  153. package/dist/lib/definitions/index.js.map +1 -1
  154. package/dist/lib/model/AccessoryInfo.d.ts +6 -6
  155. package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
  156. package/dist/lib/model/AccessoryInfo.js +86 -76
  157. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  158. package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
  159. package/dist/lib/model/ControllerStorage.js +9 -9
  160. package/dist/lib/model/ControllerStorage.js.map +1 -1
  161. package/dist/lib/model/HAPStorage.d.ts.map +1 -1
  162. package/dist/lib/model/HAPStorage.js +2 -1
  163. package/dist/lib/model/HAPStorage.js.map +1 -1
  164. package/dist/lib/model/IdentifierCache.d.ts +11 -11
  165. package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
  166. package/dist/lib/model/IdentifierCache.js +69 -67
  167. package/dist/lib/model/IdentifierCache.js.map +1 -1
  168. package/dist/lib/tv/AccessControlManagement.d.ts +1 -1
  169. package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
  170. package/dist/lib/tv/AccessControlManagement.js +2 -2
  171. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  172. package/dist/lib/util/clone.js +5 -4
  173. package/dist/lib/util/clone.js.map +1 -1
  174. package/dist/lib/util/color-utils.d.ts.map +1 -1
  175. package/dist/lib/util/color-utils.js +2 -2
  176. package/dist/lib/util/color-utils.js.map +1 -1
  177. package/dist/lib/util/eventedhttp.d.ts +4 -4
  178. package/dist/lib/util/eventedhttp.d.ts.map +1 -1
  179. package/dist/lib/util/eventedhttp.js +54 -51
  180. package/dist/lib/util/eventedhttp.js.map +1 -1
  181. package/dist/lib/util/hapCrypto.d.ts +5 -5
  182. package/dist/lib/util/hapCrypto.d.ts.map +1 -1
  183. package/dist/lib/util/hapCrypto.js +66 -82
  184. package/dist/lib/util/hapCrypto.js.map +1 -1
  185. package/dist/lib/util/hapStatusError.js +3 -3
  186. package/dist/lib/util/hapStatusError.js.map +1 -1
  187. package/dist/lib/util/net-utils.d.ts.map +1 -1
  188. package/dist/lib/util/net-utils.js +4 -6
  189. package/dist/lib/util/net-utils.js.map +1 -1
  190. package/dist/lib/util/once.d.ts +1 -1
  191. package/dist/lib/util/once.d.ts.map +1 -1
  192. package/dist/lib/util/once.js +2 -1
  193. package/dist/lib/util/once.js.map +1 -1
  194. package/dist/lib/util/promise-utils.d.ts +2 -0
  195. package/dist/lib/util/promise-utils.d.ts.map +1 -0
  196. package/dist/lib/util/promise-utils.js +10 -0
  197. package/dist/lib/util/promise-utils.js.map +1 -0
  198. package/dist/lib/util/request-util.d.ts.map +1 -1
  199. package/dist/lib/util/request-util.js +1 -0
  200. package/dist/lib/util/request-util.js.map +1 -1
  201. package/dist/lib/util/time.d.ts +1 -1
  202. package/dist/lib/util/time.d.ts.map +1 -1
  203. package/dist/lib/util/time.js +8 -8
  204. package/dist/lib/util/time.js.map +1 -1
  205. package/dist/lib/util/tlv.d.ts.map +1 -1
  206. package/dist/lib/util/tlv.js +15 -12
  207. package/dist/lib/util/tlv.js.map +1 -1
  208. package/dist/lib/util/uuid.d.ts.map +1 -1
  209. package/dist/lib/util/uuid.js +26 -20
  210. package/dist/lib/util/uuid.js.map +1 -1
  211. package/dist/types.d.ts +0 -1
  212. package/dist/types.d.ts.map +1 -1
  213. package/package.json +22 -19
@@ -2,8 +2,8 @@
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
4
  var tslib_1 = require("tslib");
5
- var assert_1 = tslib_1.__importDefault(require("assert"));
6
- var debug_1 = tslib_1.__importDefault(require("debug"));
5
+ var assert_1 = (0, tslib_1.__importDefault)(require("assert"));
6
+ var debug_1 = (0, tslib_1.__importDefault)(require("debug"));
7
7
  var events_1 = require("events");
8
8
  var definitions_1 = require("./definitions");
9
9
  var HAPServer_1 = require("./HAPServer");
@@ -12,7 +12,7 @@ var hapStatusError_1 = require("./util/hapStatusError");
12
12
  var once_1 = require("./util/once");
13
13
  var request_util_1 = require("./util/request-util");
14
14
  var uuid_1 = require("./util/uuid");
15
- var debug = debug_1.default("HAP-NodeJS:Characteristic");
15
+ var debug = (0, debug_1.default)("HAP-NodeJS:Characteristic");
16
16
  var Formats;
17
17
  (function (Formats) {
18
18
  Formats["BOOL"] = "bool";
@@ -155,20 +155,20 @@ var CharacteristicEventTypes;
155
155
  })(CharacteristicEventTypes = exports.CharacteristicEventTypes || (exports.CharacteristicEventTypes = {}));
156
156
  var ValidValuesIterable = /** @class */ (function () {
157
157
  function ValidValuesIterable(props) {
158
- assert_1.default(request_util_1.isNumericFormat(props.format), "Cannot instantiate valid values iterable when format is not numeric. Found " + props.format);
158
+ (0, assert_1.default)((0, request_util_1.isNumericFormat)(props.format), "Cannot instantiate valid values iterable when format is not numeric. Found " + props.format);
159
159
  this.props = props;
160
160
  }
161
161
  ValidValuesIterable.prototype[Symbol.iterator] = function () {
162
162
  var _a, _b, value, e_1_1, min, max, stepValue, i;
163
163
  var e_1, _c;
164
- return tslib_1.__generator(this, function (_d) {
164
+ return (0, tslib_1.__generator)(this, function (_d) {
165
165
  switch (_d.label) {
166
166
  case 0:
167
167
  if (!this.props.validValues) return [3 /*break*/, 9];
168
168
  _d.label = 1;
169
169
  case 1:
170
170
  _d.trys.push([1, 6, 7, 8]);
171
- _a = tslib_1.__values(this.props.validValues), _b = _a.next();
171
+ _a = (0, tslib_1.__values)(this.props.validValues), _b = _a.next();
172
172
  _d.label = 2;
173
173
  case 2:
174
174
  if (!!_b.done) return [3 /*break*/, 5];
@@ -207,8 +207,8 @@ var ValidValuesIterable = /** @class */ (function () {
207
207
  stepValue = this.props.minStep;
208
208
  }
209
209
  }
210
- else if (request_util_1.isUnsignedNumericFormat(this.props.format)) {
211
- max = request_util_1.numericUpperBound(this.props.format);
210
+ else if ((0, request_util_1.isUnsignedNumericFormat)(this.props.format)) {
211
+ max = (0, request_util_1.numericUpperBound)(this.props.format);
212
212
  }
213
213
  else {
214
214
  throw new Error("Could not find valid iterator strategy for props: " + JSON.stringify(this.props));
@@ -230,6 +230,39 @@ var ValidValuesIterable = /** @class */ (function () {
230
230
  };
231
231
  return ValidValuesIterable;
232
232
  }());
233
+ var numberPattern = /^-?\d+$/;
234
+ function extractHAPStatusFromError(error) {
235
+ var errorValue = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
236
+ if (numberPattern.test(error.message)) {
237
+ var value = parseInt(error.message, 10);
238
+ if ((0, HAPServer_1.IsKnownHAPStatusError)(value)) {
239
+ errorValue = value;
240
+ }
241
+ }
242
+ return errorValue;
243
+ }
244
+ function maxWithUndefined(a, b) {
245
+ if (a === undefined) {
246
+ return b;
247
+ }
248
+ else if (b === undefined) {
249
+ return a;
250
+ }
251
+ else {
252
+ return Math.max(a, b);
253
+ }
254
+ }
255
+ function minWithUndefined(a, b) {
256
+ if (a === undefined) {
257
+ return b;
258
+ }
259
+ else if (b === undefined) {
260
+ return a;
261
+ }
262
+ else {
263
+ return Math.min(a, b);
264
+ }
265
+ }
233
266
  /**
234
267
  * Characteristic represents a particular typed variable that can be assigned to a Service. For instance, a
235
268
  * "Hue" Characteristic might store a 'float' value of type 'arcdegrees'. You could add the Hue Characteristic
@@ -241,7 +274,7 @@ var ValidValuesIterable = /** @class */ (function () {
241
274
  * to any native or custom Services, but Siri will likely not be able to work with these.
242
275
  */
243
276
  var Characteristic = /** @class */ (function (_super) {
244
- tslib_1.__extends(Characteristic, _super);
277
+ (0, tslib_1.__extends)(Characteristic, _super);
245
278
  function Characteristic(displayName, UUID, props) {
246
279
  var _this = _super.call(this) || this;
247
280
  _this.iid = null;
@@ -279,7 +312,7 @@ var Characteristic = /** @class */ (function (_super) {
279
312
  * @param handler
280
313
  */
281
314
  Characteristic.prototype.onGet = function (handler) {
282
- if (typeof handler !== 'function') {
315
+ if (typeof handler !== "function") {
283
316
  this.characteristicWarning(".onGet handler must be a function");
284
317
  return this;
285
318
  }
@@ -308,7 +341,7 @@ var Characteristic = /** @class */ (function (_super) {
308
341
  * @param handler
309
342
  */
310
343
  Characteristic.prototype.onSet = function (handler) {
311
- if (typeof handler !== 'function') {
344
+ if (typeof handler !== "function") {
312
345
  this.characteristicWarning(".onSet handler must be a function");
313
346
  return this;
314
347
  }
@@ -330,14 +363,14 @@ var Characteristic = /** @class */ (function (_super) {
330
363
  * @param props - Partial properties object with the desired updates.
331
364
  */
332
365
  Characteristic.prototype.setProps = function (props) {
333
- assert_1.default(props, "props cannot be undefined when setting props");
366
+ (0, assert_1.default)(props, "props cannot be undefined when setting props");
334
367
  // TODO calling setProps after publish doesn't lead to a increment in the current configuration number
335
368
  // for every value "null" can be used to reset props, except for required props
336
369
  if (props.format) {
337
370
  this.props.format = props.format;
338
371
  }
339
372
  if (props.perms) {
340
- assert_1.default(props.perms.length > 0, "characteristic prop perms cannot be empty array");
373
+ (0, assert_1.default)(props.perms.length > 0, "characteristic prop perms cannot be empty array");
341
374
  this.props.perms = props.perms;
342
375
  }
343
376
  if (props.unit !== undefined) {
@@ -351,24 +384,24 @@ var Characteristic = /** @class */ (function (_super) {
351
384
  if (props.minValue === null) {
352
385
  props.minValue = undefined;
353
386
  }
354
- else if (!request_util_1.isNumericFormat(this.props.format)) {
387
+ else if (!(0, request_util_1.isNumericFormat)(this.props.format)) {
355
388
  this.characteristicWarning("Characteristic Property 'minValue' can only be set for characteristics with numeric format, but not for " + this.props.format, "error-message" /* ERROR_MESSAGE */);
356
389
  props.minValue = undefined;
357
390
  }
358
- else if (typeof props.minValue !== 'number' || !Number.isFinite(props.minValue)) {
359
- this.characteristicWarning("Characteristic Property 'minValue' must be a finite number, received \"" + props.minValue + "\" (" + typeof props.minValue + ")", "error-message" /* ERROR_MESSAGE */);
391
+ else if (typeof props.minValue !== "number" || !Number.isFinite(props.minValue)) {
392
+ this.characteristicWarning("Characteristic Property 'minValue' must be a finite number, received \"".concat(props.minValue, "\" (").concat(typeof props.minValue, ")"), "error-message" /* ERROR_MESSAGE */);
360
393
  props.minValue = undefined;
361
394
  }
362
395
  else {
363
- if (props.minValue < request_util_1.numericLowerBound(this.props.format)) {
396
+ if (props.minValue < (0, request_util_1.numericLowerBound)(this.props.format)) {
364
397
  this.characteristicWarning("Characteristic Property 'minValue' was set to " + props.minValue + ", but for numeric format " +
365
- this.props.format + " minimum possible is " + request_util_1.numericLowerBound(this.props.format), "error-message" /* ERROR_MESSAGE */);
366
- props.minValue = request_util_1.numericLowerBound(this.props.format);
398
+ this.props.format + " minimum possible is " + (0, request_util_1.numericLowerBound)(this.props.format), "error-message" /* ERROR_MESSAGE */);
399
+ props.minValue = (0, request_util_1.numericLowerBound)(this.props.format);
367
400
  }
368
- else if (props.minValue > request_util_1.numericUpperBound(this.props.format)) {
401
+ else if (props.minValue > (0, request_util_1.numericUpperBound)(this.props.format)) {
369
402
  this.characteristicWarning("Characteristic Property 'minValue' was set to " + props.minValue + ", but for numeric format " +
370
- this.props.format + " maximum possible is " + request_util_1.numericUpperBound(this.props.format), "error-message" /* ERROR_MESSAGE */);
371
- props.minValue = request_util_1.numericLowerBound(this.props.format);
403
+ this.props.format + " maximum possible is " + (0, request_util_1.numericUpperBound)(this.props.format), "error-message" /* ERROR_MESSAGE */);
404
+ props.minValue = (0, request_util_1.numericLowerBound)(this.props.format);
372
405
  }
373
406
  }
374
407
  this.props.minValue = props.minValue;
@@ -378,24 +411,24 @@ var Characteristic = /** @class */ (function (_super) {
378
411
  if (props.maxValue === null) {
379
412
  props.maxValue = undefined;
380
413
  }
381
- else if (!request_util_1.isNumericFormat(this.props.format)) {
414
+ else if (!(0, request_util_1.isNumericFormat)(this.props.format)) {
382
415
  this.characteristicWarning("Characteristic Property 'maxValue' can only be set for characteristics with numeric format, but not for " + this.props.format, "error-message" /* ERROR_MESSAGE */);
383
416
  props.maxValue = undefined;
384
417
  }
385
- else if (typeof props.maxValue !== 'number' || !Number.isFinite(props.maxValue)) {
386
- this.characteristicWarning("Characteristic Property 'maxValue' must be a finite number, received \"" + props.maxValue + "\" (" + typeof props.maxValue + ")", "error-message" /* ERROR_MESSAGE */);
418
+ else if (typeof props.maxValue !== "number" || !Number.isFinite(props.maxValue)) {
419
+ this.characteristicWarning("Characteristic Property 'maxValue' must be a finite number, received \"".concat(props.maxValue, "\" (").concat(typeof props.maxValue, ")"), "error-message" /* ERROR_MESSAGE */);
387
420
  props.maxValue = undefined;
388
421
  }
389
422
  else {
390
- if (props.maxValue > request_util_1.numericUpperBound(this.props.format)) {
423
+ if (props.maxValue > (0, request_util_1.numericUpperBound)(this.props.format)) {
391
424
  this.characteristicWarning("Characteristic Property 'maxValue' was set to " + props.maxValue + ", but for numeric format " +
392
- this.props.format + " maximum possible is " + request_util_1.numericUpperBound(this.props.format), "error-message" /* ERROR_MESSAGE */);
393
- props.maxValue = request_util_1.numericUpperBound(this.props.format);
425
+ this.props.format + " maximum possible is " + (0, request_util_1.numericUpperBound)(this.props.format), "error-message" /* ERROR_MESSAGE */);
426
+ props.maxValue = (0, request_util_1.numericUpperBound)(this.props.format);
394
427
  }
395
- else if (props.maxValue < request_util_1.numericLowerBound(this.props.format)) {
428
+ else if (props.maxValue < (0, request_util_1.numericLowerBound)(this.props.format)) {
396
429
  this.characteristicWarning("Characteristic Property 'maxValue' was set to " + props.maxValue + ", but for numeric format " +
397
- this.props.format + " minimum possible is " + request_util_1.numericUpperBound(this.props.format), "error-message" /* ERROR_MESSAGE */);
398
- props.maxValue = request_util_1.numericUpperBound(this.props.format);
430
+ this.props.format + " minimum possible is " + (0, request_util_1.numericUpperBound)(this.props.format), "error-message" /* ERROR_MESSAGE */);
431
+ props.maxValue = (0, request_util_1.numericUpperBound)(this.props.format);
399
432
  }
400
433
  }
401
434
  this.props.maxValue = props.maxValue;
@@ -404,11 +437,11 @@ var Characteristic = /** @class */ (function (_super) {
404
437
  if (props.minStep === null) {
405
438
  this.props.minStep = undefined;
406
439
  }
407
- else if (!request_util_1.isNumericFormat(this.props.format)) {
440
+ else if (!(0, request_util_1.isNumericFormat)(this.props.format)) {
408
441
  this.characteristicWarning("Characteristic Property `minStep` can only be set for characteristics with numeric format, but not for " + this.props.format, "error-message" /* ERROR_MESSAGE */);
409
442
  }
410
443
  else {
411
- if (props.minStep < 1 && request_util_1.isIntegerNumericFormat(this.props.format)) {
444
+ if (props.minStep < 1 && (0, request_util_1.isIntegerNumericFormat)(this.props.format)) {
412
445
  this.characteristicWarning("Characteristic Property `minStep` was set to a value lower than 1, " +
413
446
  "this will have no effect on format `" + this.props.format);
414
447
  }
@@ -445,11 +478,11 @@ var Characteristic = /** @class */ (function (_super) {
445
478
  if (props.validValues === null) {
446
479
  this.props.validValues = undefined;
447
480
  }
448
- else if (!request_util_1.isNumericFormat(this.props.format)) {
481
+ else if (!(0, request_util_1.isNumericFormat)(this.props.format)) {
449
482
  this.characteristicWarning("Characteristic Property `validValues` was supplied for non numeric format " + this.props.format);
450
483
  }
451
484
  else {
452
- assert_1.default(props.validValues.length, "characteristic prop validValues cannot be empty array");
485
+ (0, assert_1.default)(props.validValues.length, "characteristic prop validValues cannot be empty array");
453
486
  this.props.validValues = props.validValues;
454
487
  }
455
488
  }
@@ -457,11 +490,11 @@ var Characteristic = /** @class */ (function (_super) {
457
490
  if (props.validValueRanges === null) {
458
491
  this.props.validValueRanges = undefined;
459
492
  }
460
- else if (!request_util_1.isNumericFormat(this.props.format)) {
493
+ else if (!(0, request_util_1.isNumericFormat)(this.props.format)) {
461
494
  this.characteristicWarning("Characteristic Property `validValueRanges` was supplied for non numeric format " + this.props.format);
462
495
  }
463
496
  else {
464
- assert_1.default(props.validValueRanges.length === 2, "characteristic prop validValueRanges must have a length of 2");
497
+ (0, assert_1.default)(props.validValueRanges.length === 2, "characteristic prop validValueRanges must have a length of 2");
465
498
  this.props.validValueRanges = props.validValueRanges;
466
499
  }
467
500
  }
@@ -629,7 +662,7 @@ var Characteristic = /** @class */ (function (_super) {
629
662
  /**
630
663
  * This method acts similarly to {@link updateValue} by setting the current value of the characteristic
631
664
  * without calling any {@link CharacteristicEventTypes.SET} or {@link onSet} handlers.
632
- * The difference is that this method forces a event notification sent (updateValue only sends one if the value changed).
665
+ * The difference is that this method forces an event notification sent (updateValue only sends one if the value changed).
633
666
  * This is especially useful for characteristics like {@link Characteristic.ButtonEvent} or {@link Characteristic.ProgrammableSwitchEvent}.
634
667
  *
635
668
  * @param value - The new value.
@@ -653,10 +686,10 @@ var Characteristic = /** @class */ (function (_super) {
653
686
  * @private Used by the Accessory to load the characteristic value
654
687
  */
655
688
  Characteristic.prototype.handleGetRequest = function (connection, context) {
656
- return tslib_1.__awaiter(this, void 0, void 0, function () {
689
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
657
690
  var value, oldValue, error_1, hapStatusError;
658
691
  var _this = this;
659
- return tslib_1.__generator(this, function (_a) {
692
+ return (0, tslib_1.__generator)(this, function (_a) {
660
693
  switch (_a.label) {
661
694
  case 0:
662
695
  if (!this.props.perms.includes("pr" /* PAIRED_READ */)) { // check if we are allowed to read from this characteristic
@@ -683,7 +716,7 @@ var Characteristic = /** @class */ (function (_super) {
683
716
  value = this.validateUserInput(value);
684
717
  }
685
718
  catch (error) {
686
- this.characteristicWarning("An illegal value was supplied by the read handler for characteristic: " + (error === null || error === void 0 ? void 0 : error.message), "warn-message" /* WARN_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
719
+ 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" /* WARN_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
687
720
  this.statusCode = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
688
721
  // noinspection JSDeprecatedSymbols
689
722
  this.status = error;
@@ -709,7 +742,7 @@ var Characteristic = /** @class */ (function (_super) {
709
742
  this.status = error_1;
710
743
  }
711
744
  else {
712
- this.characteristicWarning("Unhandled error thrown inside read handler for characteristic: " + (error_1 === null || error_1 === void 0 ? void 0 : error_1.message), "error-message" /* ERROR_MESSAGE */, error_1 === null || error_1 === void 0 ? void 0 : error_1.stack);
745
+ 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" /* ERROR_MESSAGE */, error_1 === null || error_1 === void 0 ? void 0 : error_1.stack);
713
746
  this.statusCode = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
714
747
  // noinspection JSDeprecatedSymbols
715
748
  this.status = error_1;
@@ -724,13 +757,13 @@ var Characteristic = /** @class */ (function (_super) {
724
757
  return [2 /*return*/, this.validateUserInput(this.value)];
725
758
  }
726
759
  catch (error) {
727
- this.characteristicWarning("An illegal value was supplied by setting `value` for characteristic: " + (error === null || error === void 0 ? void 0 : error.message), "warn-message" /* WARN_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
760
+ this.characteristicWarning("An illegal value was supplied by setting `value` for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "warn-message" /* WARN_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
728
761
  return [2 /*return*/, Promise.reject(-70402 /* SERVICE_COMMUNICATION_FAILURE */)];
729
762
  }
730
763
  }
731
764
  return [2 /*return*/, new Promise(function (resolve, reject) {
732
765
  try {
733
- _this.emit("get" /* GET */, once_1.once(function (status, value) {
766
+ _this.emit("get" /* GET */, (0, once_1.once)(function (status, value) {
734
767
  if (status) {
735
768
  if (typeof status === "number") {
736
769
  var hapStatusError = new hapStatusError_1.HapStatusError(status);
@@ -765,7 +798,7 @@ var Characteristic = /** @class */ (function (_super) {
765
798
  }), context, connection);
766
799
  }
767
800
  catch (error) {
768
- _this.characteristicWarning("Unhandled error thrown inside read handler for characteristic: " + (error === null || error === void 0 ? void 0 : error.message), "error-message" /* ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
801
+ _this.characteristicWarning("Unhandled error thrown inside read handler for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "error-message" /* ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
769
802
  _this.statusCode = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
770
803
  // noinspection JSDeprecatedSymbols
771
804
  _this.status = error;
@@ -788,10 +821,10 @@ var Characteristic = /** @class */ (function (_super) {
788
821
  * @private
789
822
  */
790
823
  Characteristic.prototype.handleSetRequest = function (value, connection, context) {
791
- return tslib_1.__awaiter(this, void 0, void 0, function () {
824
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
792
825
  var oldValue, writeResponse, error_2, hapStatusError;
793
826
  var _this = this;
794
- return tslib_1.__generator(this, function (_a) {
827
+ return (0, tslib_1.__generator)(this, function (_a) {
795
828
  switch (_a.label) {
796
829
  case 0:
797
830
  this.statusCode = 0 /* SUCCESS */;
@@ -804,7 +837,7 @@ var Characteristic = /** @class */ (function (_super) {
804
837
  value = this.validateClientSuppliedValue(value);
805
838
  }
806
839
  catch (e) {
807
- debug("[" + this.displayName + "]", e.message);
840
+ debug("[".concat(this.displayName, "]"), e.message);
808
841
  return [2 /*return*/, Promise.reject(-70410 /* INVALID_VALUE_IN_REQUEST */)];
809
842
  }
810
843
  }
@@ -849,7 +882,7 @@ var Characteristic = /** @class */ (function (_super) {
849
882
  this.status = error_2;
850
883
  }
851
884
  else {
852
- this.characteristicWarning("Unhandled error thrown inside write handler for characteristic: " + (error_2 === null || error_2 === void 0 ? void 0 : error_2.message), "error-message" /* ERROR_MESSAGE */, error_2 === null || error_2 === void 0 ? void 0 : error_2.stack);
885
+ 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" /* ERROR_MESSAGE */, error_2 === null || error_2 === void 0 ? void 0 : error_2.stack);
853
886
  this.statusCode = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
854
887
  // noinspection JSDeprecatedSymbols
855
888
  this.status = error_2;
@@ -864,7 +897,7 @@ var Characteristic = /** @class */ (function (_super) {
864
897
  else {
865
898
  return [2 /*return*/, new Promise(function (resolve, reject) {
866
899
  try {
867
- _this.emit("set" /* SET */, value, once_1.once(function (status, writeResponse) {
900
+ _this.emit("set" /* SET */, value, (0, once_1.once)(function (status, writeResponse) {
868
901
  if (status) {
869
902
  if (typeof status === "number") {
870
903
  var hapStatusError = new hapStatusError_1.HapStatusError(status);
@@ -905,7 +938,7 @@ var Characteristic = /** @class */ (function (_super) {
905
938
  }), context, connection);
906
939
  }
907
940
  catch (error) {
908
- _this.characteristicWarning("Unhandled error thrown inside write handler for characteristic: " + (error === null || error === void 0 ? void 0 : error.message), "error-message" /* ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
941
+ _this.characteristicWarning("Unhandled error thrown inside write handler for characteristic: ".concat(error === null || error === void 0 ? void 0 : error.message), "error-message" /* ERROR_MESSAGE */, error === null || error === void 0 ? void 0 : error.stack);
909
942
  _this.statusCode = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
910
943
  // noinspection JSDeprecatedSymbols
911
944
  _this.status = error;
@@ -961,9 +994,9 @@ var Characteristic = /** @class */ (function (_super) {
961
994
  return "";
962
995
  }
963
996
  case "data" /* DATA */:
964
- return null; // who knows!
997
+ return ""; // who knows!
965
998
  case "tlv8" /* TLV8 */:
966
- return null; // who knows!
999
+ return ""; // who knows!
967
1000
  case "dict" /* DICTIONARY */:
968
1001
  return {};
969
1002
  case "array" /* ARRAY */:
@@ -978,10 +1011,10 @@ var Characteristic = /** @class */ (function (_super) {
978
1011
  case Characteristic.CurrentTemperature.UUID:
979
1012
  return 0; // some existing integrations expect this to be 0 by default
980
1013
  default: {
981
- if (((_a = this.props.validValues) === null || _a === void 0 ? void 0 : _a.length) && typeof this.props.validValues[0] === 'number') {
1014
+ if (((_a = this.props.validValues) === null || _a === void 0 ? void 0 : _a.length) && typeof this.props.validValues[0] === "number") {
982
1015
  return this.props.validValues[0];
983
1016
  }
984
- if (typeof this.props.minValue === 'number' && Number.isFinite(this.props.minValue)) {
1017
+ if (typeof this.props.minValue === "number" && Number.isFinite(this.props.minValue)) {
985
1018
  return this.props.minValue;
986
1019
  }
987
1020
  return 0;
@@ -998,18 +1031,18 @@ var Characteristic = /** @class */ (function (_super) {
998
1031
  * @param value - Value supplied by the HomeKit controller
999
1032
  */
1000
1033
  Characteristic.prototype.validateClientSuppliedValue = function (value) {
1001
- if (value == undefined) {
1002
- throw new Error("Client supplied invalid value for " + this.props.format + ": undefined");
1034
+ if (value == null) {
1035
+ throw new Error("Client supplied invalid value for ".concat(this.props.format, ": ").concat(value));
1003
1036
  }
1004
1037
  switch (this.props.format) {
1005
1038
  case "bool" /* BOOL */: {
1006
- if (typeof value === 'boolean') {
1039
+ if (typeof value === "boolean") {
1007
1040
  return value;
1008
1041
  }
1009
- if (typeof value === 'number' && (value === 1 || value === 0)) {
1042
+ if (typeof value === "number" && (value === 1 || value === 0)) {
1010
1043
  return Boolean(value);
1011
1044
  }
1012
- throw new Error("Client supplied invalid type for " + this.props.format + ": \"" + value + "\" (" + typeof value + ")");
1045
+ throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
1013
1046
  }
1014
1047
  case "int" /* INT */:
1015
1048
  case "float" /* FLOAT */:
@@ -1021,53 +1054,53 @@ var Characteristic = /** @class */ (function (_super) {
1021
1054
  value = value ? 1 : 0;
1022
1055
  }
1023
1056
  if (typeof value !== "number" || !Number.isFinite(value)) {
1024
- throw new Error("Client supplied invalid type for " + this.props.format + ": \"" + value + "\" (" + typeof value + ")");
1057
+ throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
1025
1058
  }
1026
- var numericMin = maxWithUndefined(this.props.minValue, request_util_1.numericLowerBound(this.props.format));
1027
- var numericMax = minWithUndefined(this.props.maxValue, request_util_1.numericUpperBound(this.props.format));
1028
- if (typeof numericMin === 'number' && value < numericMin) {
1029
- throw new Error("Client supplied value of " + value + " is less than the minimum allowed value of " + numericMin);
1059
+ var numericMin = maxWithUndefined(this.props.minValue, (0, request_util_1.numericLowerBound)(this.props.format));
1060
+ var numericMax = minWithUndefined(this.props.maxValue, (0, request_util_1.numericUpperBound)(this.props.format));
1061
+ if (typeof numericMin === "number" && value < numericMin) {
1062
+ throw new Error("Client supplied value of ".concat(value, " is less than the minimum allowed value of ").concat(numericMin));
1030
1063
  }
1031
- if (typeof numericMax === 'number' && value > numericMax) {
1032
- throw new Error("Client supplied value of " + value + " is greater than the maximum allowed value of " + numericMax);
1064
+ if (typeof numericMax === "number" && value > numericMax) {
1065
+ throw new Error("Client supplied value of ".concat(value, " is greater than the maximum allowed value of ").concat(numericMax));
1033
1066
  }
1034
1067
  if (this.props.validValues && !this.props.validValues.includes(value)) {
1035
- throw new Error("Client supplied value of " + value + " is not in " + this.props.validValues.toString());
1068
+ throw new Error("Client supplied value of ".concat(value, " is not in ").concat(this.props.validValues.toString()));
1036
1069
  }
1037
1070
  if (this.props.validValueRanges && this.props.validValueRanges.length === 2) {
1038
1071
  if (value < this.props.validValueRanges[0]) {
1039
- throw new Error("Client supplied value of " + value + " is less than the minimum allowed value of " + this.props.validValueRanges[0]);
1072
+ throw new Error("Client supplied value of ".concat(value, " is less than the minimum allowed value of ").concat(this.props.validValueRanges[0]));
1040
1073
  }
1041
1074
  if (value > this.props.validValueRanges[1]) {
1042
- throw new Error("Client supplied value of " + value + " is greater than the maximum allowed value of " + this.props.validValueRanges[1]);
1075
+ throw new Error("Client supplied value of ".concat(value, " is greater than the maximum allowed value of ").concat(this.props.validValueRanges[1]));
1043
1076
  }
1044
1077
  }
1045
1078
  return value;
1046
1079
  }
1047
1080
  case "string" /* STRING */: {
1048
1081
  if (typeof value !== "string") {
1049
- throw new Error("Client supplied invalid type for " + this.props.format + ": \"" + value + "\" (" + typeof value + ")");
1082
+ throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
1050
1083
  }
1051
1084
  var maxLength = this.props.maxLen != null ? this.props.maxLen : 64; // default is 64; max is 256 which is set in setProps
1052
1085
  if (value.length > maxLength) {
1053
- throw new Error("Client supplied value length of " + value.length + " exceeds maximum length allowed of " + maxLength);
1086
+ throw new Error("Client supplied value length of ".concat(value.length, " exceeds maximum length allowed of ").concat(maxLength));
1054
1087
  }
1055
1088
  return value;
1056
1089
  }
1057
1090
  case "data" /* DATA */: {
1058
1091
  if (typeof value !== "string") {
1059
- throw new Error("Client supplied invalid type for " + this.props.format + ": \"" + value + "\" (" + typeof value + ")");
1092
+ throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
1060
1093
  }
1061
1094
  // we don't validate base64 here
1062
1095
  var maxLength = this.props.maxDataLen != null ? this.props.maxDataLen : 0x200000; // default is 0x200000
1063
1096
  if (value.length > maxLength) {
1064
- throw new Error("Client supplied value length of " + value.length + " exceeds maximum length allowed of " + maxLength);
1097
+ throw new Error("Client supplied value length of ".concat(value.length, " exceeds maximum length allowed of ").concat(maxLength));
1065
1098
  }
1066
1099
  return value;
1067
1100
  }
1068
1101
  case "tlv8" /* TLV8 */:
1069
1102
  if (typeof value !== "string") {
1070
- throw new Error("Client supplied invalid type for " + this.props.format + ": \"" + value + "\" (" + typeof value + ")");
1103
+ throw new Error("Client supplied invalid type for ".concat(this.props.format, ": \"").concat(value, "\" (").concat(typeof value, ")"));
1071
1104
  }
1072
1105
  return value;
1073
1106
  }
@@ -1087,8 +1120,8 @@ var Characteristic = /** @class */ (function (_super) {
1087
1120
  this.characteristicWarning("characteristic must have a non null value otherwise HomeKit will reject this accessory, ignoring new value", "error-message" /* ERROR_MESSAGE */);
1088
1121
  return this.value; // don't change the value
1089
1122
  }
1090
- if (this.getDefaultValue() === null) {
1091
- return value; // any format which has default value null, is allowed to have null as a value (e.g. TLV8 or DATA formats)
1123
+ if (this.props.format === "data" /* DATA */ || this.props.format === "tlv8" /* TLV8 */) {
1124
+ return value; // TLV8 and DATA formats are allowed to have null as a value
1092
1125
  }
1093
1126
  /**
1094
1127
  * A short disclaimer here.
@@ -1111,7 +1144,7 @@ var Characteristic = /** @class */ (function (_super) {
1111
1144
  }
1112
1145
  }
1113
1146
  else {
1114
- // we currently allow null for any non custom defined characteristics
1147
+ // we currently allow null for any non-custom defined characteristics
1115
1148
  return value;
1116
1149
  }
1117
1150
  }
@@ -1141,12 +1174,12 @@ var Characteristic = /** @class */ (function (_super) {
1141
1174
  if (typeof value === "string") {
1142
1175
  value = this.props.format === "float" /* FLOAT */ ? parseFloat(value) : parseInt(value, 10);
1143
1176
  }
1144
- if (typeof value !== 'number' || !Number.isFinite(value)) {
1145
- this.characteristicWarning("characteristic value expected valid finite number and received \"" + value + "\" (" + typeof value + ")");
1146
- value = typeof this.value === 'number' ? this.value : this.props.minValue || 0;
1177
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1178
+ this.characteristicWarning("characteristic value expected valid finite number and received \"".concat(value, "\" (").concat(typeof value, ")"));
1179
+ value = typeof this.value === "number" ? this.value : this.props.minValue || 0;
1147
1180
  }
1148
- var numericMin = maxWithUndefined(this.props.minValue, request_util_1.numericLowerBound(this.props.format));
1149
- var numericMax = minWithUndefined(this.props.maxValue, request_util_1.numericUpperBound(this.props.format));
1181
+ var numericMin = maxWithUndefined(this.props.minValue, (0, request_util_1.numericLowerBound)(this.props.format));
1182
+ var numericMax = minWithUndefined(this.props.maxValue, (0, request_util_1.numericUpperBound)(this.props.format));
1150
1183
  var stepValue = undefined;
1151
1184
  if (this.props.format === "float" /* FLOAT */) {
1152
1185
  stepValue = this.props.minStep;
@@ -1155,28 +1188,28 @@ var Characteristic = /** @class */ (function (_super) {
1155
1188
  stepValue = maxWithUndefined(this.props.minStep, 1);
1156
1189
  }
1157
1190
  if (numericMin != null && value < numericMin) {
1158
- this.characteristicWarning("characteristic was supplied illegal value: number " + value + " exceeded minimum of " + numericMin);
1191
+ this.characteristicWarning("characteristic was supplied illegal value: number ".concat(value, " exceeded minimum of ").concat(numericMin));
1159
1192
  value = numericMin;
1160
1193
  }
1161
1194
  if (numericMax != null && value > numericMax) {
1162
- this.characteristicWarning("characteristic was supplied illegal value: number " + value + " exceeded maximum of " + numericMax);
1195
+ this.characteristicWarning("characteristic was supplied illegal value: number ".concat(value, " exceeded maximum of ").concat(numericMax));
1163
1196
  value = numericMax;
1164
1197
  }
1165
1198
  if (this.props.validValues && !this.props.validValues.includes(value)) {
1166
- this.characteristicWarning("characteristic value " + value + " is not contained in valid values array");
1199
+ this.characteristicWarning("characteristic value ".concat(value, " is not contained in valid values array"));
1167
1200
  return this.props.validValues.includes(this.value) ? this.value : (this.props.validValues[0] || 0);
1168
1201
  }
1169
1202
  if (this.props.validValueRanges && this.props.validValueRanges.length === 2) {
1170
1203
  if (value < this.props.validValueRanges[0]) {
1171
- this.characteristicWarning("characteristic was supplied illegal value: number " + value + " not contained in valid value range of " + this.props.validValueRanges + ", supplying illegal values will throw errors in the future");
1204
+ 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"));
1172
1205
  value = this.props.validValueRanges[0];
1173
1206
  }
1174
1207
  else if (value > this.props.validValueRanges[1]) {
1175
- this.characteristicWarning("characteristic was supplied illegal value: number " + value + " not contained in valid value range of " + this.props.validValueRanges + ", supplying illegal values will throw errors in the future");
1208
+ 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"));
1176
1209
  value = this.props.validValueRanges[1];
1177
1210
  }
1178
1211
  }
1179
- if (stepValue != undefined) {
1212
+ if (stepValue != null) {
1180
1213
  if (stepValue === 1) {
1181
1214
  value = Math.round(value);
1182
1215
  }
@@ -1189,20 +1222,22 @@ var Characteristic = /** @class */ (function (_super) {
1189
1222
  }
1190
1223
  case "string" /* STRING */: {
1191
1224
  if (typeof value === "number") {
1192
- this.characteristicWarning("characteristic was supplied illegal value: number instead of string, supplying illegal values will throw errors in the future");
1225
+ this.characteristicWarning("characteristic was supplied illegal value: number instead of string, " +
1226
+ "supplying illegal values will throw errors in the future");
1193
1227
  value = String(value);
1194
1228
  }
1195
1229
  if (typeof value !== "string") {
1196
1230
  this.characteristicWarning("characteristic value expected string and received " + (typeof value));
1197
- value = typeof this.value === 'string' ? this.value : value + '';
1231
+ value = typeof this.value === "string" ? this.value : value + "";
1198
1232
  }
1199
- if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) { // mirrors the case value = null at the beginning
1200
- this.characteristicWarning("[" + this.displayName + "] characteristic must have a length of more than 1 character otherwise HomeKit will reject this accessory, ignoring new value");
1233
+ // mirrors the case value = null at the beginning
1234
+ if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) {
1235
+ this.characteristicWarning("[".concat(this.displayName, "] characteristic must have a length of more than 1 character otherwise HomeKit will reject this accessory, ignoring new value"));
1201
1236
  return this.value; // just return the current value
1202
1237
  }
1203
1238
  var maxLength = (_a = this.props.maxLen) !== null && _a !== void 0 ? _a : 64; // default is 64 (max is 256 which is set in setProps)
1204
1239
  if (value.length > maxLength) {
1205
- this.characteristicWarning("characteristic was supplied illegal value: string '" + value + "' exceeded max length of " + maxLength);
1240
+ this.characteristicWarning("characteristic was supplied illegal value: string '".concat(value, "' exceeded max length of ").concat(maxLength));
1206
1241
  value = value.substring(0, maxLength);
1207
1242
  }
1208
1243
  return value;
@@ -1263,9 +1298,9 @@ var Characteristic = /** @class */ (function (_super) {
1263
1298
  this.updateValue(characteristic.value);
1264
1299
  var getListeners = characteristic.listeners("get" /* GET */);
1265
1300
  if (getListeners.length) {
1266
- // the callback can only be called once so we remove all old listeners
1301
+ // the callback can only be called once, so we remove all old listeners
1267
1302
  this.removeAllListeners("get" /* GET */);
1268
- // @ts-expect-error
1303
+ // @ts-expect-error: force type
1269
1304
  getListeners.forEach(function (listener) { return _this.addListener("get" /* GET */, listener); });
1270
1305
  }
1271
1306
  this.removeOnGet();
@@ -1274,9 +1309,9 @@ var Characteristic = /** @class */ (function (_super) {
1274
1309
  }
1275
1310
  var setListeners = characteristic.listeners("set" /* SET */);
1276
1311
  if (setListeners.length) {
1277
- // the callback can only be called once so we remove all old listeners
1312
+ // the callback can only be called once, so we remove all old listeners
1278
1313
  this.removeAllListeners("set" /* SET */);
1279
- // @ts-expect-error
1314
+ // @ts-expect-error: force type
1280
1315
  setListeners.forEach(function (listener) { return _this.addListener("set" /* SET */, listener); });
1281
1316
  }
1282
1317
  this.removeOnSet();
@@ -1290,10 +1325,10 @@ var Characteristic = /** @class */ (function (_super) {
1290
1325
  */
1291
1326
  Characteristic.prototype.toHAP = function (connection, contactGetHandlers) {
1292
1327
  if (contactGetHandlers === void 0) { contactGetHandlers = true; }
1293
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1328
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
1294
1329
  var object, value, _a;
1295
1330
  var _this = this;
1296
- return tslib_1.__generator(this, function (_b) {
1331
+ return (0, tslib_1.__generator)(this, function (_b) {
1297
1332
  switch (_b.label) {
1298
1333
  case 0:
1299
1334
  object = this.internalHAPRepresentation();
@@ -1308,8 +1343,9 @@ var Characteristic = /** @class */ (function (_super) {
1308
1343
  case 2:
1309
1344
  if (!contactGetHandlers) return [3 /*break*/, 4];
1310
1345
  return [4 /*yield*/, this.handleGetRequest(connection).catch(function () {
1311
- debug('[%s] Error getting value for characteristic on /accessories request. Returning cached value instead: %s', _this.displayName, "" + _this.value);
1312
- return _this.value; // use cached value
1346
+ var value = _this.getDefaultValue();
1347
+ debug("[%s] Error getting value for characteristic on /accessories request. Returning default value instead: %s", _this.displayName, "".concat(value));
1348
+ return value; // use default value
1313
1349
  })];
1314
1350
  case 3:
1315
1351
  _a = _b.sent();
@@ -1319,7 +1355,7 @@ var Characteristic = /** @class */ (function (_super) {
1319
1355
  _b.label = 5;
1320
1356
  case 5:
1321
1357
  value = _a;
1322
- object.value = request_util_1.formatOutgoingCharacteristicValue(value, this.props);
1358
+ object.value = (0, request_util_1.formatOutgoingCharacteristicValue)(value, this.props);
1323
1359
  _b.label = 6;
1324
1360
  case 6: return [2 /*return*/, object];
1325
1361
  }
@@ -1331,10 +1367,10 @@ var Characteristic = /** @class */ (function (_super) {
1331
1367
  * @private used to generate the config hash
1332
1368
  */
1333
1369
  Characteristic.prototype.internalHAPRepresentation = function () {
1334
- assert_1.default(this.iid, "iid cannot be undefined for characteristic '" + this.displayName + "'");
1370
+ (0, assert_1.default)(this.iid, "iid cannot be undefined for characteristic '" + this.displayName + "'");
1335
1371
  // TODO include the value for characteristics of the AccessoryInformation service
1336
1372
  return {
1337
- type: uuid_1.toShortForm(this.UUID),
1373
+ type: (0, uuid_1.toShortForm)(this.UUID),
1338
1374
  iid: this.iid,
1339
1375
  value: null,
1340
1376
  perms: this.props.perms,
@@ -1367,7 +1403,7 @@ var Characteristic = /** @class */ (function (_super) {
1367
1403
  eventOnlyCharacteristic: characteristic.UUID === Characteristic.ProgrammableSwitchEvent.UUID,
1368
1404
  constructorName: constructorName,
1369
1405
  value: characteristic.value,
1370
- props: clone_1.clone({}, characteristic.props),
1406
+ props: (0, clone_1.clone)({}, characteristic.props),
1371
1407
  };
1372
1408
  };
1373
1409
  /**
@@ -1392,54 +1428,21 @@ var Characteristic = /** @class */ (function (_super) {
1392
1428
  return characteristic;
1393
1429
  };
1394
1430
  /**
1395
- * @deprecated Please use the Formats const enum above. Scheduled to be removed in 2021-06.
1431
+ * @deprecated Please use the Formats const enum above.
1396
1432
  */
1397
- // @ts-expect-error
1433
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1398
1434
  Characteristic.Formats = Formats;
1399
1435
  /**
1400
- * @deprecated Please use the Units const enum above. Scheduled to be removed in 2021-06.
1436
+ * @deprecated Please use the Units const enum above.
1401
1437
  */
1402
- // @ts-expect-error
1438
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1403
1439
  Characteristic.Units = Units;
1404
1440
  /**
1405
- * @deprecated Please use the Perms const enum above. Scheduled to be removed in 2021-06.
1441
+ * @deprecated Please use the Perms const enum above.
1406
1442
  */
1407
- // @ts-expect-error
1443
+ // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1408
1444
  Characteristic.Perms = Perms;
1409
1445
  return Characteristic;
1410
1446
  }(events_1.EventEmitter));
1411
1447
  exports.Characteristic = Characteristic;
1412
- var numberPattern = /^-?\d+$/;
1413
- function extractHAPStatusFromError(error) {
1414
- var errorValue = -70402 /* SERVICE_COMMUNICATION_FAILURE */;
1415
- if (numberPattern.test(error.message)) {
1416
- var value = parseInt(error.message, 10);
1417
- if (HAPServer_1.IsKnownHAPStatusError(value)) {
1418
- errorValue = value;
1419
- }
1420
- }
1421
- return errorValue;
1422
- }
1423
- function maxWithUndefined(a, b) {
1424
- if (a === undefined) {
1425
- return b;
1426
- }
1427
- else if (b === undefined) {
1428
- return a;
1429
- }
1430
- else {
1431
- return Math.max(a, b);
1432
- }
1433
- }
1434
- function minWithUndefined(a, b) {
1435
- if (a === undefined) {
1436
- return b;
1437
- }
1438
- else if (b === undefined) {
1439
- return a;
1440
- }
1441
- else {
1442
- return Math.min(a, b);
1443
- }
1444
- }
1445
1448
  //# sourceMappingURL=Characteristic.js.map