@homebridge/hap-nodejs 2.3.1-beta.1 → 2.3.1-beta.3

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 (252) hide show
  1. package/README.md +13 -4
  2. package/dist/accessories/types.d.ts +0 -1
  3. package/dist/hap.d.ts +1 -1
  4. package/dist/hap.js +6 -4
  5. package/dist/hap.js.map +1 -1
  6. package/dist/index.d.ts +4 -1
  7. package/dist/index.js +4 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal-types.d.ts +6 -7
  10. package/dist/internal-types.js +1 -5
  11. package/dist/internal-types.js.map +1 -1
  12. package/dist/lib/Accessory.d.ts +53 -25
  13. package/dist/lib/Accessory.js +289 -171
  14. package/dist/lib/Accessory.js.map +1 -1
  15. package/dist/lib/Advertiser.d.ts +37 -18
  16. package/dist/lib/Advertiser.js +143 -62
  17. package/dist/lib/Advertiser.js.map +1 -1
  18. package/dist/lib/Bridge.d.ts +1 -2
  19. package/dist/lib/Bridge.js +1 -1
  20. package/dist/lib/Characteristic.d.ts +19 -20
  21. package/dist/lib/Characteristic.js +187 -153
  22. package/dist/lib/Characteristic.js.map +1 -1
  23. package/dist/lib/HAPServer.d.ts +19 -13
  24. package/dist/lib/HAPServer.js +266 -220
  25. package/dist/lib/HAPServer.js.map +1 -1
  26. package/dist/lib/Service.d.ts +11 -11
  27. package/dist/lib/Service.js +54 -37
  28. package/dist/lib/Service.js.map +1 -1
  29. package/dist/lib/camera/RTPProxy.d.ts +5 -5
  30. package/dist/lib/camera/RTPProxy.js +48 -23
  31. package/dist/lib/camera/RTPProxy.js.map +1 -1
  32. package/dist/lib/camera/RTPStreamManagement.d.ts +18 -13
  33. package/dist/lib/camera/RTPStreamManagement.js +247 -216
  34. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  35. package/dist/lib/camera/RecordingManagement.d.ts +13 -13
  36. package/dist/lib/camera/RecordingManagement.js +115 -110
  37. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  38. package/dist/lib/camera/index.d.ts +0 -1
  39. package/dist/lib/controller/AdaptiveLightingController.d.ts +41 -36
  40. package/dist/lib/controller/AdaptiveLightingController.js +126 -113
  41. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  42. package/dist/lib/controller/CameraController.d.ts +17 -17
  43. package/dist/lib/controller/CameraController.js +30 -26
  44. package/dist/lib/controller/CameraController.js.map +1 -1
  45. package/dist/lib/controller/Controller.d.ts +15 -12
  46. package/dist/lib/controller/Controller.js +0 -1
  47. package/dist/lib/controller/Controller.js.map +1 -1
  48. package/dist/lib/controller/DoorbellController.d.ts +6 -6
  49. package/dist/lib/controller/DoorbellController.js +10 -3
  50. package/dist/lib/controller/DoorbellController.js.map +1 -1
  51. package/dist/lib/controller/RemoteController.d.ts +46 -27
  52. package/dist/lib/controller/RemoteController.js +268 -178
  53. package/dist/lib/controller/RemoteController.js.map +1 -1
  54. package/dist/lib/controller/index.d.ts +0 -1
  55. package/dist/lib/datastream/DataStreamManagement.d.ts +6 -6
  56. package/dist/lib/datastream/DataStreamManagement.js +30 -26
  57. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  58. package/dist/lib/datastream/DataStreamParser.d.ts +25 -8
  59. package/dist/lib/datastream/DataStreamParser.js +124 -105
  60. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  61. package/dist/lib/datastream/DataStreamServer.d.ts +47 -23
  62. package/dist/lib/datastream/DataStreamServer.js +285 -143
  63. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  64. package/dist/lib/datastream/index.d.ts +0 -1
  65. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +0 -1
  66. package/dist/lib/definitions/CharacteristicDefinitions.js +578 -578
  67. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  68. package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -1
  69. package/dist/lib/definitions/index.d.ts +0 -1
  70. package/dist/lib/gen/HomeKit.d.ts +0 -1
  71. package/dist/lib/model/AccessoryInfo.d.ts +5 -6
  72. package/dist/lib/model/AccessoryInfo.js +23 -19
  73. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  74. package/dist/lib/model/ControllerStorage.d.ts +11 -5
  75. package/dist/lib/model/ControllerStorage.js +34 -8
  76. package/dist/lib/model/ControllerStorage.js.map +1 -1
  77. package/dist/lib/model/HAPFileStorage.d.ts +20 -2
  78. package/dist/lib/model/HAPFileStorage.js +59 -10
  79. package/dist/lib/model/HAPFileStorage.js.map +1 -1
  80. package/dist/lib/model/HAPStorage.d.ts +0 -1
  81. package/dist/lib/model/HAPStorage.js +6 -3
  82. package/dist/lib/model/HAPStorage.js.map +1 -1
  83. package/dist/lib/model/IdentifierCache.d.ts +2 -3
  84. package/dist/lib/model/IdentifierCache.js +26 -13
  85. package/dist/lib/model/IdentifierCache.js.map +1 -1
  86. package/dist/lib/tv/AccessControlManagement.d.ts +6 -7
  87. package/dist/lib/tv/AccessControlManagement.js +13 -19
  88. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  89. package/dist/lib/util/checkName.d.ts +1 -2
  90. package/dist/lib/util/checkName.js.map +1 -1
  91. package/dist/lib/util/clone.d.ts +0 -1
  92. package/dist/lib/util/clone.js.map +1 -1
  93. package/dist/lib/util/color-utils.d.ts +1 -2
  94. package/dist/lib/util/color-utils.js +1 -1
  95. package/dist/lib/util/errors.d.ts +4 -0
  96. package/dist/lib/util/errors.js +15 -0
  97. package/dist/lib/util/errors.js.map +1 -0
  98. package/dist/lib/util/eventedhttp.d.ts +63 -19
  99. package/dist/lib/util/eventedhttp.js +170 -48
  100. package/dist/lib/util/eventedhttp.js.map +1 -1
  101. package/dist/lib/util/hapCrypto.d.ts +1 -2
  102. package/dist/lib/util/hapCrypto.js +6 -7
  103. package/dist/lib/util/hapCrypto.js.map +1 -1
  104. package/dist/lib/util/hapStatusError.d.ts +0 -1
  105. package/dist/lib/util/hapStatusError.js +1 -1
  106. package/dist/lib/util/hapStatusError.js.map +1 -1
  107. package/dist/lib/util/net-utils.d.ts +1 -2
  108. package/dist/lib/util/net-utils.js +6 -7
  109. package/dist/lib/util/net-utils.js.map +1 -1
  110. package/dist/lib/util/once.d.ts +0 -1
  111. package/dist/lib/util/promise-utils.d.ts +1 -2
  112. package/dist/lib/util/promise-utils.js +2 -1
  113. package/dist/lib/util/promise-utils.js.map +1 -1
  114. package/dist/lib/util/request-util.d.ts +4 -4
  115. package/dist/lib/util/request-util.js +29 -28
  116. package/dist/lib/util/request-util.js.map +1 -1
  117. package/dist/lib/util/time.d.ts +1 -2
  118. package/dist/lib/util/time.js.map +1 -1
  119. package/dist/lib/util/tlv.d.ts +4 -4
  120. package/dist/lib/util/tlv.js +16 -5
  121. package/dist/lib/util/tlv.js.map +1 -1
  122. package/dist/lib/util/uuid.d.ts +5 -2
  123. package/dist/lib/util/uuid.js +6 -0
  124. package/dist/lib/util/uuid.js.map +1 -1
  125. package/dist/types.d.ts +20 -17
  126. package/dist/types.js +0 -1
  127. package/dist/types.js.map +1 -1
  128. package/package.json +8 -14
  129. package/dist/accessories/AirConditioner_accessory.d.ts +0 -2
  130. package/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
  131. package/dist/accessories/AirConditioner_accessory.js +0 -126
  132. package/dist/accessories/AirConditioner_accessory.js.map +0 -1
  133. package/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
  134. package/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
  135. package/dist/accessories/AppleTVRemote_accessory.js +0 -146
  136. package/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
  137. package/dist/accessories/Camera_accessory.d.ts +0 -2
  138. package/dist/accessories/Camera_accessory.d.ts.map +0 -1
  139. package/dist/accessories/Camera_accessory.js +0 -562
  140. package/dist/accessories/Camera_accessory.js.map +0 -1
  141. package/dist/accessories/Fan_accessory.d.ts +0 -2
  142. package/dist/accessories/Fan_accessory.d.ts.map +0 -1
  143. package/dist/accessories/Fan_accessory.js +0 -71
  144. package/dist/accessories/Fan_accessory.js.map +0 -1
  145. package/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
  146. package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
  147. package/dist/accessories/GarageDoorOpener_accessory.js +0 -76
  148. package/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
  149. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
  150. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
  151. package/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -103
  152. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
  153. package/dist/accessories/Light_accessory.d.ts +0 -2
  154. package/dist/accessories/Light_accessory.d.ts.map +0 -1
  155. package/dist/accessories/Light_accessory.js +0 -143
  156. package/dist/accessories/Light_accessory.js.map +0 -1
  157. package/dist/accessories/Lock_accessory.d.ts +0 -2
  158. package/dist/accessories/Lock_accessory.d.ts.map +0 -1
  159. package/dist/accessories/Lock_accessory.js +0 -74
  160. package/dist/accessories/Lock_accessory.js.map +0 -1
  161. package/dist/accessories/MotionSensor_accessory.d.ts +0 -2
  162. package/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
  163. package/dist/accessories/MotionSensor_accessory.js +0 -43
  164. package/dist/accessories/MotionSensor_accessory.js.map +0 -1
  165. package/dist/accessories/Outlet_accessory.d.ts +0 -2
  166. package/dist/accessories/Outlet_accessory.d.ts.map +0 -1
  167. package/dist/accessories/Outlet_accessory.js +0 -77
  168. package/dist/accessories/Outlet_accessory.js.map +0 -1
  169. package/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
  170. package/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
  171. package/dist/accessories/SmartSpeaker_accessory.js +0 -42
  172. package/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
  173. package/dist/accessories/Sprinkler_accessory.d.ts +0 -2
  174. package/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
  175. package/dist/accessories/Sprinkler_accessory.js +0 -126
  176. package/dist/accessories/Sprinkler_accessory.js.map +0 -1
  177. package/dist/accessories/TV_accessory.d.ts +0 -2
  178. package/dist/accessories/TV_accessory.d.ts.map +0 -1
  179. package/dist/accessories/TV_accessory.js +0 -99
  180. package/dist/accessories/TV_accessory.js.map +0 -1
  181. package/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
  182. package/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
  183. package/dist/accessories/TemperatureSensor_accessory.js +0 -42
  184. package/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
  185. package/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
  186. package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
  187. package/dist/accessories/Wi-FiRouter_accessory.js +0 -14
  188. package/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
  189. package/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
  190. package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
  191. package/dist/accessories/Wi-FiSatellite_accessory.js +0 -16
  192. package/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
  193. package/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
  194. package/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
  195. package/dist/accessories/gstreamer-audioProducer.js +0 -145
  196. package/dist/accessories/gstreamer-audioProducer.js.map +0 -1
  197. package/dist/accessories/types.d.ts.map +0 -1
  198. package/dist/hap.d.ts.map +0 -1
  199. package/dist/index.d.ts.map +0 -1
  200. package/dist/internal-types.d.ts.map +0 -1
  201. package/dist/lib/Accessory.d.ts.map +0 -1
  202. package/dist/lib/Advertiser.d.ts.map +0 -1
  203. package/dist/lib/Bridge.d.ts.map +0 -1
  204. package/dist/lib/Characteristic.d.ts.map +0 -1
  205. package/dist/lib/HAPServer.d.ts.map +0 -1
  206. package/dist/lib/Service.d.ts.map +0 -1
  207. package/dist/lib/camera/RTPProxy.d.ts.map +0 -1
  208. package/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
  209. package/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
  210. package/dist/lib/camera/index.d.ts.map +0 -1
  211. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
  212. package/dist/lib/controller/CameraController.d.ts.map +0 -1
  213. package/dist/lib/controller/Controller.d.ts.map +0 -1
  214. package/dist/lib/controller/DoorbellController.d.ts.map +0 -1
  215. package/dist/lib/controller/RemoteController.d.ts.map +0 -1
  216. package/dist/lib/controller/index.d.ts.map +0 -1
  217. package/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
  218. package/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
  219. package/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
  220. package/dist/lib/datastream/index.d.ts.map +0 -1
  221. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
  222. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
  223. package/dist/lib/definitions/generate-definitions.d.ts +0 -34
  224. package/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
  225. package/dist/lib/definitions/generate-definitions.js +0 -624
  226. package/dist/lib/definitions/generate-definitions.js.map +0 -1
  227. package/dist/lib/definitions/generator-configuration.d.ts +0 -22
  228. package/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
  229. package/dist/lib/definitions/generator-configuration.js +0 -674
  230. package/dist/lib/definitions/generator-configuration.js.map +0 -1
  231. package/dist/lib/definitions/index.d.ts.map +0 -1
  232. package/dist/lib/gen/HomeKit.d.ts.map +0 -1
  233. package/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
  234. package/dist/lib/model/ControllerStorage.d.ts.map +0 -1
  235. package/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
  236. package/dist/lib/model/HAPStorage.d.ts.map +0 -1
  237. package/dist/lib/model/IdentifierCache.d.ts.map +0 -1
  238. package/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
  239. package/dist/lib/util/checkName.d.ts.map +0 -1
  240. package/dist/lib/util/clone.d.ts.map +0 -1
  241. package/dist/lib/util/color-utils.d.ts.map +0 -1
  242. package/dist/lib/util/eventedhttp.d.ts.map +0 -1
  243. package/dist/lib/util/hapCrypto.d.ts.map +0 -1
  244. package/dist/lib/util/hapStatusError.d.ts.map +0 -1
  245. package/dist/lib/util/net-utils.d.ts.map +0 -1
  246. package/dist/lib/util/once.d.ts.map +0 -1
  247. package/dist/lib/util/promise-utils.d.ts.map +0 -1
  248. package/dist/lib/util/request-util.d.ts.map +0 -1
  249. package/dist/lib/util/time.d.ts.map +0 -1
  250. package/dist/lib/util/tlv.d.ts.map +0 -1
  251. package/dist/lib/util/uuid.d.ts.map +0 -1
  252. package/dist/types.d.ts.map +0 -1
@@ -2,8 +2,10 @@ import assert from 'node:assert';
2
2
  import { EventEmitter } from 'node:events';
3
3
  import { inspect } from 'node:util';
4
4
  import createDebug from 'debug';
5
+ import { CharacteristicWarningType } from './Accessory.js';
5
6
  import { HAPStatus } from './HAPServer.js';
6
7
  import { clone } from './util/clone.js';
8
+ import { errorMessage, errorStack } from './util/errors.js';
7
9
  import { HapStatusError } from './util/hapStatusError.js';
8
10
  import { once } from './util/once.js';
9
11
  import { extractHAPStatusFromError, formatOutgoingCharacteristicValue, isIntegerNumericFormat, isNumericFormat, isUnsignedNumericFormat, numericLowerBound, numericUpperBound, } from './util/request-util.js';
@@ -12,7 +14,6 @@ const debug = createDebug('HAP-NodeJS:Characteristic');
12
14
  /**
13
15
  * @group Characteristic
14
16
  */
15
- // eslint-disable-next-line no-restricted-syntax
16
17
  export var Formats;
17
18
  (function (Formats) {
18
19
  Formats["BOOL"] = "bool";
@@ -56,7 +57,6 @@ export var Formats;
56
57
  /**
57
58
  * @group Characteristic
58
59
  */
59
- // eslint-disable-next-line no-restricted-syntax
60
60
  export var Units;
61
61
  (function (Units) {
62
62
  /**
@@ -73,7 +73,6 @@ export var Units;
73
73
  /**
74
74
  * @group Characteristic
75
75
  */
76
- // eslint-disable-next-line no-restricted-syntax
77
76
  export var Perms;
78
77
  (function (Perms) {
79
78
  Perms["PAIRED_READ"] = "pr";
@@ -87,18 +86,17 @@ export var Perms;
87
86
  Perms["WRITE_RESPONSE"] = "wr";
88
87
  })(Perms || (Perms = {}));
89
88
  /**
90
- * The wire values of {@link Perms}, as a runtime lookup. A const enum is erased during compilation and cannot be enumerated, so this set is the enum's
91
- * runtime mirror and lives beside it: a permission added to the enum above must be added here as well. The members are referenced rather than retyped,
92
- * so the compiler inlines the same string literals the enum declares. `EVENTS` is an alias of `NOTIFY` and shares its value, hence is not listed.
89
+ * The wire values of {@link Perms}, as a runtime lookup. It lives beside the enum: a permission added to the enum above must be added here as well.
90
+ * `EVENTS` is an alias of `NOTIFY` and shares its value, hence is not listed.
93
91
  */
94
92
  const VALID_PERMS = new Set([
95
- "pr" /* Perms.PAIRED_READ */,
96
- "pw" /* Perms.PAIRED_WRITE */,
97
- "ev" /* Perms.NOTIFY */,
98
- "aa" /* Perms.ADDITIONAL_AUTHORIZATION */,
99
- "tw" /* Perms.TIMED_WRITE */,
100
- "hd" /* Perms.HIDDEN */,
101
- "wr" /* Perms.WRITE_RESPONSE */,
93
+ Perms.PAIRED_READ,
94
+ Perms.PAIRED_WRITE,
95
+ Perms.NOTIFY,
96
+ Perms.ADDITIONAL_AUTHORIZATION,
97
+ Perms.TIMED_WRITE,
98
+ Perms.HIDDEN,
99
+ Perms.WRITE_RESPONSE,
102
100
  ]);
103
101
  /**
104
102
  * Checks that a value is a well-formed permissions array: a non-empty array in which every entry is one of the {@link Perms} wire values.
@@ -150,7 +148,6 @@ export function describePerms(perms) {
150
148
  *
151
149
  * @group Characteristic
152
150
  */
153
- // eslint-disable-next-line no-restricted-syntax
154
151
  export var Access;
155
152
  (function (Access) {
156
153
  Access[Access["READ"] = 0] = "READ";
@@ -160,7 +157,6 @@ export var Access;
160
157
  /**
161
158
  * @group Characteristic
162
159
  */
163
- // eslint-disable-next-line no-restricted-syntax
164
160
  export var ChangeReason;
165
161
  (function (ChangeReason) {
166
162
  /**
@@ -183,7 +179,6 @@ export var ChangeReason;
183
179
  /**
184
180
  * @group Characteristic
185
181
  */
186
- // eslint-disable-next-line no-restricted-syntax
187
182
  export var CharacteristicEventTypes;
188
183
  (function (CharacteristicEventTypes) {
189
184
  /**
@@ -259,8 +254,14 @@ class ValidValuesIterable {
259
254
  else {
260
255
  throw new Error(`Could not find valid iterator strategy for props: ${JSON.stringify(this.props)}`);
261
256
  }
262
- for (let i = min; i <= max; i += stepValue) {
263
- yield i;
257
+ if (!(stepValue > 0)) {
258
+ stepValue = 1; // a step of zero or less would never reach the maximum
259
+ }
260
+ // Counted in whole steps, and rounded: adding 0.1 again and again drifts (0.30000000000000004, ...)
261
+ // and ends at 0.9999999999999999, one step short of a maximum of 1.
262
+ const steps = Math.floor(Number.parseFloat(((max - min) / stepValue).toFixed(9)));
263
+ for (let i = 0; i <= steps; i++) {
264
+ yield Number.parseFloat((min + i * stepValue).toFixed(9));
264
265
  }
265
266
  }
266
267
  }
@@ -291,7 +292,7 @@ function minWithUndefined(a, b) {
291
292
  * Characteristic represents a particular typed variable that can be assigned to a Service. For instance, a
292
293
  * "Hue" Characteristic might store a 'float' value of type 'arcdegrees'. You could add the Hue Characteristic
293
294
  * to a {@link Service} in order to store that value. A particular Characteristic is distinguished from others by its
294
- * UUID. HomeKit provides a set of known Characteristic UUIDs defined in HomeKit.ts along with a
295
+ * UUID. HomeKit provides a set of known Characteristic UUIDs defined in CharacteristicDefinitions.ts along with a
295
296
  * corresponding concrete subclass.
296
297
  *
297
298
  * You can also define custom Characteristics by providing your own UUID. Custom Characteristics can be added
@@ -299,7 +300,6 @@ function minWithUndefined(a, b) {
299
300
  *
300
301
  * @group Characteristic
301
302
  */
302
- // eslint-disable-next-line ts/no-unsafe-declaration-merging
303
303
  export class Characteristic extends EventEmitter {
304
304
  // Pattern below is for automatic detection of the section of defined characteristics. Used by the generator
305
305
  // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -1373,8 +1373,8 @@ export class Characteristic extends EventEmitter {
1373
1373
  this.displayName = displayName;
1374
1374
  this.UUID = UUID;
1375
1375
  this.props = {
1376
- format: "int" /* Formats.INT */,
1377
- perms: ["ev" /* Perms.NOTIFY */],
1376
+ format: Formats.INT,
1377
+ perms: [Perms.NOTIFY],
1378
1378
  };
1379
1379
  this.setProps(props || {}); // ensure sanity checks are called
1380
1380
  }
@@ -1444,6 +1444,7 @@ export class Characteristic extends EventEmitter {
1444
1444
  */
1445
1445
  setProps(props) {
1446
1446
  assert(props, 'props cannot be undefined when setting props');
1447
+ props = { ...props }; // values are corrected below, and that must not change the object of the caller
1447
1448
  let formatDidChange = false;
1448
1449
  // for every value "null" can be used to reset props, except for required props
1449
1450
  if (props.format) {
@@ -1457,7 +1458,7 @@ export class Characteristic extends EventEmitter {
1457
1458
  */
1458
1459
  if (props.perms) {
1459
1460
  if (!isValidPerms(props.perms)) {
1460
- this.characteristicWarning(`characteristic contains invalid permissions: ${describePerms(props.perms)}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, undefined, true);
1461
+ this.characteristicWarning(`characteristic contains invalid permissions: ${describePerms(props.perms)}`, CharacteristicWarningType.ERROR_MESSAGE, undefined, true);
1461
1462
  }
1462
1463
  /* Everything downstream treats `props.perms` as an array. A non-array is the dangerous shape rather than merely an invalid one: on a string
1463
1464
  * `includes` substring-matches, so a declared `"pr"` would answer true to a paired-read check and quietly grant access, and `push` would throw
@@ -1480,20 +1481,20 @@ export class Characteristic extends EventEmitter {
1480
1481
  props.minValue = undefined;
1481
1482
  }
1482
1483
  else if (!isNumericFormat(this.props.format)) {
1483
- this.characteristicWarning(`Characteristic Property 'minValue' can only be set for characteristics with numeric format, but not for ${this.props.format}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1484
+ this.characteristicWarning(`Characteristic Property 'minValue' can only be set for characteristics with numeric format, but not for ${this.props.format}`, CharacteristicWarningType.ERROR_MESSAGE);
1484
1485
  props.minValue = undefined;
1485
1486
  }
1486
1487
  else if (typeof props.minValue !== 'number' || !Number.isFinite(props.minValue)) {
1487
- this.characteristicWarning(`Characteristic Property 'minValue' must be a finite number, received "${props.minValue}" (${typeof props.minValue})`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1488
+ this.characteristicWarning(`Characteristic Property 'minValue' must be a finite number, received "${props.minValue}" (${typeof props.minValue})`, CharacteristicWarningType.ERROR_MESSAGE);
1488
1489
  props.minValue = undefined;
1489
1490
  }
1490
1491
  else {
1491
1492
  if (props.minValue < numericLowerBound(this.props.format)) {
1492
- this.characteristicWarning(`Characteristic Property 'minValue' was set to ${props.minValue}, but for numeric format ${this.props.format} minimum possible is ${numericLowerBound(this.props.format)}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1493
+ this.characteristicWarning(`Characteristic Property 'minValue' was set to ${props.minValue}, but for numeric format ${this.props.format} minimum possible is ${numericLowerBound(this.props.format)}`, CharacteristicWarningType.ERROR_MESSAGE);
1493
1494
  props.minValue = numericLowerBound(this.props.format);
1494
1495
  }
1495
1496
  else if (props.minValue > numericUpperBound(this.props.format)) {
1496
- this.characteristicWarning(`Characteristic Property 'minValue' was set to ${props.minValue}, but for numeric format ${this.props.format} maximum possible is ${numericUpperBound(this.props.format)}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1497
+ this.characteristicWarning(`Characteristic Property 'minValue' was set to ${props.minValue}, but for numeric format ${this.props.format} maximum possible is ${numericUpperBound(this.props.format)}`, CharacteristicWarningType.ERROR_MESSAGE);
1497
1498
  props.minValue = numericLowerBound(this.props.format);
1498
1499
  }
1499
1500
  }
@@ -1505,20 +1506,20 @@ export class Characteristic extends EventEmitter {
1505
1506
  props.maxValue = undefined;
1506
1507
  }
1507
1508
  else if (!isNumericFormat(this.props.format)) {
1508
- this.characteristicWarning(`Characteristic Property 'maxValue' can only be set for characteristics with numeric format, but not for ${this.props.format}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1509
+ this.characteristicWarning(`Characteristic Property 'maxValue' can only be set for characteristics with numeric format, but not for ${this.props.format}`, CharacteristicWarningType.ERROR_MESSAGE);
1509
1510
  props.maxValue = undefined;
1510
1511
  }
1511
1512
  else if (typeof props.maxValue !== 'number' || !Number.isFinite(props.maxValue)) {
1512
- this.characteristicWarning(`Characteristic Property 'maxValue' must be a finite number, received "${props.maxValue}" (${typeof props.maxValue})`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1513
+ this.characteristicWarning(`Characteristic Property 'maxValue' must be a finite number, received "${props.maxValue}" (${typeof props.maxValue})`, CharacteristicWarningType.ERROR_MESSAGE);
1513
1514
  props.maxValue = undefined;
1514
1515
  }
1515
1516
  else {
1516
1517
  if (props.maxValue > numericUpperBound(this.props.format)) {
1517
- this.characteristicWarning(`Characteristic Property 'maxValue' was set to ${props.maxValue}, but for numeric format ${this.props.format} maximum possible is ${numericUpperBound(this.props.format)}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1518
+ this.characteristicWarning(`Characteristic Property 'maxValue' was set to ${props.maxValue}, but for numeric format ${this.props.format} maximum possible is ${numericUpperBound(this.props.format)}`, CharacteristicWarningType.ERROR_MESSAGE);
1518
1519
  props.maxValue = numericUpperBound(this.props.format);
1519
1520
  }
1520
1521
  else if (props.maxValue < numericLowerBound(this.props.format)) {
1521
- this.characteristicWarning(`Characteristic Property 'maxValue' was set to ${props.maxValue}, but for numeric format ${this.props.format} minimum possible is ${numericLowerBound(this.props.format)}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1522
+ this.characteristicWarning(`Characteristic Property 'maxValue' was set to ${props.maxValue}, but for numeric format ${this.props.format} minimum possible is ${numericLowerBound(this.props.format)}`, CharacteristicWarningType.ERROR_MESSAGE);
1522
1523
  props.maxValue = numericUpperBound(this.props.format);
1523
1524
  }
1524
1525
  }
@@ -1529,13 +1530,17 @@ export class Characteristic extends EventEmitter {
1529
1530
  this.props.minStep = undefined;
1530
1531
  }
1531
1532
  else if (!isNumericFormat(this.props.format)) {
1532
- this.characteristicWarning(`Characteristic Property \`minStep\` can only be set for characteristics with numeric format, but not for ${this.props.format}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1533
+ this.characteristicWarning(`Characteristic Property \`minStep\` can only be set for characteristics with numeric format, but not for ${this.props.format}`, CharacteristicWarningType.ERROR_MESSAGE);
1534
+ }
1535
+ else if (typeof props.minStep !== 'number' || !Number.isFinite(props.minStep) || props.minStep <= 0) {
1536
+ this.characteristicWarning(`Characteristic Property \`minStep\` must be a number above 0, but ${JSON.stringify(props.minStep)} was supplied. It is ignored.`, CharacteristicWarningType.ERROR_MESSAGE);
1537
+ }
1538
+ else if (isIntegerNumericFormat(this.props.format) && !Number.isInteger(props.minStep)) {
1539
+ // published, a step of 0.5 lets the Home app write 21.5, which an integer format refuses
1540
+ this.characteristicWarning(`Characteristic Property \`minStep\` must be a whole number for format \`${this.props.format}\`, `
1541
+ + `but ${props.minStep} was supplied. It is ignored.`);
1533
1542
  }
1534
1543
  else {
1535
- if (props.minStep < 1 && isIntegerNumericFormat(this.props.format)) {
1536
- this.characteristicWarning('Characteristic Property `minStep` was set to a value lower than 1, '
1537
- + `this will have no effect on format \`${this.props.format}`);
1538
- }
1539
1544
  this.props.minStep = props.minStep;
1540
1545
  }
1541
1546
  }
@@ -1543,8 +1548,8 @@ export class Characteristic extends EventEmitter {
1543
1548
  if (props.maxLen === null) {
1544
1549
  this.props.maxLen = undefined;
1545
1550
  }
1546
- else if (this.props.format !== "string" /* Formats.STRING */) {
1547
- this.characteristicWarning(`Characteristic Property \`maxLen\` can only be set for characteristics with format \`STRING\`, but not for ${this.props.format}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1551
+ else if (this.props.format !== Formats.STRING) {
1552
+ this.characteristicWarning(`Characteristic Property \`maxLen\` can only be set for characteristics with format \`STRING\`, but not for ${this.props.format}`, CharacteristicWarningType.ERROR_MESSAGE);
1548
1553
  }
1549
1554
  else {
1550
1555
  if (props.maxLen > 256) {
@@ -1558,8 +1563,8 @@ export class Characteristic extends EventEmitter {
1558
1563
  if (props.maxDataLen === null) {
1559
1564
  this.props.maxDataLen = undefined;
1560
1565
  }
1561
- else if (this.props.format !== "data" /* Formats.DATA */) {
1562
- this.characteristicWarning(`Characteristic Property \`maxDataLen\` can only be set for characteristics with format \`DATA\`, but not for ${this.props.format}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
1566
+ else if (this.props.format !== Formats.DATA) {
1567
+ this.characteristicWarning(`Characteristic Property \`maxDataLen\` can only be set for characteristics with format \`DATA\`, but not for ${this.props.format}`, CharacteristicWarningType.ERROR_MESSAGE);
1563
1568
  }
1564
1569
  else {
1565
1570
  this.props.maxDataLen = props.maxDataLen;
@@ -1596,13 +1601,13 @@ export class Characteristic extends EventEmitter {
1596
1601
  if (this.props.minValue > this.props.maxValue) { // see https://github.com/homebridge/HAP-NodeJS/issues/690
1597
1602
  this.props.minValue = undefined;
1598
1603
  this.props.maxValue = undefined;
1599
- throw new Error(`Error setting CharacteristicsProps for '${this.displayName}': 'minValue' cannot be greater or equal the 'maxValue'!`);
1604
+ throw new Error(`Error setting CharacteristicsProps for '${this.displayName}': 'minValue' cannot be greater than 'maxValue'!`);
1600
1605
  }
1601
1606
  }
1602
1607
  // the properties are part of the configuration HomeKit is served, so a published accessory must recompute its configuration number;
1603
1608
  // a call that changes nothing leaves the configuration hash and therefore the number as it was
1604
- this.emit("characteristic-configurationChange" /* CharacteristicEventTypes.CHARACTERISTIC_CONFIGURATION_CHANGE */);
1605
- if ((isNumericFormat(this.props.format) || this.props.format === "string" /* Formats.STRING */)
1609
+ this.emit(CharacteristicEventTypes.CHARACTERISTIC_CONFIGURATION_CHANGE);
1610
+ if ((isNumericFormat(this.props.format) || this.props.format === Formats.STRING)
1606
1611
  && this.value != null
1607
1612
  && !formatDidChange
1608
1613
  && this.statusCode === HAPStatus.SUCCESS
@@ -1613,8 +1618,8 @@ export class Characteristic extends EventEmitter {
1613
1618
  // - If the format is changed through `setProps` we rely on the user to supply a valid value after the `setProps` call!
1614
1619
  // - If the characteristic is marked as erroneous the value is not considered valid anyway, and we must not remove the `statusCode`.
1615
1620
  // - Special case for `ProgrammableSwitchEvent` where every change in value is considered an event which would result in ghost button presses
1616
- // validateUserInput when called from setProps is intended to clamp value withing allowed range. It is why warnings should not be displayed.
1617
- const correctedValue = this.validateUserInput(this.value, "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
1621
+ // validateUserInput when called from setProps is intended to clamp the value within the allowed range. That is why warnings should not be displayed.
1622
+ const correctedValue = this.validateUserInput(this.value, CharacteristicWarningType.DEBUG_MESSAGE);
1618
1623
  if (correctedValue !== this.value) {
1619
1624
  // we don't want to emit a CHANGE event if the value didn't change at all!
1620
1625
  this.updateValue(correctedValue);
@@ -1632,7 +1637,7 @@ export class Characteristic extends EventEmitter {
1632
1637
  * {@link CharacteristicProps.minStep})
1633
1638
  * And lastly you can specify a range via {@link CharacteristicProps.validValueRanges}
1634
1639
  * Implicitly a valid value range is predefined for characteristics with Format {@link Formats.UINT8}, {@link Formats.UINT16},
1635
- * {@link Formats.UINT32} and {@link Formats.UINT64}: starting by zero to their respective maximum number
1640
+ * {@link Formats.UINT32} and {@link Formats.UINT64}: starting at zero up to their respective maximum number
1636
1641
  *
1637
1642
  * The method will automatically detect which type of valid values definition is used and provide
1638
1643
  * the correct Iterator for that case.
@@ -1671,8 +1676,8 @@ export class Characteristic extends EventEmitter {
1671
1676
  * @param handler - Handler called to check additional authorization data.
1672
1677
  */
1673
1678
  setupAdditionalAuthorization(handler) {
1674
- if (!this.props.perms.includes("aa" /* Perms.ADDITIONAL_AUTHORIZATION */)) {
1675
- this.props.perms.push("aa" /* Perms.ADDITIONAL_AUTHORIZATION */);
1679
+ if (!this.props.perms.includes(Perms.ADDITIONAL_AUTHORIZATION)) {
1680
+ this.props.perms.push(Perms.ADDITIONAL_AUTHORIZATION);
1676
1681
  }
1677
1682
  this.additionalAuthorizationHandler = handler;
1678
1683
  }
@@ -1694,15 +1699,17 @@ export class Characteristic extends EventEmitter {
1694
1699
  value = this.validateUserInput(value);
1695
1700
  }
1696
1701
  catch (error) {
1697
- this.characteristicWarning(error?.message || 'Unknown error', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1702
+ this.characteristicWarning((error instanceof Error && error.message) || 'Unknown error', CharacteristicWarningType.ERROR_MESSAGE, errorStack(error));
1698
1703
  if (callback) {
1699
- callback(error);
1704
+ callback(error instanceof Error
1705
+ ? error
1706
+ : new Error(String(error)));
1700
1707
  }
1701
1708
  return this;
1702
1709
  }
1703
1710
  this.handleSetRequest(value, undefined, context).then((value) => {
1704
1711
  if (callback) {
1705
- if (value) { // possible write response
1712
+ if (value != null) { // possible write response, which may well be 0, false or an empty string
1706
1713
  callback(null, value);
1707
1714
  }
1708
1715
  else {
@@ -1734,7 +1741,7 @@ export class Characteristic extends EventEmitter {
1734
1741
  value = this.validateUserInput(value);
1735
1742
  }
1736
1743
  catch (error) {
1737
- this.characteristicWarning(error?.message || 'Unknown error', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1744
+ this.characteristicWarning((error instanceof Error && error.message) || 'Unknown error', CharacteristicWarningType.ERROR_MESSAGE, errorStack(error));
1738
1745
  if (callback) {
1739
1746
  callback();
1740
1747
  }
@@ -1746,11 +1753,11 @@ export class Characteristic extends EventEmitter {
1746
1753
  if (callback) {
1747
1754
  callback();
1748
1755
  }
1749
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1756
+ this.emit(CharacteristicEventTypes.CHANGE, {
1750
1757
  originator: undefined,
1751
1758
  oldValue,
1752
1759
  newValue: value,
1753
- reason: "update" /* ChangeReason.UPDATE */,
1760
+ reason: ChangeReason.UPDATE,
1754
1761
  context,
1755
1762
  });
1756
1763
  return this; // for chaining
@@ -1765,28 +1772,28 @@ export class Characteristic extends EventEmitter {
1765
1772
  * @param context - Passed to the {@link CharacteristicEventTypes.CHANGE} event handler.
1766
1773
  */
1767
1774
  sendEventNotification(value, context) {
1775
+ value = this.validateUserInput(value); // may throw, and then nothing has changed
1768
1776
  this.statusCode = HAPStatus.SUCCESS;
1769
- value = this.validateUserInput(value);
1770
1777
  const oldValue = this.value;
1771
1778
  this.value = value;
1772
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1779
+ this.emit(CharacteristicEventTypes.CHANGE, {
1773
1780
  originator: undefined,
1774
1781
  oldValue,
1775
1782
  newValue: value,
1776
- reason: "event" /* ChangeReason.EVENT */,
1783
+ reason: ChangeReason.EVENT,
1777
1784
  context,
1778
1785
  });
1779
1786
  return this; // for chaining
1780
1787
  }
1781
1788
  /**
1782
- * Called when a HAP requests wants to know the current value of the characteristic.
1789
+ * Called when a HAP request wants to know the current value of the characteristic.
1783
1790
  *
1784
1791
  * @param connection - The HAP connection from which the request originated from.
1785
- * @param context - Deprecated parameter. There for backwards compatibility.
1792
+ * @param context - Passed on to the handler and to the listeners of the change event.
1786
1793
  * @private
1787
1794
  */
1788
1795
  async handleGetRequest(connection, context) {
1789
- if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if we are allowed to read from this characteristic
1796
+ if (!this.props.perms.includes(Perms.PAIRED_READ)) { // check if we are allowed to read from this characteristic
1790
1797
  throw HAPStatus.WRITE_ONLY_CHARACTERISTIC;
1791
1798
  }
1792
1799
  if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
@@ -1794,7 +1801,7 @@ export class Characteristic extends EventEmitter {
1794
1801
  return null;
1795
1802
  }
1796
1803
  if (this.getHandler) {
1797
- if (this.listeners("get" /* CharacteristicEventTypes.GET */).length > 0) {
1804
+ if (this.listenerCount(CharacteristicEventTypes.GET) > 0) {
1798
1805
  this.characteristicWarning('Ignoring on(\'get\') handler as onGet handler was defined instead');
1799
1806
  }
1800
1807
  try {
@@ -1804,18 +1811,18 @@ export class Characteristic extends EventEmitter {
1804
1811
  value = this.validateUserInput(value);
1805
1812
  }
1806
1813
  catch (error) {
1807
- this.characteristicWarning(`An illegal value was supplied by the read handler for characteristic: ${error?.message}`, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error?.stack);
1814
+ this.characteristicWarning(`An illegal value was supplied by the read handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.WARN_MESSAGE, errorStack(error));
1808
1815
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1809
1816
  return Promise.reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1810
1817
  }
1811
1818
  const oldValue = this.value;
1812
1819
  this.value = value;
1813
1820
  if (oldValue !== value) { // emit a change event if necessary
1814
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1821
+ this.emit(CharacteristicEventTypes.CHANGE, {
1815
1822
  originator: connection,
1816
1823
  oldValue,
1817
1824
  newValue: value,
1818
- reason: "read" /* ChangeReason.READ */,
1825
+ reason: ChangeReason.READ,
1819
1826
  context,
1820
1827
  });
1821
1828
  }
@@ -1830,13 +1837,13 @@ export class Characteristic extends EventEmitter {
1830
1837
  this.statusCode = error.hapStatus;
1831
1838
  }
1832
1839
  else {
1833
- this.characteristicWarning(`Unhandled error thrown inside read handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1840
+ this.characteristicWarning(`Unhandled error thrown inside read handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.ERROR_MESSAGE, errorStack(error));
1834
1841
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1835
1842
  }
1836
1843
  throw this.statusCode;
1837
1844
  }
1838
1845
  }
1839
- if (this.listeners("get" /* CharacteristicEventTypes.GET */).length === 0) {
1846
+ if (this.listenerCount(CharacteristicEventTypes.GET) === 0) {
1840
1847
  if (this.statusCode) {
1841
1848
  throw this.statusCode;
1842
1849
  }
@@ -1844,13 +1851,13 @@ export class Characteristic extends EventEmitter {
1844
1851
  return this.validateUserInput(this.value);
1845
1852
  }
1846
1853
  catch (error) {
1847
- this.characteristicWarning(`An illegal value was supplied by setting \`value\` for characteristic: ${error?.message}`, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error?.stack);
1854
+ this.characteristicWarning(`An illegal value was supplied by setting \`value\` for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.WARN_MESSAGE, errorStack(error));
1848
1855
  return Promise.reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1849
1856
  }
1850
1857
  }
1851
1858
  return new Promise((resolve, reject) => {
1852
1859
  try {
1853
- this.emit("get" /* CharacteristicEventTypes.GET */, once((status, value) => {
1860
+ this.emit(CharacteristicEventTypes.GET, once((status, value) => {
1854
1861
  if (status) {
1855
1862
  if (typeof status === 'number') {
1856
1863
  const hapStatusError = new HapStatusError(status);
@@ -1872,7 +1879,7 @@ export class Characteristic extends EventEmitter {
1872
1879
  }
1873
1880
  catch (error) {
1874
1881
  // this runs inside the plugin's callback; a throw would land in the plugin and leave the request unanswered
1875
- this.characteristicWarning(`An illegal value was supplied by the read handler for characteristic: ${error?.message}`, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error?.stack);
1882
+ this.characteristicWarning(`An illegal value was supplied by the read handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.WARN_MESSAGE, errorStack(error));
1876
1883
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1877
1884
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1878
1885
  return;
@@ -1881,36 +1888,35 @@ export class Characteristic extends EventEmitter {
1881
1888
  this.value = value;
1882
1889
  resolve(value);
1883
1890
  if (oldValue !== value) { // emit a change event if necessary
1884
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1891
+ this.emit(CharacteristicEventTypes.CHANGE, {
1885
1892
  originator: connection,
1886
1893
  oldValue,
1887
1894
  newValue: value,
1888
- reason: "read" /* ChangeReason.READ */,
1895
+ reason: ChangeReason.READ,
1889
1896
  context,
1890
1897
  });
1891
1898
  }
1892
1899
  }), context, connection);
1893
1900
  }
1894
1901
  catch (error) {
1895
- this.characteristicWarning(`Unhandled error thrown inside read handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1902
+ this.characteristicWarning(`Unhandled error thrown inside read handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.ERROR_MESSAGE, errorStack(error));
1896
1903
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1897
1904
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1898
1905
  }
1899
1906
  });
1900
1907
  }
1901
1908
  /**
1902
- * Called when a HAP requests update the current value of the characteristic.
1909
+ * Called when a HAP request updates the current value of the characteristic.
1903
1910
  *
1904
1911
  * @param value - The updated value
1905
1912
  * @param connection - The connection from which the request originated from
1906
- * @param context - Deprecated parameter. There for backwards compatibility.
1913
+ * @param context - Passed on to the handler and to the listeners of the change event.
1907
1914
  * @returns Promise resolve to void in normal operation. When characteristic supports write-response, HAP
1908
1915
  * requests a write-response and the set handler returns a write-response value, the respective
1909
1916
  * write response value is resolved.
1910
1917
  * @private
1911
1918
  */
1912
1919
  async handleSetRequest(value, connection, context) {
1913
- this.statusCode = HAPStatus.SUCCESS;
1914
1920
  if (connection !== undefined) {
1915
1921
  // if connection is undefined, the set "request" comes from the setValue method.
1916
1922
  // for setValue a value of "null" is allowed and checked via validateUserInput.
@@ -1918,32 +1924,34 @@ export class Characteristic extends EventEmitter {
1918
1924
  value = this.validateClientSuppliedValue(value);
1919
1925
  }
1920
1926
  catch (e) {
1921
- debug(`[${this.displayName}]`, e.message);
1927
+ debug(`[${this.displayName}]`, errorMessage(e));
1922
1928
  return Promise.reject(HAPStatus.INVALID_VALUE_IN_REQUEST);
1923
1929
  }
1924
1930
  }
1931
+ // only now: a write which was refused above changes nothing, so it must not clear an error state either
1932
+ this.statusCode = HAPStatus.SUCCESS;
1925
1933
  const oldValue = this.value;
1926
1934
  if (this.setHandler) {
1927
- if (this.listeners("set" /* CharacteristicEventTypes.SET */).length > 0) {
1935
+ if (this.listenerCount(CharacteristicEventTypes.SET) > 0) {
1928
1936
  this.characteristicWarning('Ignoring on(\'set\') handler as onSet handler was defined instead');
1929
1937
  }
1930
1938
  try {
1931
1939
  const writeResponse = await this.setHandler(value, context, connection);
1932
1940
  this.statusCode = HAPStatus.SUCCESS;
1933
- if (writeResponse != null && this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
1941
+ if (writeResponse != null && this.props.perms.includes(Perms.WRITE_RESPONSE)) {
1934
1942
  this.value = this.validateUserInput(writeResponse);
1935
1943
  return this.value;
1936
1944
  }
1937
1945
  else {
1938
1946
  if (writeResponse != null) {
1939
- this.characteristicWarning('SET handler returned write response value, though the characteristic doesn\'t support write response', "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
1947
+ this.characteristicWarning('SET handler returned write response value, though the characteristic doesn\'t support write response', CharacteristicWarningType.DEBUG_MESSAGE);
1940
1948
  }
1941
1949
  this.value = value;
1942
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1950
+ this.emit(CharacteristicEventTypes.CHANGE, {
1943
1951
  originator: connection,
1944
1952
  oldValue,
1945
1953
  newValue: value,
1946
- reason: "write" /* ChangeReason.WRITE */,
1954
+ reason: ChangeReason.WRITE,
1947
1955
  context,
1948
1956
  });
1949
1957
  return;
@@ -1958,19 +1966,19 @@ export class Characteristic extends EventEmitter {
1958
1966
  this.statusCode = error.hapStatus;
1959
1967
  }
1960
1968
  else {
1961
- this.characteristicWarning(`Unhandled error thrown inside write handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
1969
+ this.characteristicWarning(`Unhandled error thrown inside write handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.ERROR_MESSAGE, errorStack(error));
1962
1970
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1963
1971
  }
1964
1972
  throw this.statusCode;
1965
1973
  }
1966
1974
  }
1967
- if (this.listeners("set" /* CharacteristicEventTypes.SET */).length === 0) {
1975
+ if (this.listenerCount(CharacteristicEventTypes.SET) === 0) {
1968
1976
  this.value = value;
1969
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1977
+ this.emit(CharacteristicEventTypes.CHANGE, {
1970
1978
  originator: connection,
1971
1979
  oldValue,
1972
1980
  newValue: value,
1973
- reason: "write" /* ChangeReason.WRITE */,
1981
+ reason: ChangeReason.WRITE,
1974
1982
  context,
1975
1983
  });
1976
1984
  return Promise.resolve();
@@ -1978,7 +1986,7 @@ export class Characteristic extends EventEmitter {
1978
1986
  else {
1979
1987
  return new Promise((resolve, reject) => {
1980
1988
  try {
1981
- this.emit("set" /* CharacteristicEventTypes.SET */, value, once((status, writeResponse) => {
1989
+ this.emit(CharacteristicEventTypes.SET, value, once((status, writeResponse) => {
1982
1990
  if (status) {
1983
1991
  if (typeof status === 'number') {
1984
1992
  const hapStatusError = new HapStatusError(status);
@@ -1995,14 +2003,14 @@ export class Characteristic extends EventEmitter {
1995
2003
  return;
1996
2004
  }
1997
2005
  this.statusCode = HAPStatus.SUCCESS;
1998
- if (writeResponse != null && this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
2006
+ if (writeResponse != null && this.props.perms.includes(Perms.WRITE_RESPONSE)) {
1999
2007
  // support write response simply by letting the implementor pass the response as second argument to the callback
2000
2008
  try {
2001
2009
  this.value = this.validateUserInput(writeResponse);
2002
2010
  }
2003
2011
  catch (error) {
2004
2012
  // this runs inside the plugin's callback; a throw would land in the plugin and leave the request unanswered
2005
- this.characteristicWarning(`An illegal write response value was supplied by the write handler for characteristic: ${error?.message}`, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, error?.stack);
2013
+ this.characteristicWarning(`An illegal write response value was supplied by the write handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.WARN_MESSAGE, errorStack(error));
2006
2014
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
2007
2015
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
2008
2016
  return;
@@ -2011,22 +2019,22 @@ export class Characteristic extends EventEmitter {
2011
2019
  }
2012
2020
  else {
2013
2021
  if (writeResponse != null) {
2014
- this.characteristicWarning('SET handler returned write response value, though the characteristic doesn\'t support write response', "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
2022
+ this.characteristicWarning('SET handler returned write response value, though the characteristic doesn\'t support write response', CharacteristicWarningType.DEBUG_MESSAGE);
2015
2023
  }
2016
2024
  this.value = value;
2017
2025
  resolve();
2018
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
2026
+ this.emit(CharacteristicEventTypes.CHANGE, {
2019
2027
  originator: connection,
2020
2028
  oldValue,
2021
2029
  newValue: value,
2022
- reason: "write" /* ChangeReason.WRITE */,
2030
+ reason: ChangeReason.WRITE,
2023
2031
  context,
2024
2032
  });
2025
2033
  }
2026
2034
  }), context, connection);
2027
2035
  }
2028
2036
  catch (error) {
2029
- this.characteristicWarning(`Unhandled error thrown inside write handler for characteristic: ${error?.message}`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
2037
+ this.characteristicWarning(`Unhandled error thrown inside write handler for characteristic: ${errorMessage(error)}`, CharacteristicWarningType.ERROR_MESSAGE, errorStack(error));
2030
2038
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
2031
2039
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
2032
2040
  }
@@ -2039,12 +2047,12 @@ export class Characteristic extends EventEmitter {
2039
2047
  */
2040
2048
  subscribe() {
2041
2049
  if (this.subscriptions === 0) {
2042
- this.emit("subscribe" /* CharacteristicEventTypes.SUBSCRIBE */);
2050
+ this.emit(CharacteristicEventTypes.SUBSCRIBE);
2043
2051
  }
2044
2052
  this.subscriptions++;
2045
2053
  }
2046
2054
  /**
2047
- * Called once a HomeKit controller unsubscribe to events of this characteristic or a HomeKit controller
2055
+ * Called once a HomeKit controller unsubscribes from events of this characteristic or a HomeKit controller
2048
2056
  * which was subscribed to this characteristic disconnects.
2049
2057
  * @private
2050
2058
  */
@@ -2053,15 +2061,15 @@ export class Characteristic extends EventEmitter {
2053
2061
  this.subscriptions--;
2054
2062
  this.subscriptions = Math.max(this.subscriptions, 0);
2055
2063
  if (wasOne) {
2056
- this.emit("unsubscribe" /* CharacteristicEventTypes.UNSUBSCRIBE */);
2064
+ this.emit(CharacteristicEventTypes.UNSUBSCRIBE);
2057
2065
  }
2058
2066
  }
2059
2067
  getDefaultValue() {
2060
2068
  // noinspection JSDeprecatedSymbols
2061
2069
  switch (this.props.format) {
2062
- case "bool" /* Formats.BOOL */:
2070
+ case Formats.BOOL:
2063
2071
  return false;
2064
- case "string" /* Formats.STRING */:
2072
+ case Formats.STRING:
2065
2073
  switch (this.UUID) {
2066
2074
  case Characteristic.Manufacturer.UUID:
2067
2075
  return 'Default-Manufacturer';
@@ -2074,16 +2082,16 @@ export class Characteristic extends EventEmitter {
2074
2082
  default:
2075
2083
  return '';
2076
2084
  }
2077
- case "data" /* Formats.DATA */:
2085
+ case Formats.DATA:
2078
2086
  return ''; // who knows!
2079
- case "tlv8" /* Formats.TLV8 */:
2087
+ case Formats.TLV8:
2080
2088
  return ''; // who knows!
2081
- case "int" /* Formats.INT */:
2082
- case "float" /* Formats.FLOAT */:
2083
- case "uint8" /* Formats.UINT8 */:
2084
- case "uint16" /* Formats.UINT16 */:
2085
- case "uint32" /* Formats.UINT32 */:
2086
- case "uint64" /* Formats.UINT64 */:
2089
+ case Formats.INT:
2090
+ case Formats.FLOAT:
2091
+ case Formats.UINT8:
2092
+ case Formats.UINT16:
2093
+ case Formats.UINT32:
2094
+ case Formats.UINT64:
2087
2095
  switch (this.UUID) {
2088
2096
  case Characteristic.CurrentTemperature.UUID:
2089
2097
  return 0; // some existing integrations expect this to be 0 by default
@@ -2112,7 +2120,7 @@ export class Characteristic extends EventEmitter {
2112
2120
  throw new Error(`Client supplied invalid value for ${this.props.format}: ${value}`);
2113
2121
  }
2114
2122
  switch (this.props.format) {
2115
- case "bool" /* Formats.BOOL */: {
2123
+ case Formats.BOOL: {
2116
2124
  if (typeof value === 'boolean') {
2117
2125
  return value;
2118
2126
  }
@@ -2121,18 +2129,21 @@ export class Characteristic extends EventEmitter {
2121
2129
  }
2122
2130
  throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2123
2131
  }
2124
- case "int" /* Formats.INT */:
2125
- case "float" /* Formats.FLOAT */:
2126
- case "uint8" /* Formats.UINT8 */:
2127
- case "uint16" /* Formats.UINT16 */:
2128
- case "uint32" /* Formats.UINT32 */:
2129
- case "uint64" /* Formats.UINT64 */: {
2132
+ case Formats.INT:
2133
+ case Formats.FLOAT:
2134
+ case Formats.UINT8:
2135
+ case Formats.UINT16:
2136
+ case Formats.UINT32:
2137
+ case Formats.UINT64: {
2130
2138
  if (typeof value === 'boolean') {
2131
2139
  value = value ? 1 : 0;
2132
2140
  }
2133
2141
  if (typeof value !== 'number' || !Number.isFinite(value)) {
2134
2142
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2135
2143
  }
2144
+ if (isIntegerNumericFormat(this.props.format) && !Number.isInteger(value)) {
2145
+ throw new TypeError(`Client supplied a value of ${value}, which is not a whole number, for ${this.props.format}`);
2146
+ }
2136
2147
  const numericMin = maxWithUndefined(this.props.minValue, numericLowerBound(this.props.format));
2137
2148
  const numericMax = minWithUndefined(this.props.maxValue, numericUpperBound(this.props.format));
2138
2149
  if (typeof numericMin === 'number' && value < numericMin) {
@@ -2154,7 +2165,7 @@ export class Characteristic extends EventEmitter {
2154
2165
  }
2155
2166
  return value;
2156
2167
  }
2157
- case "string" /* Formats.STRING */: {
2168
+ case Formats.STRING: {
2158
2169
  if (typeof value !== 'string') {
2159
2170
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2160
2171
  }
@@ -2164,7 +2175,7 @@ export class Characteristic extends EventEmitter {
2164
2175
  }
2165
2176
  return value;
2166
2177
  }
2167
- case "data" /* Formats.DATA */: {
2178
+ case Formats.DATA: {
2168
2179
  if (typeof value !== 'string') {
2169
2180
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2170
2181
  }
@@ -2175,7 +2186,7 @@ export class Characteristic extends EventEmitter {
2175
2186
  }
2176
2187
  return value;
2177
2188
  }
2178
- case "tlv8" /* Formats.TLV8 */:
2189
+ case Formats.TLV8:
2179
2190
  if (typeof value !== 'string') {
2180
2191
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2181
2192
  }
@@ -2191,24 +2202,24 @@ export class Characteristic extends EventEmitter {
2191
2202
  * @param value - The value received from the API call
2192
2203
  * @param warningType - Optionally defines the warning type to use when raising a {@link CharacteristicEventTypes.CHARACTERISTIC_WARNING}.
2193
2204
  */
2194
- validateUserInput(value, warningType = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */) {
2205
+ validateUserInput(value, warningType = CharacteristicWarningType.WARN_MESSAGE) {
2195
2206
  if (value === null) {
2196
2207
  if (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID) { // mirrors the statement in case: Formats.STRING
2197
- this.characteristicWarning('characteristic must have a non null value otherwise HomeKit will reject this accessory, ignoring new value', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
2208
+ this.characteristicWarning('characteristic must have a non null value otherwise HomeKit will reject this accessory, ignoring new value', CharacteristicWarningType.ERROR_MESSAGE);
2198
2209
  return this.value; // don't change the value
2199
2210
  }
2200
- if (this.props.format === "data" /* Formats.DATA */ || this.props.format === "tlv8" /* Formats.TLV8 */) {
2211
+ if (this.props.format === Formats.DATA || this.props.format === Formats.TLV8) {
2201
2212
  return value; // TLV8 and DATA formats are allowed to have null as a value
2202
2213
  }
2203
2214
  /**
2204
2215
  * A short disclaimer here.
2205
2216
  * null is actually a perfectly valid value for characteristics to have.
2206
2217
  * The Home app will show "no response" for some characteristics for which it can't handle null
2207
- * but ultimately its valid and the developers decision what the return.
2208
- * BUT: out of history hap-nodejs did replace null with the last known value and thus
2209
- * homebridge devs started to adopting this method as a way of not changing the value in a GET handler.
2218
+ * but ultimately it's valid and the developer's decision what to return.
2219
+ * BUT: for historical reasons hap-nodejs did replace null with the last known value and thus
2220
+ * homebridge devs started adopting this method as a way of not changing the value in a GET handler.
2210
2221
  * As an intermediate step we kept the behavior but added a warning printed to the console.
2211
- * In a future update we will do the breaking change of return null below!
2222
+ * In a future update we will do the breaking change of returning null below!
2212
2223
  */
2213
2224
  if (this.UUID.endsWith(BASE_UUID)) { // we have an apple defined characteristic (at least assuming nobody else uses the UUID namespace)
2214
2225
  if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
@@ -2221,12 +2232,12 @@ export class Characteristic extends EventEmitter {
2221
2232
  }
2222
2233
  }
2223
2234
  else {
2224
- // we currently allow null for any non-custom defined characteristics
2235
+ // we currently allow null for any custom defined characteristics
2225
2236
  return value;
2226
2237
  }
2227
2238
  }
2228
2239
  switch (this.props.format) {
2229
- case "bool" /* Formats.BOOL */: {
2240
+ case Formats.BOOL: {
2230
2241
  if (typeof value === 'boolean') {
2231
2242
  return value;
2232
2243
  }
@@ -2239,17 +2250,17 @@ export class Characteristic extends EventEmitter {
2239
2250
  this.characteristicWarning(`characteristic value expected boolean and received ${typeof value}`, warningType);
2240
2251
  return false;
2241
2252
  }
2242
- case "int" /* Formats.INT */:
2243
- case "float" /* Formats.FLOAT */:
2244
- case "uint8" /* Formats.UINT8 */:
2245
- case "uint16" /* Formats.UINT16 */:
2246
- case "uint32" /* Formats.UINT32 */:
2247
- case "uint64" /* Formats.UINT64 */: {
2253
+ case Formats.INT:
2254
+ case Formats.FLOAT:
2255
+ case Formats.UINT8:
2256
+ case Formats.UINT16:
2257
+ case Formats.UINT32:
2258
+ case Formats.UINT64: {
2248
2259
  if (typeof value === 'boolean') {
2249
2260
  value = value ? 1 : 0;
2250
2261
  }
2251
2262
  if (typeof value === 'string') {
2252
- value = this.props.format === "float" /* Formats.FLOAT */
2263
+ value = this.props.format === Formats.FLOAT
2253
2264
  ? Number.parseFloat(value)
2254
2265
  : parseInt(value, 10);
2255
2266
  }
@@ -2262,7 +2273,7 @@ export class Characteristic extends EventEmitter {
2262
2273
  const numericMin = maxWithUndefined(this.props.minValue, numericLowerBound(this.props.format));
2263
2274
  let numericMax = minWithUndefined(this.props.maxValue, numericUpperBound(this.props.format));
2264
2275
  let stepValue;
2265
- if (this.props.format === "float" /* Formats.FLOAT */) {
2276
+ if (this.props.format === Formats.FLOAT) {
2266
2277
  stepValue = this.props.minStep;
2267
2278
  }
2268
2279
  else {
@@ -2271,9 +2282,15 @@ export class Characteristic extends EventEmitter {
2271
2282
  if (stepValue != null && stepValue > 0) {
2272
2283
  const minValue = this.props.minValue ?? 0;
2273
2284
  if (numericMax != null) {
2274
- numericMax = stepValue * Math.floor((numericMax - minValue) / stepValue) + minValue;
2285
+ // (0.3 - 0) / 0.1 comes out as 2.9999999999999996. That is three whole steps, not two,
2286
+ // so the floating point error is rounded away before the number of steps is rounded down.
2287
+ const steps = Math.floor(Number.parseFloat(((numericMax - minValue) / stepValue).toFixed(9)));
2288
+ numericMax = Math.min(numericMax, stepValue * steps + minValue);
2275
2289
  }
2276
2290
  value = stepValue * Math.round((value - minValue) / stepValue) + minValue;
2291
+ if (numericMax != null && value > numericMax && value - numericMax < 1e-9) {
2292
+ value = numericMax; // 0.1 * 3 comes out as 0.30000000000000004, which is the maximum of 0.3 and not above it
2293
+ }
2277
2294
  }
2278
2295
  if (numericMin != null && value < numericMin) {
2279
2296
  this.characteristicWarning(`characteristic was supplied illegal value: number ${value} exceeded minimum of ${numericMin}`, warningType);
@@ -2303,7 +2320,7 @@ export class Characteristic extends EventEmitter {
2303
2320
  }
2304
2321
  return value;
2305
2322
  }
2306
- case "string" /* Formats.STRING */: {
2323
+ case Formats.STRING: {
2307
2324
  if (typeof value === 'number') {
2308
2325
  this.characteristicWarning('characteristic was supplied illegal value: number instead of string, '
2309
2326
  + 'supplying illegal values will throw errors in the future', warningType);
@@ -2311,24 +2328,31 @@ export class Characteristic extends EventEmitter {
2311
2328
  }
2312
2329
  if (typeof value !== 'string') {
2313
2330
  this.characteristicWarning(`characteristic value expected string and received ${typeof value}`, warningType);
2331
+ // keep what is there. Turning the value into text would store the words "undefined" or "null".
2314
2332
  value = typeof this.value === 'string'
2315
2333
  ? this.value
2316
- : `${value}`;
2334
+ : '';
2317
2335
  }
2318
2336
  // mirrors the case value = null at the beginning
2319
2337
  if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) {
2320
- this.characteristicWarning(`[${this.displayName}] characteristic must have a length of more than 1 character otherwise`
2321
- + ` HomeKit will reject this accessory, ignoring new value ${warningType}`);
2338
+ this.characteristicWarning('characteristic must have a length of more than 1 character otherwise'
2339
+ + ' HomeKit will reject this accessory, ignoring new value', warningType);
2322
2340
  return this.value; // just return the current value
2323
2341
  }
2324
2342
  const maxLength = this.props.maxLen ?? 64; // default is 64 (max is 256 which is set in setProps)
2325
2343
  if (value.length > maxLength) {
2326
2344
  this.characteristicWarning(`characteristic was supplied illegal value: string '${value}' exceeded max length of ${maxLength}`, warningType);
2327
2345
  value = value.substring(0, maxLength);
2346
+ // an emoji (and any character past U+FFFF) takes two UTF-16 code units: when the cut fell between them,
2347
+ // drop the first half too, as half a character is not valid text
2348
+ const last = value.charCodeAt(value.length - 1);
2349
+ if (last >= 0xD800 && last <= 0xDBFF) {
2350
+ value = value.substring(0, value.length - 1);
2351
+ }
2328
2352
  }
2329
2353
  return value;
2330
2354
  }
2331
- case "data" /* Formats.DATA */:
2355
+ case Formats.DATA:
2332
2356
  if (typeof value !== 'string') {
2333
2357
  throw new TypeError('characteristic with DATA format must have string value');
2334
2358
  }
@@ -2337,7 +2361,7 @@ export class Characteristic extends EventEmitter {
2337
2361
  throw new Error('characteristic with DATA format exceeds specified maxDataLen');
2338
2362
  }
2339
2363
  return value;
2340
- case "tlv8" /* Formats.TLV8 */:
2364
+ case Formats.TLV8:
2341
2365
  if (value === undefined) {
2342
2366
  this.characteristicWarning('characteristic was supplied illegal value: undefined', warningType);
2343
2367
  return this.value;
@@ -2346,7 +2370,7 @@ export class Characteristic extends EventEmitter {
2346
2370
  }
2347
2371
  // hopefully it shouldn't get to this point
2348
2372
  if (value === undefined) {
2349
- this.characteristicWarning('characteristic was supplied illegal value: undefined', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
2373
+ this.characteristicWarning('characteristic was supplied illegal value: undefined', CharacteristicWarningType.ERROR_MESSAGE);
2350
2374
  return this.value;
2351
2375
  }
2352
2376
  return value;
@@ -2368,10 +2392,10 @@ export class Characteristic extends EventEmitter {
2368
2392
  * (see {@link validateUserInput}), and on something like {@link Characteristic.PasswordSetting} that value is the secret itself, so those keep the
2369
2393
  * long-standing behaviour of going nowhere until an accessory is listening.
2370
2394
  */
2371
- characteristicWarning(message, type = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */,
2395
+ characteristicWarning(message, type = CharacteristicWarningType.WARN_MESSAGE,
2372
2396
  // eslint-disable-next-line unicorn/error-message -- only here to capture the stack
2373
2397
  stack = new Error().stack, reportWhenUnheard = false) {
2374
- const heard = this.emit("characteristic-warning" /* CharacteristicEventTypes.CHARACTERISTIC_WARNING */, type, message, stack);
2398
+ const heard = this.emit(CharacteristicEventTypes.CHARACTERISTIC_WARNING, type, message, stack);
2375
2399
  if (!heard && reportWhenUnheard) {
2376
2400
  // The stack the subscribers would have received goes with it: a characteristic with no service carries no accessory or service name, so it is
2377
2401
  // the only thing that locates the fault.
@@ -2394,23 +2418,30 @@ export class Characteristic extends EventEmitter {
2394
2418
  * @private
2395
2419
  */
2396
2420
  replaceBy(characteristic) {
2397
- this.props = characteristic.props;
2421
+ // a copy, lists included: otherwise a later setProps() on one of the two would change the other as well
2422
+ this.props = {
2423
+ ...characteristic.props,
2424
+ perms: [...characteristic.props.perms],
2425
+ validValues: characteristic.props.validValues && [...characteristic.props.validValues],
2426
+ validValueRanges: characteristic.props.validValueRanges && [...characteristic.props.validValueRanges],
2427
+ adminOnlyAccess: characteristic.props.adminOnlyAccess && [...characteristic.props.adminOnlyAccess],
2428
+ };
2398
2429
  this.updateValue(characteristic.value);
2399
- const getListeners = characteristic.listeners("get" /* CharacteristicEventTypes.GET */);
2430
+ const getListeners = characteristic.listeners(CharacteristicEventTypes.GET);
2400
2431
  if (getListeners.length) {
2401
2432
  // the callback can only be called once, so we remove all old listeners
2402
- this.removeAllListeners("get" /* CharacteristicEventTypes.GET */);
2403
- getListeners.forEach(listener => this.addListener("get" /* CharacteristicEventTypes.GET */, listener));
2433
+ this.removeAllListeners(CharacteristicEventTypes.GET);
2434
+ getListeners.forEach(listener => this.addListener(CharacteristicEventTypes.GET, listener));
2404
2435
  }
2405
2436
  this.removeOnGet();
2406
2437
  if (characteristic.getHandler) {
2407
2438
  this.onGet(characteristic.getHandler);
2408
2439
  }
2409
- const setListeners = characteristic.listeners("set" /* CharacteristicEventTypes.SET */);
2440
+ const setListeners = characteristic.listeners(CharacteristicEventTypes.SET);
2410
2441
  if (setListeners.length) {
2411
2442
  // the callback can only be called once, so we remove all old listeners
2412
- this.removeAllListeners("set" /* CharacteristicEventTypes.SET */);
2413
- setListeners.forEach(listener => this.addListener("set" /* CharacteristicEventTypes.SET */, listener));
2443
+ this.removeAllListeners(CharacteristicEventTypes.SET);
2444
+ setListeners.forEach(listener => this.addListener(CharacteristicEventTypes.SET, listener));
2414
2445
  }
2415
2446
  this.removeOnSet();
2416
2447
  if (characteristic.setHandler) {
@@ -2423,7 +2454,7 @@ export class Characteristic extends EventEmitter {
2423
2454
  */
2424
2455
  async toHAP(connection, contactGetHandlers = true) {
2425
2456
  const object = this.internalHAPRepresentation();
2426
- if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) {
2457
+ if (!this.props.perms.includes(Perms.PAIRED_READ)) {
2427
2458
  object.value = undefined;
2428
2459
  }
2429
2460
  else if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
@@ -2494,9 +2525,12 @@ export class Characteristic extends EventEmitter {
2494
2525
  */
2495
2526
  static deserialize(json) {
2496
2527
  let characteristic;
2497
- if (json.constructorName && json.constructorName.charAt(0).toUpperCase() === json.constructorName.charAt(0)
2498
- && Characteristic[json.constructorName]) { // MUST start with uppercase character and must exist on Characteristic object
2499
- const constructor = Characteristic[json.constructorName];
2528
+ // The saved name must be one of the characteristic definitions, and it must be the SAME characteristic:
2529
+ // a plugin's own class may share its name with a definition (e.g. "Version") while having its own UUID.
2530
+ const constructor = json.constructorName && Object.hasOwn(Characteristic, json.constructorName)
2531
+ ? Characteristic[json.constructorName]
2532
+ : undefined;
2533
+ if (typeof constructor === 'function' && constructor.UUID === json.UUID) {
2500
2534
  characteristic = new constructor();
2501
2535
  characteristic.displayName = json.displayName;
2502
2536
  characteristic.setProps(json.props);