@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.
- package/README.md +13 -4
- package/dist/accessories/types.d.ts +0 -1
- package/dist/hap.d.ts +1 -1
- package/dist/hap.js +6 -4
- package/dist/hap.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +6 -7
- package/dist/internal-types.js +1 -5
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +49 -25
- package/dist/lib/Accessory.js +275 -171
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +37 -18
- package/dist/lib/Advertiser.js +143 -62
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -2
- package/dist/lib/Bridge.js +1 -1
- package/dist/lib/Characteristic.d.ts +40 -21
- package/dist/lib/Characteristic.js +207 -153
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +19 -13
- package/dist/lib/HAPServer.js +266 -220
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +16 -12
- package/dist/lib/Service.js +58 -37
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +5 -5
- package/dist/lib/camera/RTPProxy.js +48 -23
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +18 -13
- package/dist/lib/camera/RTPStreamManagement.js +247 -216
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +13 -13
- package/dist/lib/camera/RecordingManagement.js +115 -110
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +0 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +41 -36
- package/dist/lib/controller/AdaptiveLightingController.js +126 -113
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +17 -17
- package/dist/lib/controller/CameraController.js +30 -26
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +15 -12
- package/dist/lib/controller/Controller.js +0 -1
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +6 -6
- package/dist/lib/controller/DoorbellController.js +10 -3
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +46 -27
- package/dist/lib/controller/RemoteController.js +268 -178
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +0 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +6 -6
- package/dist/lib/datastream/DataStreamManagement.js +30 -26
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +25 -8
- package/dist/lib/datastream/DataStreamParser.js +124 -105
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +47 -23
- package/dist/lib/datastream/DataStreamServer.js +285 -143
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +0 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +35 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +649 -568
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +7 -1
- package/dist/lib/definitions/ServiceDefinitions.js +16 -1
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +0 -1
- package/dist/lib/gen/HomeKit.d.ts +0 -1
- package/dist/lib/model/AccessoryInfo.d.ts +5 -6
- package/dist/lib/model/AccessoryInfo.js +23 -19
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +11 -5
- package/dist/lib/model/ControllerStorage.js +34 -8
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPFileStorage.d.ts +20 -2
- package/dist/lib/model/HAPFileStorage.js +59 -10
- package/dist/lib/model/HAPFileStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +0 -1
- package/dist/lib/model/HAPStorage.js +6 -3
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +2 -3
- package/dist/lib/model/IdentifierCache.js +26 -13
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +6 -7
- package/dist/lib/tv/AccessControlManagement.js +13 -19
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +1 -2
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts +0 -1
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -2
- package/dist/lib/util/color-utils.js +1 -1
- package/dist/lib/util/errors.d.ts +4 -0
- package/dist/lib/util/errors.js +15 -0
- package/dist/lib/util/errors.js.map +1 -0
- package/dist/lib/util/eventedhttp.d.ts +63 -19
- package/dist/lib/util/eventedhttp.js +170 -48
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +1 -2
- package/dist/lib/util/hapCrypto.js +6 -7
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +0 -1
- package/dist/lib/util/hapStatusError.js +1 -1
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.d.ts +1 -2
- package/dist/lib/util/net-utils.js +6 -7
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.d.ts +0 -1
- package/dist/lib/util/promise-utils.d.ts +1 -2
- package/dist/lib/util/promise-utils.js +2 -1
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +4 -4
- package/dist/lib/util/request-util.js +29 -28
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -2
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +4 -4
- package/dist/lib/util/tlv.js +16 -5
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +5 -2
- package/dist/lib/util/uuid.js +6 -0
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +20 -17
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -14
- package/dist/accessories/AirConditioner_accessory.d.ts +0 -2
- package/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
- package/dist/accessories/AirConditioner_accessory.js +0 -126
- package/dist/accessories/AirConditioner_accessory.js.map +0 -1
- package/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
- package/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
- package/dist/accessories/AppleTVRemote_accessory.js +0 -146
- package/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
- package/dist/accessories/Camera_accessory.d.ts +0 -2
- package/dist/accessories/Camera_accessory.d.ts.map +0 -1
- package/dist/accessories/Camera_accessory.js +0 -562
- package/dist/accessories/Camera_accessory.js.map +0 -1
- package/dist/accessories/Fan_accessory.d.ts +0 -2
- package/dist/accessories/Fan_accessory.d.ts.map +0 -1
- package/dist/accessories/Fan_accessory.js +0 -71
- package/dist/accessories/Fan_accessory.js.map +0 -1
- package/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
- package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +0 -76
- package/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
- package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -103
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
- package/dist/accessories/Light_accessory.d.ts +0 -2
- package/dist/accessories/Light_accessory.d.ts.map +0 -1
- package/dist/accessories/Light_accessory.js +0 -143
- package/dist/accessories/Light_accessory.js.map +0 -1
- package/dist/accessories/Lock_accessory.d.ts +0 -2
- package/dist/accessories/Lock_accessory.d.ts.map +0 -1
- package/dist/accessories/Lock_accessory.js +0 -74
- package/dist/accessories/Lock_accessory.js.map +0 -1
- package/dist/accessories/MotionSensor_accessory.d.ts +0 -2
- package/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
- package/dist/accessories/MotionSensor_accessory.js +0 -43
- package/dist/accessories/MotionSensor_accessory.js.map +0 -1
- package/dist/accessories/Outlet_accessory.d.ts +0 -2
- package/dist/accessories/Outlet_accessory.d.ts.map +0 -1
- package/dist/accessories/Outlet_accessory.js +0 -77
- package/dist/accessories/Outlet_accessory.js.map +0 -1
- package/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
- package/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
- package/dist/accessories/SmartSpeaker_accessory.js +0 -42
- package/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
- package/dist/accessories/Sprinkler_accessory.d.ts +0 -2
- package/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
- package/dist/accessories/Sprinkler_accessory.js +0 -126
- package/dist/accessories/Sprinkler_accessory.js.map +0 -1
- package/dist/accessories/TV_accessory.d.ts +0 -2
- package/dist/accessories/TV_accessory.d.ts.map +0 -1
- package/dist/accessories/TV_accessory.js +0 -99
- package/dist/accessories/TV_accessory.js.map +0 -1
- package/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
- package/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
- package/dist/accessories/TemperatureSensor_accessory.js +0 -42
- package/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +0 -14
- package/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +0 -16
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
- package/dist/accessories/gstreamer-audioProducer.js +0 -145
- package/dist/accessories/gstreamer-audioProducer.js.map +0 -1
- package/dist/accessories/types.d.ts.map +0 -1
- package/dist/hap.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/internal-types.d.ts.map +0 -1
- package/dist/lib/Accessory.d.ts.map +0 -1
- package/dist/lib/Advertiser.d.ts.map +0 -1
- package/dist/lib/Bridge.d.ts.map +0 -1
- package/dist/lib/Characteristic.d.ts.map +0 -1
- package/dist/lib/HAPServer.d.ts.map +0 -1
- package/dist/lib/Service.d.ts.map +0 -1
- package/dist/lib/camera/RTPProxy.d.ts.map +0 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
- package/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
- package/dist/lib/camera/index.d.ts.map +0 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
- package/dist/lib/controller/CameraController.d.ts.map +0 -1
- package/dist/lib/controller/Controller.d.ts.map +0 -1
- package/dist/lib/controller/DoorbellController.d.ts.map +0 -1
- package/dist/lib/controller/RemoteController.d.ts.map +0 -1
- package/dist/lib/controller/index.d.ts.map +0 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
- package/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
- package/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
- package/dist/lib/datastream/index.d.ts.map +0 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
- package/dist/lib/definitions/generate-definitions.d.ts +0 -34
- package/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
- package/dist/lib/definitions/generate-definitions.js +0 -624
- package/dist/lib/definitions/generate-definitions.js.map +0 -1
- package/dist/lib/definitions/generator-configuration.d.ts +0 -22
- package/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
- package/dist/lib/definitions/generator-configuration.js +0 -674
- package/dist/lib/definitions/generator-configuration.js.map +0 -1
- package/dist/lib/definitions/index.d.ts.map +0 -1
- package/dist/lib/gen/HomeKit.d.ts.map +0 -1
- package/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
- package/dist/lib/model/ControllerStorage.d.ts.map +0 -1
- package/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
- package/dist/lib/model/HAPStorage.d.ts.map +0 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +0 -1
- package/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
- package/dist/lib/util/checkName.d.ts.map +0 -1
- package/dist/lib/util/clone.d.ts.map +0 -1
- package/dist/lib/util/color-utils.d.ts.map +0 -1
- package/dist/lib/util/eventedhttp.d.ts.map +0 -1
- package/dist/lib/util/hapCrypto.d.ts.map +0 -1
- package/dist/lib/util/hapStatusError.d.ts.map +0 -1
- package/dist/lib/util/net-utils.d.ts.map +0 -1
- package/dist/lib/util/once.d.ts.map +0 -1
- package/dist/lib/util/promise-utils.d.ts.map +0 -1
- package/dist/lib/util/request-util.d.ts.map +0 -1
- package/dist/lib/util/time.d.ts.map +0 -1
- package/dist/lib/util/tlv.d.ts.map +0 -1
- package/dist/lib/util/uuid.d.ts.map +0 -1
- 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.
|
|
91
|
-
*
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
263
|
-
|
|
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
|
|
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:
|
|
1357
|
-
perms: [
|
|
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)}`,
|
|
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}`,
|
|
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})`,
|
|
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)}`,
|
|
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)}`,
|
|
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}`,
|
|
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})`,
|
|
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)}`,
|
|
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)}`,
|
|
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}`,
|
|
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 !==
|
|
1527
|
-
this.characteristicWarning(`Characteristic Property \`maxLen\` can only be set for characteristics with format \`STRING\`, but not for ${this.props.format}`,
|
|
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 !==
|
|
1542
|
-
this.characteristicWarning(`Characteristic Property \`maxDataLen\` can only be set for characteristics with format \`DATA\`, but not for ${this.props.format}`,
|
|
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
|
|
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(
|
|
1585
|
-
if ((isNumericFormat(this.props.format) || this.props.format ===
|
|
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
|
|
1597
|
-
const correctedValue = this.validateUserInput(this.value,
|
|
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
|
|
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(
|
|
1655
|
-
this.props.perms.push(
|
|
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
|
|
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
|
|
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(
|
|
1756
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1730
1757
|
originator: undefined,
|
|
1731
1758
|
oldValue,
|
|
1732
1759
|
newValue: value,
|
|
1733
|
-
reason:
|
|
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(
|
|
1779
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1753
1780
|
originator: undefined,
|
|
1754
1781
|
oldValue,
|
|
1755
1782
|
newValue: value,
|
|
1756
|
-
reason:
|
|
1783
|
+
reason: ChangeReason.EVENT,
|
|
1757
1784
|
context,
|
|
1758
1785
|
});
|
|
1759
1786
|
return this; // for chaining
|
|
1760
1787
|
}
|
|
1761
1788
|
/**
|
|
1762
|
-
* Called when a HAP
|
|
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 -
|
|
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(
|
|
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.
|
|
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
|
|
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(
|
|
1821
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1795
1822
|
originator: connection,
|
|
1796
1823
|
oldValue,
|
|
1797
1824
|
newValue: value,
|
|
1798
|
-
reason:
|
|
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
|
|
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.
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
1891
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1865
1892
|
originator: connection,
|
|
1866
1893
|
oldValue,
|
|
1867
1894
|
newValue: value,
|
|
1868
|
-
reason:
|
|
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
|
|
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
|
|
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 -
|
|
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
|
|
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.
|
|
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(
|
|
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',
|
|
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(
|
|
1950
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1923
1951
|
originator: connection,
|
|
1924
1952
|
oldValue,
|
|
1925
1953
|
newValue: value,
|
|
1926
|
-
reason:
|
|
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
|
|
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.
|
|
1975
|
+
if (this.listenerCount(CharacteristicEventTypes.SET) === 0) {
|
|
1948
1976
|
this.value = value;
|
|
1949
|
-
this.emit(
|
|
1977
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1950
1978
|
originator: connection,
|
|
1951
1979
|
oldValue,
|
|
1952
1980
|
newValue: value,
|
|
1953
|
-
reason:
|
|
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(
|
|
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(
|
|
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
|
|
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',
|
|
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(
|
|
2026
|
+
this.emit(CharacteristicEventTypes.CHANGE, {
|
|
1999
2027
|
originator: connection,
|
|
2000
2028
|
oldValue,
|
|
2001
2029
|
newValue: value,
|
|
2002
|
-
reason:
|
|
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
|
|
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(
|
|
2050
|
+
this.emit(CharacteristicEventTypes.SUBSCRIBE);
|
|
2023
2051
|
}
|
|
2024
2052
|
this.subscriptions++;
|
|
2025
2053
|
}
|
|
2026
2054
|
/**
|
|
2027
|
-
* Called once 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(
|
|
2064
|
+
this.emit(CharacteristicEventTypes.UNSUBSCRIBE);
|
|
2037
2065
|
}
|
|
2038
2066
|
}
|
|
2039
2067
|
getDefaultValue() {
|
|
2040
2068
|
// noinspection JSDeprecatedSymbols
|
|
2041
2069
|
switch (this.props.format) {
|
|
2042
|
-
case
|
|
2070
|
+
case Formats.BOOL:
|
|
2043
2071
|
return false;
|
|
2044
|
-
case
|
|
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
|
|
2085
|
+
case Formats.DATA:
|
|
2058
2086
|
return ''; // who knows!
|
|
2059
|
-
case
|
|
2087
|
+
case Formats.TLV8:
|
|
2060
2088
|
return ''; // who knows!
|
|
2061
|
-
case
|
|
2062
|
-
case
|
|
2063
|
-
case
|
|
2064
|
-
case
|
|
2065
|
-
case
|
|
2066
|
-
case
|
|
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
|
|
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
|
|
2105
|
-
case
|
|
2106
|
-
case
|
|
2107
|
-
case
|
|
2108
|
-
case
|
|
2109
|
-
case
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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',
|
|
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 ===
|
|
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
|
|
2188
|
-
* BUT:
|
|
2189
|
-
* homebridge devs started
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2223
|
-
case
|
|
2224
|
-
case
|
|
2225
|
-
case
|
|
2226
|
-
case
|
|
2227
|
-
case
|
|
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 ===
|
|
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 ===
|
|
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
|
-
|
|
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
|
|
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
|
-
:
|
|
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(
|
|
2301
|
-
+
|
|
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
|
|
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
|
|
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',
|
|
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 =
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
2383
|
-
getListeners.forEach(listener => this.addListener(
|
|
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(
|
|
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(
|
|
2393
|
-
setListeners.forEach(listener => this.addListener(
|
|
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(
|
|
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
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
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);
|