@homebridge/hap-nodejs 2.3.1-beta.0 → 2.3.1-beta.2

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 (254) 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 +49 -25
  13. package/dist/lib/Accessory.js +275 -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 +40 -21
  21. package/dist/lib/Characteristic.js +207 -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 +16 -12
  27. package/dist/lib/Service.js +58 -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 +35 -1
  66. package/dist/lib/definitions/CharacteristicDefinitions.js +649 -568
  67. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  68. package/dist/lib/definitions/ServiceDefinitions.d.ts +7 -1
  69. package/dist/lib/definitions/ServiceDefinitions.js +16 -1
  70. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  71. package/dist/lib/definitions/index.d.ts +0 -1
  72. package/dist/lib/gen/HomeKit.d.ts +0 -1
  73. package/dist/lib/model/AccessoryInfo.d.ts +5 -6
  74. package/dist/lib/model/AccessoryInfo.js +23 -19
  75. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  76. package/dist/lib/model/ControllerStorage.d.ts +11 -5
  77. package/dist/lib/model/ControllerStorage.js +34 -8
  78. package/dist/lib/model/ControllerStorage.js.map +1 -1
  79. package/dist/lib/model/HAPFileStorage.d.ts +20 -2
  80. package/dist/lib/model/HAPFileStorage.js +59 -10
  81. package/dist/lib/model/HAPFileStorage.js.map +1 -1
  82. package/dist/lib/model/HAPStorage.d.ts +0 -1
  83. package/dist/lib/model/HAPStorage.js +6 -3
  84. package/dist/lib/model/HAPStorage.js.map +1 -1
  85. package/dist/lib/model/IdentifierCache.d.ts +2 -3
  86. package/dist/lib/model/IdentifierCache.js +26 -13
  87. package/dist/lib/model/IdentifierCache.js.map +1 -1
  88. package/dist/lib/tv/AccessControlManagement.d.ts +6 -7
  89. package/dist/lib/tv/AccessControlManagement.js +13 -19
  90. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  91. package/dist/lib/util/checkName.d.ts +1 -2
  92. package/dist/lib/util/checkName.js.map +1 -1
  93. package/dist/lib/util/clone.d.ts +0 -1
  94. package/dist/lib/util/clone.js.map +1 -1
  95. package/dist/lib/util/color-utils.d.ts +1 -2
  96. package/dist/lib/util/color-utils.js +1 -1
  97. package/dist/lib/util/errors.d.ts +4 -0
  98. package/dist/lib/util/errors.js +15 -0
  99. package/dist/lib/util/errors.js.map +1 -0
  100. package/dist/lib/util/eventedhttp.d.ts +63 -19
  101. package/dist/lib/util/eventedhttp.js +170 -48
  102. package/dist/lib/util/eventedhttp.js.map +1 -1
  103. package/dist/lib/util/hapCrypto.d.ts +1 -2
  104. package/dist/lib/util/hapCrypto.js +6 -7
  105. package/dist/lib/util/hapCrypto.js.map +1 -1
  106. package/dist/lib/util/hapStatusError.d.ts +0 -1
  107. package/dist/lib/util/hapStatusError.js +1 -1
  108. package/dist/lib/util/hapStatusError.js.map +1 -1
  109. package/dist/lib/util/net-utils.d.ts +1 -2
  110. package/dist/lib/util/net-utils.js +6 -7
  111. package/dist/lib/util/net-utils.js.map +1 -1
  112. package/dist/lib/util/once.d.ts +0 -1
  113. package/dist/lib/util/promise-utils.d.ts +1 -2
  114. package/dist/lib/util/promise-utils.js +2 -1
  115. package/dist/lib/util/promise-utils.js.map +1 -1
  116. package/dist/lib/util/request-util.d.ts +4 -4
  117. package/dist/lib/util/request-util.js +29 -28
  118. package/dist/lib/util/request-util.js.map +1 -1
  119. package/dist/lib/util/time.d.ts +1 -2
  120. package/dist/lib/util/time.js.map +1 -1
  121. package/dist/lib/util/tlv.d.ts +4 -4
  122. package/dist/lib/util/tlv.js +16 -5
  123. package/dist/lib/util/tlv.js.map +1 -1
  124. package/dist/lib/util/uuid.d.ts +5 -2
  125. package/dist/lib/util/uuid.js +6 -0
  126. package/dist/lib/util/uuid.js.map +1 -1
  127. package/dist/types.d.ts +20 -17
  128. package/dist/types.js +0 -1
  129. package/dist/types.js.map +1 -1
  130. package/package.json +8 -14
  131. package/dist/accessories/AirConditioner_accessory.d.ts +0 -2
  132. package/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
  133. package/dist/accessories/AirConditioner_accessory.js +0 -126
  134. package/dist/accessories/AirConditioner_accessory.js.map +0 -1
  135. package/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
  136. package/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
  137. package/dist/accessories/AppleTVRemote_accessory.js +0 -146
  138. package/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
  139. package/dist/accessories/Camera_accessory.d.ts +0 -2
  140. package/dist/accessories/Camera_accessory.d.ts.map +0 -1
  141. package/dist/accessories/Camera_accessory.js +0 -562
  142. package/dist/accessories/Camera_accessory.js.map +0 -1
  143. package/dist/accessories/Fan_accessory.d.ts +0 -2
  144. package/dist/accessories/Fan_accessory.d.ts.map +0 -1
  145. package/dist/accessories/Fan_accessory.js +0 -71
  146. package/dist/accessories/Fan_accessory.js.map +0 -1
  147. package/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
  148. package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
  149. package/dist/accessories/GarageDoorOpener_accessory.js +0 -76
  150. package/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
  151. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
  152. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
  153. package/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -103
  154. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
  155. package/dist/accessories/Light_accessory.d.ts +0 -2
  156. package/dist/accessories/Light_accessory.d.ts.map +0 -1
  157. package/dist/accessories/Light_accessory.js +0 -143
  158. package/dist/accessories/Light_accessory.js.map +0 -1
  159. package/dist/accessories/Lock_accessory.d.ts +0 -2
  160. package/dist/accessories/Lock_accessory.d.ts.map +0 -1
  161. package/dist/accessories/Lock_accessory.js +0 -74
  162. package/dist/accessories/Lock_accessory.js.map +0 -1
  163. package/dist/accessories/MotionSensor_accessory.d.ts +0 -2
  164. package/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
  165. package/dist/accessories/MotionSensor_accessory.js +0 -43
  166. package/dist/accessories/MotionSensor_accessory.js.map +0 -1
  167. package/dist/accessories/Outlet_accessory.d.ts +0 -2
  168. package/dist/accessories/Outlet_accessory.d.ts.map +0 -1
  169. package/dist/accessories/Outlet_accessory.js +0 -77
  170. package/dist/accessories/Outlet_accessory.js.map +0 -1
  171. package/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
  172. package/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
  173. package/dist/accessories/SmartSpeaker_accessory.js +0 -42
  174. package/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
  175. package/dist/accessories/Sprinkler_accessory.d.ts +0 -2
  176. package/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
  177. package/dist/accessories/Sprinkler_accessory.js +0 -126
  178. package/dist/accessories/Sprinkler_accessory.js.map +0 -1
  179. package/dist/accessories/TV_accessory.d.ts +0 -2
  180. package/dist/accessories/TV_accessory.d.ts.map +0 -1
  181. package/dist/accessories/TV_accessory.js +0 -99
  182. package/dist/accessories/TV_accessory.js.map +0 -1
  183. package/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
  184. package/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
  185. package/dist/accessories/TemperatureSensor_accessory.js +0 -42
  186. package/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
  187. package/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
  188. package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
  189. package/dist/accessories/Wi-FiRouter_accessory.js +0 -14
  190. package/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
  191. package/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
  192. package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
  193. package/dist/accessories/Wi-FiSatellite_accessory.js +0 -16
  194. package/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
  195. package/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
  196. package/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
  197. package/dist/accessories/gstreamer-audioProducer.js +0 -145
  198. package/dist/accessories/gstreamer-audioProducer.js.map +0 -1
  199. package/dist/accessories/types.d.ts.map +0 -1
  200. package/dist/hap.d.ts.map +0 -1
  201. package/dist/index.d.ts.map +0 -1
  202. package/dist/internal-types.d.ts.map +0 -1
  203. package/dist/lib/Accessory.d.ts.map +0 -1
  204. package/dist/lib/Advertiser.d.ts.map +0 -1
  205. package/dist/lib/Bridge.d.ts.map +0 -1
  206. package/dist/lib/Characteristic.d.ts.map +0 -1
  207. package/dist/lib/HAPServer.d.ts.map +0 -1
  208. package/dist/lib/Service.d.ts.map +0 -1
  209. package/dist/lib/camera/RTPProxy.d.ts.map +0 -1
  210. package/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
  211. package/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
  212. package/dist/lib/camera/index.d.ts.map +0 -1
  213. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
  214. package/dist/lib/controller/CameraController.d.ts.map +0 -1
  215. package/dist/lib/controller/Controller.d.ts.map +0 -1
  216. package/dist/lib/controller/DoorbellController.d.ts.map +0 -1
  217. package/dist/lib/controller/RemoteController.d.ts.map +0 -1
  218. package/dist/lib/controller/index.d.ts.map +0 -1
  219. package/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
  220. package/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
  221. package/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
  222. package/dist/lib/datastream/index.d.ts.map +0 -1
  223. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
  224. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
  225. package/dist/lib/definitions/generate-definitions.d.ts +0 -34
  226. package/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
  227. package/dist/lib/definitions/generate-definitions.js +0 -624
  228. package/dist/lib/definitions/generate-definitions.js.map +0 -1
  229. package/dist/lib/definitions/generator-configuration.d.ts +0 -22
  230. package/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
  231. package/dist/lib/definitions/generator-configuration.js +0 -674
  232. package/dist/lib/definitions/generator-configuration.js.map +0 -1
  233. package/dist/lib/definitions/index.d.ts.map +0 -1
  234. package/dist/lib/gen/HomeKit.d.ts.map +0 -1
  235. package/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
  236. package/dist/lib/model/ControllerStorage.d.ts.map +0 -1
  237. package/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
  238. package/dist/lib/model/HAPStorage.d.ts.map +0 -1
  239. package/dist/lib/model/IdentifierCache.d.ts.map +0 -1
  240. package/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
  241. package/dist/lib/util/checkName.d.ts.map +0 -1
  242. package/dist/lib/util/clone.d.ts.map +0 -1
  243. package/dist/lib/util/color-utils.d.ts.map +0 -1
  244. package/dist/lib/util/eventedhttp.d.ts.map +0 -1
  245. package/dist/lib/util/hapCrypto.d.ts.map +0 -1
  246. package/dist/lib/util/hapStatusError.d.ts.map +0 -1
  247. package/dist/lib/util/net-utils.d.ts.map +0 -1
  248. package/dist/lib/util/once.d.ts.map +0 -1
  249. package/dist/lib/util/promise-utils.d.ts.map +0 -1
  250. package/dist/lib/util/request-util.d.ts.map +0 -1
  251. package/dist/lib/util/time.d.ts.map +0 -1
  252. package/dist/lib/util/tlv.d.ts.map +0 -1
  253. package/dist/lib/util/uuid.d.ts.map +0 -1
  254. 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
  // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -547,6 +547,10 @@ export class Characteristic extends EventEmitter {
547
547
  * @group Characteristic Definitions
548
548
  */
549
549
  static DisplayOrder;
550
+ /**
551
+ * @group Characteristic Definitions
552
+ */
553
+ static ErrorStatus;
550
554
  /**
551
555
  * @group Characteristic Definitions
552
556
  */
@@ -571,6 +575,10 @@ export class Characteristic extends EventEmitter {
571
575
  * @group Characteristic Definitions
572
576
  */
573
577
  static FirmwareRevision;
578
+ /**
579
+ * @group Characteristic Definitions
580
+ */
581
+ static FirmwareUpdateEnabled;
574
582
  /**
575
583
  * @group Characteristic Definitions
576
584
  */
@@ -974,6 +982,10 @@ export class Characteristic extends EventEmitter {
974
982
  * @group Characteristic Definitions
975
983
  */
976
984
  static ServiceLabelNamespace;
985
+ /**
986
+ * @group Characteristic Definitions
987
+ */
988
+ static SessionTransportEndpointList;
977
989
  /**
978
990
  * @group Characteristic Definitions
979
991
  */
@@ -1223,6 +1235,14 @@ export class Characteristic extends EventEmitter {
1223
1235
  * @group Characteristic Definitions
1224
1236
  */
1225
1237
  static ThirdPartyCameraActive;
1238
+ /**
1239
+ * @group Characteristic Definitions
1240
+ */
1241
+ static ThirdPartyCameraInUse;
1242
+ /**
1243
+ * @group Characteristic Definitions
1244
+ */
1245
+ static ThirdPartyEcosystemEnabled;
1226
1246
  /**
1227
1247
  * @group Characteristic Definitions
1228
1248
  */
@@ -1353,8 +1373,8 @@ export class Characteristic extends EventEmitter {
1353
1373
  this.displayName = displayName;
1354
1374
  this.UUID = UUID;
1355
1375
  this.props = {
1356
- format: "int" /* Formats.INT */,
1357
- perms: ["ev" /* Perms.NOTIFY */],
1376
+ format: Formats.INT,
1377
+ perms: [Perms.NOTIFY],
1358
1378
  };
1359
1379
  this.setProps(props || {}); // ensure sanity checks are called
1360
1380
  }
@@ -1424,6 +1444,7 @@ export class Characteristic extends EventEmitter {
1424
1444
  */
1425
1445
  setProps(props) {
1426
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
1427
1448
  let formatDidChange = false;
1428
1449
  // for every value "null" can be used to reset props, except for required props
1429
1450
  if (props.format) {
@@ -1437,7 +1458,7 @@ export class Characteristic extends EventEmitter {
1437
1458
  */
1438
1459
  if (props.perms) {
1439
1460
  if (!isValidPerms(props.perms)) {
1440
- 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);
1441
1462
  }
1442
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
1443
1464
  * `includes` substring-matches, so a declared `"pr"` would answer true to a paired-read check and quietly grant access, and `push` would throw
@@ -1460,20 +1481,20 @@ export class Characteristic extends EventEmitter {
1460
1481
  props.minValue = undefined;
1461
1482
  }
1462
1483
  else if (!isNumericFormat(this.props.format)) {
1463
- 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);
1464
1485
  props.minValue = undefined;
1465
1486
  }
1466
1487
  else if (typeof props.minValue !== 'number' || !Number.isFinite(props.minValue)) {
1467
- 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);
1468
1489
  props.minValue = undefined;
1469
1490
  }
1470
1491
  else {
1471
1492
  if (props.minValue < numericLowerBound(this.props.format)) {
1472
- 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);
1473
1494
  props.minValue = numericLowerBound(this.props.format);
1474
1495
  }
1475
1496
  else if (props.minValue > numericUpperBound(this.props.format)) {
1476
- 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);
1477
1498
  props.minValue = numericLowerBound(this.props.format);
1478
1499
  }
1479
1500
  }
@@ -1485,20 +1506,20 @@ export class Characteristic extends EventEmitter {
1485
1506
  props.maxValue = undefined;
1486
1507
  }
1487
1508
  else if (!isNumericFormat(this.props.format)) {
1488
- 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);
1489
1510
  props.maxValue = undefined;
1490
1511
  }
1491
1512
  else if (typeof props.maxValue !== 'number' || !Number.isFinite(props.maxValue)) {
1492
- 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);
1493
1514
  props.maxValue = undefined;
1494
1515
  }
1495
1516
  else {
1496
1517
  if (props.maxValue > numericUpperBound(this.props.format)) {
1497
- 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);
1498
1519
  props.maxValue = numericUpperBound(this.props.format);
1499
1520
  }
1500
1521
  else if (props.maxValue < numericLowerBound(this.props.format)) {
1501
- 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);
1502
1523
  props.maxValue = numericUpperBound(this.props.format);
1503
1524
  }
1504
1525
  }
@@ -1509,13 +1530,17 @@ export class Characteristic extends EventEmitter {
1509
1530
  this.props.minStep = undefined;
1510
1531
  }
1511
1532
  else if (!isNumericFormat(this.props.format)) {
1512
- 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.`);
1513
1542
  }
1514
1543
  else {
1515
- if (props.minStep < 1 && isIntegerNumericFormat(this.props.format)) {
1516
- this.characteristicWarning('Characteristic Property `minStep` was set to a value lower than 1, '
1517
- + `this will have no effect on format \`${this.props.format}`);
1518
- }
1519
1544
  this.props.minStep = props.minStep;
1520
1545
  }
1521
1546
  }
@@ -1523,8 +1548,8 @@ export class Characteristic extends EventEmitter {
1523
1548
  if (props.maxLen === null) {
1524
1549
  this.props.maxLen = undefined;
1525
1550
  }
1526
- else if (this.props.format !== "string" /* Formats.STRING */) {
1527
- 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);
1528
1553
  }
1529
1554
  else {
1530
1555
  if (props.maxLen > 256) {
@@ -1538,8 +1563,8 @@ export class Characteristic extends EventEmitter {
1538
1563
  if (props.maxDataLen === null) {
1539
1564
  this.props.maxDataLen = undefined;
1540
1565
  }
1541
- else if (this.props.format !== "data" /* Formats.DATA */) {
1542
- 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);
1543
1568
  }
1544
1569
  else {
1545
1570
  this.props.maxDataLen = props.maxDataLen;
@@ -1576,13 +1601,13 @@ export class Characteristic extends EventEmitter {
1576
1601
  if (this.props.minValue > this.props.maxValue) { // see https://github.com/homebridge/HAP-NodeJS/issues/690
1577
1602
  this.props.minValue = undefined;
1578
1603
  this.props.maxValue = undefined;
1579
- 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'!`);
1580
1605
  }
1581
1606
  }
1582
1607
  // the properties are part of the configuration HomeKit is served, so a published accessory must recompute its configuration number;
1583
1608
  // a call that changes nothing leaves the configuration hash and therefore the number as it was
1584
- this.emit("characteristic-configurationChange" /* CharacteristicEventTypes.CHARACTERISTIC_CONFIGURATION_CHANGE */);
1585
- 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)
1586
1611
  && this.value != null
1587
1612
  && !formatDidChange
1588
1613
  && this.statusCode === HAPStatus.SUCCESS
@@ -1593,8 +1618,8 @@ export class Characteristic extends EventEmitter {
1593
1618
  // - If the format is changed through `setProps` we rely on the user to supply a valid value after the `setProps` call!
1594
1619
  // - If the characteristic is marked as erroneous the value is not considered valid anyway, and we must not remove the `statusCode`.
1595
1620
  // - Special case for `ProgrammableSwitchEvent` where every change in value is considered an event which would result in ghost button presses
1596
- // validateUserInput when called from setProps is intended to clamp value withing allowed range. It is why warnings should not be displayed.
1597
- 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);
1598
1623
  if (correctedValue !== this.value) {
1599
1624
  // we don't want to emit a CHANGE event if the value didn't change at all!
1600
1625
  this.updateValue(correctedValue);
@@ -1612,7 +1637,7 @@ export class Characteristic extends EventEmitter {
1612
1637
  * {@link CharacteristicProps.minStep})
1613
1638
  * And lastly you can specify a range via {@link CharacteristicProps.validValueRanges}
1614
1639
  * Implicitly a valid value range is predefined for characteristics with Format {@link Formats.UINT8}, {@link Formats.UINT16},
1615
- * {@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
1616
1641
  *
1617
1642
  * The method will automatically detect which type of valid values definition is used and provide
1618
1643
  * the correct Iterator for that case.
@@ -1651,8 +1676,8 @@ export class Characteristic extends EventEmitter {
1651
1676
  * @param handler - Handler called to check additional authorization data.
1652
1677
  */
1653
1678
  setupAdditionalAuthorization(handler) {
1654
- if (!this.props.perms.includes("aa" /* Perms.ADDITIONAL_AUTHORIZATION */)) {
1655
- 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);
1656
1681
  }
1657
1682
  this.additionalAuthorizationHandler = handler;
1658
1683
  }
@@ -1674,15 +1699,17 @@ export class Characteristic extends EventEmitter {
1674
1699
  value = this.validateUserInput(value);
1675
1700
  }
1676
1701
  catch (error) {
1677
- 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));
1678
1703
  if (callback) {
1679
- callback(error);
1704
+ callback(error instanceof Error
1705
+ ? error
1706
+ : new Error(String(error)));
1680
1707
  }
1681
1708
  return this;
1682
1709
  }
1683
1710
  this.handleSetRequest(value, undefined, context).then((value) => {
1684
1711
  if (callback) {
1685
- if (value) { // possible write response
1712
+ if (value != null) { // possible write response, which may well be 0, false or an empty string
1686
1713
  callback(null, value);
1687
1714
  }
1688
1715
  else {
@@ -1714,7 +1741,7 @@ export class Characteristic extends EventEmitter {
1714
1741
  value = this.validateUserInput(value);
1715
1742
  }
1716
1743
  catch (error) {
1717
- 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));
1718
1745
  if (callback) {
1719
1746
  callback();
1720
1747
  }
@@ -1726,11 +1753,11 @@ export class Characteristic extends EventEmitter {
1726
1753
  if (callback) {
1727
1754
  callback();
1728
1755
  }
1729
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1756
+ this.emit(CharacteristicEventTypes.CHANGE, {
1730
1757
  originator: undefined,
1731
1758
  oldValue,
1732
1759
  newValue: value,
1733
- reason: "update" /* ChangeReason.UPDATE */,
1760
+ reason: ChangeReason.UPDATE,
1734
1761
  context,
1735
1762
  });
1736
1763
  return this; // for chaining
@@ -1745,28 +1772,28 @@ export class Characteristic extends EventEmitter {
1745
1772
  * @param context - Passed to the {@link CharacteristicEventTypes.CHANGE} event handler.
1746
1773
  */
1747
1774
  sendEventNotification(value, context) {
1775
+ value = this.validateUserInput(value); // may throw, and then nothing has changed
1748
1776
  this.statusCode = HAPStatus.SUCCESS;
1749
- value = this.validateUserInput(value);
1750
1777
  const oldValue = this.value;
1751
1778
  this.value = value;
1752
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1779
+ this.emit(CharacteristicEventTypes.CHANGE, {
1753
1780
  originator: undefined,
1754
1781
  oldValue,
1755
1782
  newValue: value,
1756
- reason: "event" /* ChangeReason.EVENT */,
1783
+ reason: ChangeReason.EVENT,
1757
1784
  context,
1758
1785
  });
1759
1786
  return this; // for chaining
1760
1787
  }
1761
1788
  /**
1762
- * 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.
1763
1790
  *
1764
1791
  * @param connection - The HAP connection from which the request originated from.
1765
- * @param context - Deprecated parameter. There for backwards compatibility.
1792
+ * @param context - Passed on to the handler and to the listeners of the change event.
1766
1793
  * @private
1767
1794
  */
1768
1795
  async handleGetRequest(connection, context) {
1769
- 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
1770
1797
  throw HAPStatus.WRITE_ONLY_CHARACTERISTIC;
1771
1798
  }
1772
1799
  if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
@@ -1774,7 +1801,7 @@ export class Characteristic extends EventEmitter {
1774
1801
  return null;
1775
1802
  }
1776
1803
  if (this.getHandler) {
1777
- if (this.listeners("get" /* CharacteristicEventTypes.GET */).length > 0) {
1804
+ if (this.listenerCount(CharacteristicEventTypes.GET) > 0) {
1778
1805
  this.characteristicWarning('Ignoring on(\'get\') handler as onGet handler was defined instead');
1779
1806
  }
1780
1807
  try {
@@ -1784,18 +1811,18 @@ export class Characteristic extends EventEmitter {
1784
1811
  value = this.validateUserInput(value);
1785
1812
  }
1786
1813
  catch (error) {
1787
- 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));
1788
1815
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1789
1816
  return Promise.reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1790
1817
  }
1791
1818
  const oldValue = this.value;
1792
1819
  this.value = value;
1793
1820
  if (oldValue !== value) { // emit a change event if necessary
1794
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1821
+ this.emit(CharacteristicEventTypes.CHANGE, {
1795
1822
  originator: connection,
1796
1823
  oldValue,
1797
1824
  newValue: value,
1798
- reason: "read" /* ChangeReason.READ */,
1825
+ reason: ChangeReason.READ,
1799
1826
  context,
1800
1827
  });
1801
1828
  }
@@ -1810,13 +1837,13 @@ export class Characteristic extends EventEmitter {
1810
1837
  this.statusCode = error.hapStatus;
1811
1838
  }
1812
1839
  else {
1813
- 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));
1814
1841
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1815
1842
  }
1816
1843
  throw this.statusCode;
1817
1844
  }
1818
1845
  }
1819
- if (this.listeners("get" /* CharacteristicEventTypes.GET */).length === 0) {
1846
+ if (this.listenerCount(CharacteristicEventTypes.GET) === 0) {
1820
1847
  if (this.statusCode) {
1821
1848
  throw this.statusCode;
1822
1849
  }
@@ -1824,13 +1851,13 @@ export class Characteristic extends EventEmitter {
1824
1851
  return this.validateUserInput(this.value);
1825
1852
  }
1826
1853
  catch (error) {
1827
- 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));
1828
1855
  return Promise.reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1829
1856
  }
1830
1857
  }
1831
1858
  return new Promise((resolve, reject) => {
1832
1859
  try {
1833
- this.emit("get" /* CharacteristicEventTypes.GET */, once((status, value) => {
1860
+ this.emit(CharacteristicEventTypes.GET, once((status, value) => {
1834
1861
  if (status) {
1835
1862
  if (typeof status === 'number') {
1836
1863
  const hapStatusError = new HapStatusError(status);
@@ -1852,7 +1879,7 @@ export class Characteristic extends EventEmitter {
1852
1879
  }
1853
1880
  catch (error) {
1854
1881
  // this runs inside the plugin's callback; a throw would land in the plugin and leave the request unanswered
1855
- 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));
1856
1883
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1857
1884
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1858
1885
  return;
@@ -1861,36 +1888,35 @@ export class Characteristic extends EventEmitter {
1861
1888
  this.value = value;
1862
1889
  resolve(value);
1863
1890
  if (oldValue !== value) { // emit a change event if necessary
1864
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1891
+ this.emit(CharacteristicEventTypes.CHANGE, {
1865
1892
  originator: connection,
1866
1893
  oldValue,
1867
1894
  newValue: value,
1868
- reason: "read" /* ChangeReason.READ */,
1895
+ reason: ChangeReason.READ,
1869
1896
  context,
1870
1897
  });
1871
1898
  }
1872
1899
  }), context, connection);
1873
1900
  }
1874
1901
  catch (error) {
1875
- 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));
1876
1903
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1877
1904
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1878
1905
  }
1879
1906
  });
1880
1907
  }
1881
1908
  /**
1882
- * 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.
1883
1910
  *
1884
1911
  * @param value - The updated value
1885
1912
  * @param connection - The connection from which the request originated from
1886
- * @param context - Deprecated parameter. There for backwards compatibility.
1913
+ * @param context - Passed on to the handler and to the listeners of the change event.
1887
1914
  * @returns Promise resolve to void in normal operation. When characteristic supports write-response, HAP
1888
1915
  * requests a write-response and the set handler returns a write-response value, the respective
1889
1916
  * write response value is resolved.
1890
1917
  * @private
1891
1918
  */
1892
1919
  async handleSetRequest(value, connection, context) {
1893
- this.statusCode = HAPStatus.SUCCESS;
1894
1920
  if (connection !== undefined) {
1895
1921
  // if connection is undefined, the set "request" comes from the setValue method.
1896
1922
  // for setValue a value of "null" is allowed and checked via validateUserInput.
@@ -1898,32 +1924,34 @@ export class Characteristic extends EventEmitter {
1898
1924
  value = this.validateClientSuppliedValue(value);
1899
1925
  }
1900
1926
  catch (e) {
1901
- debug(`[${this.displayName}]`, e.message);
1927
+ debug(`[${this.displayName}]`, errorMessage(e));
1902
1928
  return Promise.reject(HAPStatus.INVALID_VALUE_IN_REQUEST);
1903
1929
  }
1904
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;
1905
1933
  const oldValue = this.value;
1906
1934
  if (this.setHandler) {
1907
- if (this.listeners("set" /* CharacteristicEventTypes.SET */).length > 0) {
1935
+ if (this.listenerCount(CharacteristicEventTypes.SET) > 0) {
1908
1936
  this.characteristicWarning('Ignoring on(\'set\') handler as onSet handler was defined instead');
1909
1937
  }
1910
1938
  try {
1911
1939
  const writeResponse = await this.setHandler(value, context, connection);
1912
1940
  this.statusCode = HAPStatus.SUCCESS;
1913
- if (writeResponse != null && this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
1941
+ if (writeResponse != null && this.props.perms.includes(Perms.WRITE_RESPONSE)) {
1914
1942
  this.value = this.validateUserInput(writeResponse);
1915
1943
  return this.value;
1916
1944
  }
1917
1945
  else {
1918
1946
  if (writeResponse != null) {
1919
- 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);
1920
1948
  }
1921
1949
  this.value = value;
1922
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1950
+ this.emit(CharacteristicEventTypes.CHANGE, {
1923
1951
  originator: connection,
1924
1952
  oldValue,
1925
1953
  newValue: value,
1926
- reason: "write" /* ChangeReason.WRITE */,
1954
+ reason: ChangeReason.WRITE,
1927
1955
  context,
1928
1956
  });
1929
1957
  return;
@@ -1938,19 +1966,19 @@ export class Characteristic extends EventEmitter {
1938
1966
  this.statusCode = error.hapStatus;
1939
1967
  }
1940
1968
  else {
1941
- 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));
1942
1970
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1943
1971
  }
1944
1972
  throw this.statusCode;
1945
1973
  }
1946
1974
  }
1947
- if (this.listeners("set" /* CharacteristicEventTypes.SET */).length === 0) {
1975
+ if (this.listenerCount(CharacteristicEventTypes.SET) === 0) {
1948
1976
  this.value = value;
1949
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
1977
+ this.emit(CharacteristicEventTypes.CHANGE, {
1950
1978
  originator: connection,
1951
1979
  oldValue,
1952
1980
  newValue: value,
1953
- reason: "write" /* ChangeReason.WRITE */,
1981
+ reason: ChangeReason.WRITE,
1954
1982
  context,
1955
1983
  });
1956
1984
  return Promise.resolve();
@@ -1958,7 +1986,7 @@ export class Characteristic extends EventEmitter {
1958
1986
  else {
1959
1987
  return new Promise((resolve, reject) => {
1960
1988
  try {
1961
- this.emit("set" /* CharacteristicEventTypes.SET */, value, once((status, writeResponse) => {
1989
+ this.emit(CharacteristicEventTypes.SET, value, once((status, writeResponse) => {
1962
1990
  if (status) {
1963
1991
  if (typeof status === 'number') {
1964
1992
  const hapStatusError = new HapStatusError(status);
@@ -1975,14 +2003,14 @@ export class Characteristic extends EventEmitter {
1975
2003
  return;
1976
2004
  }
1977
2005
  this.statusCode = HAPStatus.SUCCESS;
1978
- if (writeResponse != null && this.props.perms.includes("wr" /* Perms.WRITE_RESPONSE */)) {
2006
+ if (writeResponse != null && this.props.perms.includes(Perms.WRITE_RESPONSE)) {
1979
2007
  // support write response simply by letting the implementor pass the response as second argument to the callback
1980
2008
  try {
1981
2009
  this.value = this.validateUserInput(writeResponse);
1982
2010
  }
1983
2011
  catch (error) {
1984
2012
  // this runs inside the plugin's callback; a throw would land in the plugin and leave the request unanswered
1985
- 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));
1986
2014
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
1987
2015
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1988
2016
  return;
@@ -1991,22 +2019,22 @@ export class Characteristic extends EventEmitter {
1991
2019
  }
1992
2020
  else {
1993
2021
  if (writeResponse != null) {
1994
- 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);
1995
2023
  }
1996
2024
  this.value = value;
1997
2025
  resolve();
1998
- this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
2026
+ this.emit(CharacteristicEventTypes.CHANGE, {
1999
2027
  originator: connection,
2000
2028
  oldValue,
2001
2029
  newValue: value,
2002
- reason: "write" /* ChangeReason.WRITE */,
2030
+ reason: ChangeReason.WRITE,
2003
2031
  context,
2004
2032
  });
2005
2033
  }
2006
2034
  }), context, connection);
2007
2035
  }
2008
2036
  catch (error) {
2009
- 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));
2010
2038
  this.statusCode = HAPStatus.SERVICE_COMMUNICATION_FAILURE;
2011
2039
  reject(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
2012
2040
  }
@@ -2019,12 +2047,12 @@ export class Characteristic extends EventEmitter {
2019
2047
  */
2020
2048
  subscribe() {
2021
2049
  if (this.subscriptions === 0) {
2022
- this.emit("subscribe" /* CharacteristicEventTypes.SUBSCRIBE */);
2050
+ this.emit(CharacteristicEventTypes.SUBSCRIBE);
2023
2051
  }
2024
2052
  this.subscriptions++;
2025
2053
  }
2026
2054
  /**
2027
- * 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
2028
2056
  * which was subscribed to this characteristic disconnects.
2029
2057
  * @private
2030
2058
  */
@@ -2033,15 +2061,15 @@ export class Characteristic extends EventEmitter {
2033
2061
  this.subscriptions--;
2034
2062
  this.subscriptions = Math.max(this.subscriptions, 0);
2035
2063
  if (wasOne) {
2036
- this.emit("unsubscribe" /* CharacteristicEventTypes.UNSUBSCRIBE */);
2064
+ this.emit(CharacteristicEventTypes.UNSUBSCRIBE);
2037
2065
  }
2038
2066
  }
2039
2067
  getDefaultValue() {
2040
2068
  // noinspection JSDeprecatedSymbols
2041
2069
  switch (this.props.format) {
2042
- case "bool" /* Formats.BOOL */:
2070
+ case Formats.BOOL:
2043
2071
  return false;
2044
- case "string" /* Formats.STRING */:
2072
+ case Formats.STRING:
2045
2073
  switch (this.UUID) {
2046
2074
  case Characteristic.Manufacturer.UUID:
2047
2075
  return 'Default-Manufacturer';
@@ -2054,16 +2082,16 @@ export class Characteristic extends EventEmitter {
2054
2082
  default:
2055
2083
  return '';
2056
2084
  }
2057
- case "data" /* Formats.DATA */:
2085
+ case Formats.DATA:
2058
2086
  return ''; // who knows!
2059
- case "tlv8" /* Formats.TLV8 */:
2087
+ case Formats.TLV8:
2060
2088
  return ''; // who knows!
2061
- case "int" /* Formats.INT */:
2062
- case "float" /* Formats.FLOAT */:
2063
- case "uint8" /* Formats.UINT8 */:
2064
- case "uint16" /* Formats.UINT16 */:
2065
- case "uint32" /* Formats.UINT32 */:
2066
- 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:
2067
2095
  switch (this.UUID) {
2068
2096
  case Characteristic.CurrentTemperature.UUID:
2069
2097
  return 0; // some existing integrations expect this to be 0 by default
@@ -2092,7 +2120,7 @@ export class Characteristic extends EventEmitter {
2092
2120
  throw new Error(`Client supplied invalid value for ${this.props.format}: ${value}`);
2093
2121
  }
2094
2122
  switch (this.props.format) {
2095
- case "bool" /* Formats.BOOL */: {
2123
+ case Formats.BOOL: {
2096
2124
  if (typeof value === 'boolean') {
2097
2125
  return value;
2098
2126
  }
@@ -2101,18 +2129,21 @@ export class Characteristic extends EventEmitter {
2101
2129
  }
2102
2130
  throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2103
2131
  }
2104
- case "int" /* Formats.INT */:
2105
- case "float" /* Formats.FLOAT */:
2106
- case "uint8" /* Formats.UINT8 */:
2107
- case "uint16" /* Formats.UINT16 */:
2108
- case "uint32" /* Formats.UINT32 */:
2109
- 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: {
2110
2138
  if (typeof value === 'boolean') {
2111
2139
  value = value ? 1 : 0;
2112
2140
  }
2113
2141
  if (typeof value !== 'number' || !Number.isFinite(value)) {
2114
2142
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2115
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
+ }
2116
2147
  const numericMin = maxWithUndefined(this.props.minValue, numericLowerBound(this.props.format));
2117
2148
  const numericMax = minWithUndefined(this.props.maxValue, numericUpperBound(this.props.format));
2118
2149
  if (typeof numericMin === 'number' && value < numericMin) {
@@ -2134,7 +2165,7 @@ export class Characteristic extends EventEmitter {
2134
2165
  }
2135
2166
  return value;
2136
2167
  }
2137
- case "string" /* Formats.STRING */: {
2168
+ case Formats.STRING: {
2138
2169
  if (typeof value !== 'string') {
2139
2170
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2140
2171
  }
@@ -2144,7 +2175,7 @@ export class Characteristic extends EventEmitter {
2144
2175
  }
2145
2176
  return value;
2146
2177
  }
2147
- case "data" /* Formats.DATA */: {
2178
+ case Formats.DATA: {
2148
2179
  if (typeof value !== 'string') {
2149
2180
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2150
2181
  }
@@ -2155,7 +2186,7 @@ export class Characteristic extends EventEmitter {
2155
2186
  }
2156
2187
  return value;
2157
2188
  }
2158
- case "tlv8" /* Formats.TLV8 */:
2189
+ case Formats.TLV8:
2159
2190
  if (typeof value !== 'string') {
2160
2191
  throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
2161
2192
  }
@@ -2171,24 +2202,24 @@ export class Characteristic extends EventEmitter {
2171
2202
  * @param value - The value received from the API call
2172
2203
  * @param warningType - Optionally defines the warning type to use when raising a {@link CharacteristicEventTypes.CHARACTERISTIC_WARNING}.
2173
2204
  */
2174
- validateUserInput(value, warningType = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */) {
2205
+ validateUserInput(value, warningType = CharacteristicWarningType.WARN_MESSAGE) {
2175
2206
  if (value === null) {
2176
2207
  if (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID) { // mirrors the statement in case: Formats.STRING
2177
- 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);
2178
2209
  return this.value; // don't change the value
2179
2210
  }
2180
- 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) {
2181
2212
  return value; // TLV8 and DATA formats are allowed to have null as a value
2182
2213
  }
2183
2214
  /**
2184
2215
  * A short disclaimer here.
2185
2216
  * null is actually a perfectly valid value for characteristics to have.
2186
2217
  * The Home app will show "no response" for some characteristics for which it can't handle null
2187
- * but ultimately its valid and the developers decision what the return.
2188
- * BUT: out of history hap-nodejs did replace null with the last known value and thus
2189
- * 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.
2190
2221
  * As an intermediate step we kept the behavior but added a warning printed to the console.
2191
- * 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!
2192
2223
  */
2193
2224
  if (this.UUID.endsWith(BASE_UUID)) { // we have an apple defined characteristic (at least assuming nobody else uses the UUID namespace)
2194
2225
  if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
@@ -2201,12 +2232,12 @@ export class Characteristic extends EventEmitter {
2201
2232
  }
2202
2233
  }
2203
2234
  else {
2204
- // we currently allow null for any non-custom defined characteristics
2235
+ // we currently allow null for any custom defined characteristics
2205
2236
  return value;
2206
2237
  }
2207
2238
  }
2208
2239
  switch (this.props.format) {
2209
- case "bool" /* Formats.BOOL */: {
2240
+ case Formats.BOOL: {
2210
2241
  if (typeof value === 'boolean') {
2211
2242
  return value;
2212
2243
  }
@@ -2219,17 +2250,17 @@ export class Characteristic extends EventEmitter {
2219
2250
  this.characteristicWarning(`characteristic value expected boolean and received ${typeof value}`, warningType);
2220
2251
  return false;
2221
2252
  }
2222
- case "int" /* Formats.INT */:
2223
- case "float" /* Formats.FLOAT */:
2224
- case "uint8" /* Formats.UINT8 */:
2225
- case "uint16" /* Formats.UINT16 */:
2226
- case "uint32" /* Formats.UINT32 */:
2227
- 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: {
2228
2259
  if (typeof value === 'boolean') {
2229
2260
  value = value ? 1 : 0;
2230
2261
  }
2231
2262
  if (typeof value === 'string') {
2232
- value = this.props.format === "float" /* Formats.FLOAT */
2263
+ value = this.props.format === Formats.FLOAT
2233
2264
  ? Number.parseFloat(value)
2234
2265
  : parseInt(value, 10);
2235
2266
  }
@@ -2242,7 +2273,7 @@ export class Characteristic extends EventEmitter {
2242
2273
  const numericMin = maxWithUndefined(this.props.minValue, numericLowerBound(this.props.format));
2243
2274
  let numericMax = minWithUndefined(this.props.maxValue, numericUpperBound(this.props.format));
2244
2275
  let stepValue;
2245
- if (this.props.format === "float" /* Formats.FLOAT */) {
2276
+ if (this.props.format === Formats.FLOAT) {
2246
2277
  stepValue = this.props.minStep;
2247
2278
  }
2248
2279
  else {
@@ -2251,9 +2282,15 @@ export class Characteristic extends EventEmitter {
2251
2282
  if (stepValue != null && stepValue > 0) {
2252
2283
  const minValue = this.props.minValue ?? 0;
2253
2284
  if (numericMax != null) {
2254
- 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);
2255
2289
  }
2256
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
+ }
2257
2294
  }
2258
2295
  if (numericMin != null && value < numericMin) {
2259
2296
  this.characteristicWarning(`characteristic was supplied illegal value: number ${value} exceeded minimum of ${numericMin}`, warningType);
@@ -2283,7 +2320,7 @@ export class Characteristic extends EventEmitter {
2283
2320
  }
2284
2321
  return value;
2285
2322
  }
2286
- case "string" /* Formats.STRING */: {
2323
+ case Formats.STRING: {
2287
2324
  if (typeof value === 'number') {
2288
2325
  this.characteristicWarning('characteristic was supplied illegal value: number instead of string, '
2289
2326
  + 'supplying illegal values will throw errors in the future', warningType);
@@ -2291,24 +2328,31 @@ export class Characteristic extends EventEmitter {
2291
2328
  }
2292
2329
  if (typeof value !== 'string') {
2293
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".
2294
2332
  value = typeof this.value === 'string'
2295
2333
  ? this.value
2296
- : `${value}`;
2334
+ : '';
2297
2335
  }
2298
2336
  // mirrors the case value = null at the beginning
2299
2337
  if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) {
2300
- this.characteristicWarning(`[${this.displayName}] characteristic must have a length of more than 1 character otherwise`
2301
- + ` 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);
2302
2340
  return this.value; // just return the current value
2303
2341
  }
2304
2342
  const maxLength = this.props.maxLen ?? 64; // default is 64 (max is 256 which is set in setProps)
2305
2343
  if (value.length > maxLength) {
2306
2344
  this.characteristicWarning(`characteristic was supplied illegal value: string '${value}' exceeded max length of ${maxLength}`, warningType);
2307
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
+ }
2308
2352
  }
2309
2353
  return value;
2310
2354
  }
2311
- case "data" /* Formats.DATA */:
2355
+ case Formats.DATA:
2312
2356
  if (typeof value !== 'string') {
2313
2357
  throw new TypeError('characteristic with DATA format must have string value');
2314
2358
  }
@@ -2317,7 +2361,7 @@ export class Characteristic extends EventEmitter {
2317
2361
  throw new Error('characteristic with DATA format exceeds specified maxDataLen');
2318
2362
  }
2319
2363
  return value;
2320
- case "tlv8" /* Formats.TLV8 */:
2364
+ case Formats.TLV8:
2321
2365
  if (value === undefined) {
2322
2366
  this.characteristicWarning('characteristic was supplied illegal value: undefined', warningType);
2323
2367
  return this.value;
@@ -2326,7 +2370,7 @@ export class Characteristic extends EventEmitter {
2326
2370
  }
2327
2371
  // hopefully it shouldn't get to this point
2328
2372
  if (value === undefined) {
2329
- 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);
2330
2374
  return this.value;
2331
2375
  }
2332
2376
  return value;
@@ -2348,10 +2392,10 @@ export class Characteristic extends EventEmitter {
2348
2392
  * (see {@link validateUserInput}), and on something like {@link Characteristic.PasswordSetting} that value is the secret itself, so those keep the
2349
2393
  * long-standing behaviour of going nowhere until an accessory is listening.
2350
2394
  */
2351
- characteristicWarning(message, type = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */,
2395
+ characteristicWarning(message, type = CharacteristicWarningType.WARN_MESSAGE,
2352
2396
  // eslint-disable-next-line unicorn/error-message -- only here to capture the stack
2353
2397
  stack = new Error().stack, reportWhenUnheard = false) {
2354
- const heard = this.emit("characteristic-warning" /* CharacteristicEventTypes.CHARACTERISTIC_WARNING */, type, message, stack);
2398
+ const heard = this.emit(CharacteristicEventTypes.CHARACTERISTIC_WARNING, type, message, stack);
2355
2399
  if (!heard && reportWhenUnheard) {
2356
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
2357
2401
  // the only thing that locates the fault.
@@ -2374,23 +2418,30 @@ export class Characteristic extends EventEmitter {
2374
2418
  * @private
2375
2419
  */
2376
2420
  replaceBy(characteristic) {
2377
- 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
+ };
2378
2429
  this.updateValue(characteristic.value);
2379
- const getListeners = characteristic.listeners("get" /* CharacteristicEventTypes.GET */);
2430
+ const getListeners = characteristic.listeners(CharacteristicEventTypes.GET);
2380
2431
  if (getListeners.length) {
2381
2432
  // the callback can only be called once, so we remove all old listeners
2382
- this.removeAllListeners("get" /* CharacteristicEventTypes.GET */);
2383
- getListeners.forEach(listener => this.addListener("get" /* CharacteristicEventTypes.GET */, listener));
2433
+ this.removeAllListeners(CharacteristicEventTypes.GET);
2434
+ getListeners.forEach(listener => this.addListener(CharacteristicEventTypes.GET, listener));
2384
2435
  }
2385
2436
  this.removeOnGet();
2386
2437
  if (characteristic.getHandler) {
2387
2438
  this.onGet(characteristic.getHandler);
2388
2439
  }
2389
- const setListeners = characteristic.listeners("set" /* CharacteristicEventTypes.SET */);
2440
+ const setListeners = characteristic.listeners(CharacteristicEventTypes.SET);
2390
2441
  if (setListeners.length) {
2391
2442
  // the callback can only be called once, so we remove all old listeners
2392
- this.removeAllListeners("set" /* CharacteristicEventTypes.SET */);
2393
- setListeners.forEach(listener => this.addListener("set" /* CharacteristicEventTypes.SET */, listener));
2443
+ this.removeAllListeners(CharacteristicEventTypes.SET);
2444
+ setListeners.forEach(listener => this.addListener(CharacteristicEventTypes.SET, listener));
2394
2445
  }
2395
2446
  this.removeOnSet();
2396
2447
  if (characteristic.setHandler) {
@@ -2403,7 +2454,7 @@ export class Characteristic extends EventEmitter {
2403
2454
  */
2404
2455
  async toHAP(connection, contactGetHandlers = true) {
2405
2456
  const object = this.internalHAPRepresentation();
2406
- if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) {
2457
+ if (!this.props.perms.includes(Perms.PAIRED_READ)) {
2407
2458
  object.value = undefined;
2408
2459
  }
2409
2460
  else if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
@@ -2474,9 +2525,12 @@ export class Characteristic extends EventEmitter {
2474
2525
  */
2475
2526
  static deserialize(json) {
2476
2527
  let characteristic;
2477
- if (json.constructorName && json.constructorName.charAt(0).toUpperCase() === json.constructorName.charAt(0)
2478
- && Characteristic[json.constructorName]) { // MUST start with uppercase character and must exist on Characteristic object
2479
- 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) {
2480
2534
  characteristic = new constructor();
2481
2535
  characteristic.displayName = json.displayName;
2482
2536
  characteristic.setProps(json.props);