@homebridge/hap-nodejs 2.2.4-beta.6 → 2.3.0-beta.0
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 +14 -17
- package/dist/accessories/AirConditioner_accessory.js +27 -29
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +61 -71
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +151 -134
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +18 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +33 -35
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +41 -44
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +32 -34
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +24 -26
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +13 -15
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +20 -22
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +18 -20
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +36 -38
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +43 -45
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +12 -14
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +9 -12
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +11 -14
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +3 -3
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +35 -36
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.d.ts +63 -63
- package/dist/accessories/types.d.ts.map +1 -1
- package/dist/accessories/types.js +83 -87
- package/dist/accessories/types.js.map +1 -1
- package/dist/hap.d.ts +50 -0
- package/dist/hap.d.ts.map +1 -0
- package/dist/hap.js +49 -0
- package/dist/hap.js.map +1 -0
- package/dist/index.d.ts +3 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -53
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +1 -1
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +19 -19
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +37 -37
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +265 -257
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +6 -6
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +143 -139
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +2 -6
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +40 -41
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +265 -216
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +30 -29
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +223 -224
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +21 -22
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +60 -68
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +2 -1
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +35 -37
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +34 -33
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +178 -132
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +18 -17
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +182 -154
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +3 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +3 -6
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +8 -8
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +111 -99
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +21 -20
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +82 -80
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +1 -1
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +5 -8
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +4 -4
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +9 -13
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +38 -37
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +188 -158
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +5 -5
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/index.js +5 -8
- package/dist/lib/controller/index.js.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +2 -2
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +32 -32
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +1 -0
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +53 -69
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +23 -22
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +152 -154
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/datastream/index.d.ts.map +1 -1
- package/dist/lib/datastream/index.js +3 -6
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +1103 -1288
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +644 -722
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +2 -2
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +241 -241
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +572 -309
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +2 -2
- package/dist/lib/definitions/index.d.ts.map +1 -1
- package/dist/lib/definitions/index.js +2 -5
- package/dist/lib/definitions/index.js.map +1 -1
- package/dist/lib/gen/HomeKit.js +1 -2
- package/dist/lib/gen/HomeKit.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +4 -3
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +53 -56
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -3
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +31 -30
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPFileStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPFileStorage.js +71 -50
- package/dist/lib/model/HAPFileStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +1 -1
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +11 -14
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +1 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +23 -27
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +6 -6
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +23 -24
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -2
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +8 -14
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +1 -5
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +1608 -410
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +23 -22
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +127 -122
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +2 -1
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +72 -59
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +1 -1
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +4 -8
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +13 -19
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -6
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +1 -1
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +9 -11
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +3 -3
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +13 -22
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -0
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +6 -11
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +1 -0
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +38 -44
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +1 -0
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +26 -38
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +24 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/package.json +50 -43
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const clone_1 = require("./util/clone");
|
|
12
|
-
const hapStatusError_1 = require("./util/hapStatusError");
|
|
13
|
-
const once_1 = require("./util/once");
|
|
14
|
-
const request_util_1 = require("./util/request-util");
|
|
15
|
-
const uuid_1 = require("./util/uuid");
|
|
16
|
-
const debug = (0, debug_1.default)("HAP-NodeJS:Characteristic");
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { inspect } from 'node:util';
|
|
4
|
+
import createDebug from 'debug';
|
|
5
|
+
import { clone } from './util/clone.js';
|
|
6
|
+
import { HapStatusError } from './util/hapStatusError.js';
|
|
7
|
+
import { once } from './util/once.js';
|
|
8
|
+
import { extractHAPStatusFromError, formatOutgoingCharacteristicValue, isIntegerNumericFormat, isNumericFormat, isUnsignedNumericFormat, numericLowerBound, numericUpperBound, } from './util/request-util.js';
|
|
9
|
+
import { BASE_UUID, toShortForm } from './util/uuid.js';
|
|
10
|
+
const debug = createDebug('HAP-NodeJS:Characteristic');
|
|
17
11
|
/**
|
|
18
12
|
* @group Characteristic
|
|
19
13
|
*/
|
|
20
|
-
|
|
14
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
15
|
+
export var Formats;
|
|
21
16
|
(function (Formats) {
|
|
22
17
|
Formats["BOOL"] = "bool";
|
|
23
18
|
/**
|
|
@@ -56,11 +51,12 @@ var Formats;
|
|
|
56
51
|
* Base64 encoded tlv8 string.
|
|
57
52
|
*/
|
|
58
53
|
Formats["TLV8"] = "tlv8";
|
|
59
|
-
})(Formats || (
|
|
54
|
+
})(Formats || (Formats = {}));
|
|
60
55
|
/**
|
|
61
56
|
* @group Characteristic
|
|
62
57
|
*/
|
|
63
|
-
|
|
58
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
59
|
+
export var Units;
|
|
64
60
|
(function (Units) {
|
|
65
61
|
/**
|
|
66
62
|
* Celsius is the only temperature unit in the HomeKit Accessory Protocol.
|
|
@@ -72,22 +68,23 @@ var Units;
|
|
|
72
68
|
Units["ARC_DEGREE"] = "arcdegrees";
|
|
73
69
|
Units["LUX"] = "lux";
|
|
74
70
|
Units["SECONDS"] = "seconds";
|
|
75
|
-
})(Units || (
|
|
71
|
+
})(Units || (Units = {}));
|
|
76
72
|
/**
|
|
77
73
|
* @group Characteristic
|
|
78
74
|
*/
|
|
79
|
-
|
|
75
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
76
|
+
export var Perms;
|
|
80
77
|
(function (Perms) {
|
|
81
78
|
Perms["PAIRED_READ"] = "pr";
|
|
82
79
|
Perms["PAIRED_WRITE"] = "pw";
|
|
83
80
|
Perms["NOTIFY"] = "ev";
|
|
84
|
-
// eslint-disable-next-line
|
|
81
|
+
// eslint-disable-next-line ts/no-duplicate-enum-values
|
|
85
82
|
Perms["EVENTS"] = "ev";
|
|
86
83
|
Perms["ADDITIONAL_AUTHORIZATION"] = "aa";
|
|
87
84
|
Perms["TIMED_WRITE"] = "tw";
|
|
88
85
|
Perms["HIDDEN"] = "hd";
|
|
89
86
|
Perms["WRITE_RESPONSE"] = "wr";
|
|
90
|
-
})(Perms || (
|
|
87
|
+
})(Perms || (Perms = {}));
|
|
91
88
|
/**
|
|
92
89
|
* 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
|
|
93
90
|
* 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,
|
|
@@ -113,14 +110,14 @@ const VALID_PERMS = new Set([
|
|
|
113
110
|
*
|
|
114
111
|
* @private
|
|
115
112
|
*/
|
|
116
|
-
function isValidPerms(perms) {
|
|
113
|
+
export function isValidPerms(perms) {
|
|
117
114
|
if (!Array.isArray(perms) || perms.length === 0) {
|
|
118
115
|
return false;
|
|
119
116
|
}
|
|
120
117
|
// for...of iteration surfaces the holes of a sparse array as undefined, which Array.prototype.every would silently skip. A hole survives JSON
|
|
121
118
|
// serialization as null, the exact malformed entry this check exists to reject.
|
|
122
119
|
for (const permission of perms) {
|
|
123
|
-
if (typeof permission !==
|
|
120
|
+
if (typeof permission !== 'string' || !VALID_PERMS.has(permission)) {
|
|
124
121
|
return false;
|
|
125
122
|
}
|
|
126
123
|
}
|
|
@@ -136,12 +133,12 @@ function isValidPerms(perms) {
|
|
|
136
133
|
*
|
|
137
134
|
* @private
|
|
138
135
|
*/
|
|
139
|
-
function describePerms(perms) {
|
|
136
|
+
export function describePerms(perms) {
|
|
140
137
|
try {
|
|
141
138
|
return JSON.stringify(perms) ?? String(perms);
|
|
142
139
|
}
|
|
143
140
|
catch {
|
|
144
|
-
return
|
|
141
|
+
return inspect(perms);
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
144
|
/**
|
|
@@ -152,16 +149,18 @@ function describePerms(perms) {
|
|
|
152
149
|
*
|
|
153
150
|
* @group Characteristic
|
|
154
151
|
*/
|
|
155
|
-
|
|
152
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
153
|
+
export var Access;
|
|
156
154
|
(function (Access) {
|
|
157
155
|
Access[Access["READ"] = 0] = "READ";
|
|
158
156
|
Access[Access["WRITE"] = 1] = "WRITE";
|
|
159
157
|
Access[Access["NOTIFY"] = 2] = "NOTIFY";
|
|
160
|
-
})(Access || (
|
|
158
|
+
})(Access || (Access = {}));
|
|
161
159
|
/**
|
|
162
160
|
* @group Characteristic
|
|
163
161
|
*/
|
|
164
|
-
|
|
162
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
163
|
+
export var ChangeReason;
|
|
165
164
|
(function (ChangeReason) {
|
|
166
165
|
/**
|
|
167
166
|
* Reason used when HomeKit writes a value or the API user calls {@link Characteristic.setValue}.
|
|
@@ -179,11 +178,12 @@ var ChangeReason;
|
|
|
179
178
|
* Used when call to {@link Characteristic.sendEventNotification} was made.
|
|
180
179
|
*/
|
|
181
180
|
ChangeReason["EVENT"] = "event";
|
|
182
|
-
})(ChangeReason || (
|
|
181
|
+
})(ChangeReason || (ChangeReason = {}));
|
|
183
182
|
/**
|
|
184
183
|
* @group Characteristic
|
|
185
184
|
*/
|
|
186
|
-
|
|
185
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
186
|
+
export var CharacteristicEventTypes;
|
|
187
187
|
(function (CharacteristicEventTypes) {
|
|
188
188
|
/**
|
|
189
189
|
* This event is thrown when a HomeKit controller wants to read the current value of the characteristic.
|
|
@@ -221,14 +221,14 @@ var CharacteristicEventTypes;
|
|
|
221
221
|
* @private
|
|
222
222
|
*/
|
|
223
223
|
CharacteristicEventTypes["CHARACTERISTIC_CONFIGURATION_CHANGE"] = "characteristic-configurationChange";
|
|
224
|
-
})(CharacteristicEventTypes || (
|
|
224
|
+
})(CharacteristicEventTypes || (CharacteristicEventTypes = {}));
|
|
225
225
|
/**
|
|
226
226
|
* @group Characteristic
|
|
227
227
|
*/
|
|
228
228
|
class ValidValuesIterable {
|
|
229
229
|
props;
|
|
230
230
|
constructor(props) {
|
|
231
|
-
(
|
|
231
|
+
assert(isNumericFormat(props.format), `Cannot instantiate valid values iterable when format is not numeric. Found ${props.format}`);
|
|
232
232
|
this.props = props;
|
|
233
233
|
}
|
|
234
234
|
*[Symbol.iterator]() {
|
|
@@ -252,11 +252,11 @@ class ValidValuesIterable {
|
|
|
252
252
|
stepValue = this.props.minStep;
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
else if (
|
|
256
|
-
max =
|
|
255
|
+
else if (isUnsignedNumericFormat(this.props.format)) {
|
|
256
|
+
max = numericUpperBound(this.props.format);
|
|
257
257
|
}
|
|
258
258
|
else {
|
|
259
|
-
throw new Error(
|
|
259
|
+
throw new Error(`Could not find valid iterator strategy for props: ${JSON.stringify(this.props)}`);
|
|
260
260
|
}
|
|
261
261
|
for (let i = min; i <= max; i += stepValue) {
|
|
262
262
|
yield i;
|
|
@@ -298,8 +298,8 @@ function minWithUndefined(a, b) {
|
|
|
298
298
|
*
|
|
299
299
|
* @group Characteristic
|
|
300
300
|
*/
|
|
301
|
-
// eslint-disable-next-line
|
|
302
|
-
class Characteristic extends
|
|
301
|
+
// eslint-disable-next-line ts/no-unsafe-declaration-merging
|
|
302
|
+
export class Characteristic extends EventEmitter {
|
|
303
303
|
// Pattern below is for automatic detection of the section of defined characteristics. Used by the generator
|
|
304
304
|
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
|
305
305
|
/**
|
|
@@ -1371,8 +1371,8 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1371
1371
|
* @param handler
|
|
1372
1372
|
*/
|
|
1373
1373
|
onGet(handler) {
|
|
1374
|
-
if (typeof handler !==
|
|
1375
|
-
this.characteristicWarning(
|
|
1374
|
+
if (typeof handler !== 'function') {
|
|
1375
|
+
this.characteristicWarning('.onGet handler must be a function');
|
|
1376
1376
|
return this;
|
|
1377
1377
|
}
|
|
1378
1378
|
this.getHandler = handler;
|
|
@@ -1400,8 +1400,8 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1400
1400
|
* @param handler
|
|
1401
1401
|
*/
|
|
1402
1402
|
onSet(handler) {
|
|
1403
|
-
if (typeof handler !==
|
|
1404
|
-
this.characteristicWarning(
|
|
1403
|
+
if (typeof handler !== 'function') {
|
|
1404
|
+
this.characteristicWarning('.onSet handler must be a function');
|
|
1405
1405
|
return this;
|
|
1406
1406
|
}
|
|
1407
1407
|
this.setHandler = handler;
|
|
@@ -1422,7 +1422,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1422
1422
|
* @param props - Partial properties object with the desired updates.
|
|
1423
1423
|
*/
|
|
1424
1424
|
setProps(props) {
|
|
1425
|
-
(
|
|
1425
|
+
assert(props, 'props cannot be undefined when setting props');
|
|
1426
1426
|
let formatDidChange = false;
|
|
1427
1427
|
// for every value "null" can be used to reset props, except for required props
|
|
1428
1428
|
if (props.format) {
|
|
@@ -1443,37 +1443,37 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1443
1443
|
* out of {@link setupAdditionalAuthorization}. An empty array fails {@link isValidPerms} exactly as the declared value does, so the accessory is
|
|
1444
1444
|
* still quarantined - it just fails closed on the way there. The warning above quotes what the plugin actually declared.
|
|
1445
1445
|
*/
|
|
1446
|
-
this.props.perms = Array.isArray(props.perms)
|
|
1446
|
+
this.props.perms = Array.isArray(props.perms)
|
|
1447
|
+
? props.perms
|
|
1448
|
+
: [];
|
|
1447
1449
|
}
|
|
1448
1450
|
if (props.unit !== undefined) {
|
|
1449
|
-
this.props.unit = props.unit
|
|
1451
|
+
this.props.unit = props.unit ?? undefined;
|
|
1450
1452
|
}
|
|
1451
1453
|
if (props.description !== undefined) {
|
|
1452
|
-
this.props.description = props.description
|
|
1454
|
+
this.props.description = props.description ?? undefined;
|
|
1453
1455
|
}
|
|
1454
1456
|
// check minValue is valid for the format type
|
|
1455
1457
|
if (props.minValue !== undefined) {
|
|
1456
1458
|
if (props.minValue === null) {
|
|
1457
1459
|
props.minValue = undefined;
|
|
1458
1460
|
}
|
|
1459
|
-
else if (!
|
|
1460
|
-
this.characteristicWarning(
|
|
1461
|
+
else if (!isNumericFormat(this.props.format)) {
|
|
1462
|
+
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 */);
|
|
1461
1463
|
props.minValue = undefined;
|
|
1462
1464
|
}
|
|
1463
|
-
else if (typeof props.minValue !==
|
|
1465
|
+
else if (typeof props.minValue !== 'number' || !Number.isFinite(props.minValue)) {
|
|
1464
1466
|
this.characteristicWarning(`Characteristic Property 'minValue' must be a finite number, received "${props.minValue}" (${typeof props.minValue})`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
|
|
1465
1467
|
props.minValue = undefined;
|
|
1466
1468
|
}
|
|
1467
1469
|
else {
|
|
1468
|
-
if (props.minValue <
|
|
1469
|
-
this.characteristicWarning(
|
|
1470
|
-
|
|
1471
|
-
props.minValue = (0, request_util_1.numericLowerBound)(this.props.format);
|
|
1470
|
+
if (props.minValue < numericLowerBound(this.props.format)) {
|
|
1471
|
+
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 */);
|
|
1472
|
+
props.minValue = numericLowerBound(this.props.format);
|
|
1472
1473
|
}
|
|
1473
|
-
else if (props.minValue >
|
|
1474
|
-
this.characteristicWarning(
|
|
1475
|
-
|
|
1476
|
-
props.minValue = (0, request_util_1.numericLowerBound)(this.props.format);
|
|
1474
|
+
else if (props.minValue > numericUpperBound(this.props.format)) {
|
|
1475
|
+
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 */);
|
|
1476
|
+
props.minValue = numericLowerBound(this.props.format);
|
|
1477
1477
|
}
|
|
1478
1478
|
}
|
|
1479
1479
|
this.props.minValue = props.minValue;
|
|
@@ -1483,24 +1483,22 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1483
1483
|
if (props.maxValue === null) {
|
|
1484
1484
|
props.maxValue = undefined;
|
|
1485
1485
|
}
|
|
1486
|
-
else if (!
|
|
1487
|
-
this.characteristicWarning(
|
|
1486
|
+
else if (!isNumericFormat(this.props.format)) {
|
|
1487
|
+
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 */);
|
|
1488
1488
|
props.maxValue = undefined;
|
|
1489
1489
|
}
|
|
1490
|
-
else if (typeof props.maxValue !==
|
|
1490
|
+
else if (typeof props.maxValue !== 'number' || !Number.isFinite(props.maxValue)) {
|
|
1491
1491
|
this.characteristicWarning(`Characteristic Property 'maxValue' must be a finite number, received "${props.maxValue}" (${typeof props.maxValue})`, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
|
|
1492
1492
|
props.maxValue = undefined;
|
|
1493
1493
|
}
|
|
1494
1494
|
else {
|
|
1495
|
-
if (props.maxValue >
|
|
1496
|
-
this.characteristicWarning(
|
|
1497
|
-
|
|
1498
|
-
props.maxValue = (0, request_util_1.numericUpperBound)(this.props.format);
|
|
1495
|
+
if (props.maxValue > numericUpperBound(this.props.format)) {
|
|
1496
|
+
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 */);
|
|
1497
|
+
props.maxValue = numericUpperBound(this.props.format);
|
|
1499
1498
|
}
|
|
1500
|
-
else if (props.maxValue <
|
|
1501
|
-
this.characteristicWarning(
|
|
1502
|
-
|
|
1503
|
-
props.maxValue = (0, request_util_1.numericUpperBound)(this.props.format);
|
|
1499
|
+
else if (props.maxValue < numericLowerBound(this.props.format)) {
|
|
1500
|
+
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 */);
|
|
1501
|
+
props.maxValue = numericUpperBound(this.props.format);
|
|
1504
1502
|
}
|
|
1505
1503
|
}
|
|
1506
1504
|
this.props.maxValue = props.maxValue;
|
|
@@ -1509,13 +1507,13 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1509
1507
|
if (props.minStep === null) {
|
|
1510
1508
|
this.props.minStep = undefined;
|
|
1511
1509
|
}
|
|
1512
|
-
else if (!
|
|
1513
|
-
this.characteristicWarning(
|
|
1510
|
+
else if (!isNumericFormat(this.props.format)) {
|
|
1511
|
+
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 */);
|
|
1514
1512
|
}
|
|
1515
1513
|
else {
|
|
1516
|
-
if (props.minStep < 1 &&
|
|
1517
|
-
this.characteristicWarning(
|
|
1518
|
-
|
|
1514
|
+
if (props.minStep < 1 && isIntegerNumericFormat(this.props.format)) {
|
|
1515
|
+
this.characteristicWarning('Characteristic Property `minStep` was set to a value lower than 1, '
|
|
1516
|
+
+ `this will have no effect on format \`${this.props.format}`);
|
|
1519
1517
|
}
|
|
1520
1518
|
this.props.minStep = props.minStep;
|
|
1521
1519
|
}
|
|
@@ -1525,11 +1523,11 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1525
1523
|
this.props.maxLen = undefined;
|
|
1526
1524
|
}
|
|
1527
1525
|
else if (this.props.format !== "string" /* Formats.STRING */) {
|
|
1528
|
-
this.characteristicWarning(
|
|
1526
|
+
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 */);
|
|
1529
1527
|
}
|
|
1530
1528
|
else {
|
|
1531
1529
|
if (props.maxLen > 256) {
|
|
1532
|
-
this.characteristicWarning(
|
|
1530
|
+
this.characteristicWarning('Characteristic Property string `maxLen` cannot be bigger than 256');
|
|
1533
1531
|
props.maxLen = 256;
|
|
1534
1532
|
}
|
|
1535
1533
|
this.props.maxLen = props.maxLen;
|
|
@@ -1540,7 +1538,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1540
1538
|
this.props.maxDataLen = undefined;
|
|
1541
1539
|
}
|
|
1542
1540
|
else if (this.props.format !== "data" /* Formats.DATA */) {
|
|
1543
|
-
this.characteristicWarning(
|
|
1541
|
+
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 */);
|
|
1544
1542
|
}
|
|
1545
1543
|
else {
|
|
1546
1544
|
this.props.maxDataLen = props.maxDataLen;
|
|
@@ -1550,11 +1548,11 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1550
1548
|
if (props.validValues === null) {
|
|
1551
1549
|
this.props.validValues = undefined;
|
|
1552
1550
|
}
|
|
1553
|
-
else if (!
|
|
1554
|
-
this.characteristicWarning(
|
|
1551
|
+
else if (!isNumericFormat(this.props.format)) {
|
|
1552
|
+
this.characteristicWarning(`Characteristic Property \`validValues\` was supplied for non numeric format ${this.props.format}`);
|
|
1555
1553
|
}
|
|
1556
1554
|
else {
|
|
1557
|
-
(
|
|
1555
|
+
assert(props.validValues.length, 'characteristic prop validValues cannot be empty array');
|
|
1558
1556
|
this.props.validValues = props.validValues;
|
|
1559
1557
|
}
|
|
1560
1558
|
}
|
|
@@ -1562,28 +1560,28 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1562
1560
|
if (props.validValueRanges === null) {
|
|
1563
1561
|
this.props.validValueRanges = undefined;
|
|
1564
1562
|
}
|
|
1565
|
-
else if (!
|
|
1566
|
-
this.characteristicWarning(
|
|
1563
|
+
else if (!isNumericFormat(this.props.format)) {
|
|
1564
|
+
this.characteristicWarning(`Characteristic Property \`validValueRanges\` was supplied for non numeric format ${this.props.format}`);
|
|
1567
1565
|
}
|
|
1568
1566
|
else {
|
|
1569
|
-
(
|
|
1567
|
+
assert(props.validValueRanges.length === 2, 'characteristic prop validValueRanges must have a length of 2');
|
|
1570
1568
|
this.props.validValueRanges = props.validValueRanges;
|
|
1571
1569
|
}
|
|
1572
1570
|
}
|
|
1573
1571
|
if (props.adminOnlyAccess !== undefined) {
|
|
1574
|
-
this.props.adminOnlyAccess = props.adminOnlyAccess
|
|
1572
|
+
this.props.adminOnlyAccess = props.adminOnlyAccess ?? undefined;
|
|
1575
1573
|
}
|
|
1576
1574
|
if (this.props.minValue != null && this.props.maxValue != null) { // the eqeq instead of eqeqeq is important here
|
|
1577
1575
|
if (this.props.minValue > this.props.maxValue) { // see https://github.com/homebridge/HAP-NodeJS/issues/690
|
|
1578
1576
|
this.props.minValue = undefined;
|
|
1579
1577
|
this.props.maxValue = undefined;
|
|
1580
|
-
throw new Error(
|
|
1578
|
+
throw new Error(`Error setting CharacteristicsProps for '${this.displayName}': 'minValue' cannot be greater or equal the 'maxValue'!`);
|
|
1581
1579
|
}
|
|
1582
1580
|
}
|
|
1583
1581
|
// the properties are part of the configuration HomeKit is served, so a published accessory must recompute its configuration number;
|
|
1584
1582
|
// a call that changes nothing leaves the configuration hash and therefore the number as it was
|
|
1585
1583
|
this.emit("characteristic-configurationChange" /* CharacteristicEventTypes.CHARACTERISTIC_CONFIGURATION_CHANGE */);
|
|
1586
|
-
if ((
|
|
1584
|
+
if ((isNumericFormat(this.props.format) || this.props.format === "string" /* Formats.STRING */)
|
|
1587
1585
|
&& this.value != null
|
|
1588
1586
|
&& !formatDidChange
|
|
1589
1587
|
&& this.statusCode === 0 /* HAPStatus.SUCCESS */
|
|
@@ -1608,11 +1606,11 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1608
1606
|
*
|
|
1609
1607
|
* The range of valid values can be defined using three different ways via the {@link CharacteristicProps} object
|
|
1610
1608
|
* (set via the {@link setProps} method):
|
|
1611
|
-
*
|
|
1612
|
-
*
|
|
1609
|
+
* First method is to specifically list every valid value inside {@link CharacteristicProps.validValues}
|
|
1610
|
+
* Second you can specify a range via {@link CharacteristicProps.minValue} and {@link CharacteristicProps.maxValue} (with optionally defining
|
|
1613
1611
|
* {@link CharacteristicProps.minStep})
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1612
|
+
* And lastly you can specify a range via {@link CharacteristicProps.validValueRanges}
|
|
1613
|
+
* Implicitly a valid value range is predefined for characteristics with Format {@link Formats.UINT8}, {@link Formats.UINT16},
|
|
1616
1614
|
* {@link Formats.UINT32} and {@link Formats.UINT64}: starting by zero to their respective maximum number
|
|
1617
1615
|
*
|
|
1618
1616
|
* The method will automatically detect which type of valid values definition is used and provide
|
|
@@ -1659,13 +1657,15 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1659
1657
|
}
|
|
1660
1658
|
setValue(value, callback, context) {
|
|
1661
1659
|
if (value instanceof Error) {
|
|
1662
|
-
this.statusCode = value instanceof
|
|
1660
|
+
this.statusCode = value instanceof HapStatusError
|
|
1661
|
+
? value.hapStatus
|
|
1662
|
+
: extractHAPStatusFromError(value);
|
|
1663
1663
|
if (callback) {
|
|
1664
1664
|
callback();
|
|
1665
1665
|
}
|
|
1666
1666
|
return this;
|
|
1667
1667
|
}
|
|
1668
|
-
if (callback && !context && typeof callback !==
|
|
1668
|
+
if (callback && !context && typeof callback !== 'function') {
|
|
1669
1669
|
context = callback;
|
|
1670
1670
|
callback = undefined;
|
|
1671
1671
|
}
|
|
@@ -1673,13 +1673,13 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1673
1673
|
value = this.validateUserInput(value);
|
|
1674
1674
|
}
|
|
1675
1675
|
catch (error) {
|
|
1676
|
-
this.characteristicWarning(error?.message ||
|
|
1676
|
+
this.characteristicWarning(error?.message || 'Unknown error', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
|
|
1677
1677
|
if (callback) {
|
|
1678
1678
|
callback(error);
|
|
1679
1679
|
}
|
|
1680
1680
|
return this;
|
|
1681
1681
|
}
|
|
1682
|
-
this.handleSetRequest(value, undefined, context).then(value => {
|
|
1682
|
+
this.handleSetRequest(value, undefined, context).then((value) => {
|
|
1683
1683
|
if (callback) {
|
|
1684
1684
|
if (value) { // possible write response
|
|
1685
1685
|
callback(null, value);
|
|
@@ -1688,7 +1688,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1688
1688
|
callback(null);
|
|
1689
1689
|
}
|
|
1690
1690
|
}
|
|
1691
|
-
}, reason => {
|
|
1691
|
+
}, (reason) => {
|
|
1692
1692
|
if (callback) {
|
|
1693
1693
|
callback(reason);
|
|
1694
1694
|
}
|
|
@@ -1697,13 +1697,15 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1697
1697
|
}
|
|
1698
1698
|
updateValue(value, callback, context) {
|
|
1699
1699
|
if (value instanceof Error) {
|
|
1700
|
-
this.statusCode = value instanceof
|
|
1700
|
+
this.statusCode = value instanceof HapStatusError
|
|
1701
|
+
? value.hapStatus
|
|
1702
|
+
: extractHAPStatusFromError(value);
|
|
1701
1703
|
if (callback) {
|
|
1702
1704
|
callback();
|
|
1703
1705
|
}
|
|
1704
1706
|
return this;
|
|
1705
1707
|
}
|
|
1706
|
-
if (callback && !context && typeof callback !==
|
|
1708
|
+
if (callback && !context && typeof callback !== 'function') {
|
|
1707
1709
|
context = callback;
|
|
1708
1710
|
callback = undefined;
|
|
1709
1711
|
}
|
|
@@ -1711,7 +1713,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1711
1713
|
value = this.validateUserInput(value);
|
|
1712
1714
|
}
|
|
1713
1715
|
catch (error) {
|
|
1714
|
-
this.characteristicWarning(error?.message ||
|
|
1716
|
+
this.characteristicWarning(error?.message || 'Unknown error', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, error?.stack);
|
|
1715
1717
|
if (callback) {
|
|
1716
1718
|
callback();
|
|
1717
1719
|
}
|
|
@@ -1723,7 +1725,13 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1723
1725
|
if (callback) {
|
|
1724
1726
|
callback();
|
|
1725
1727
|
}
|
|
1726
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1728
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1729
|
+
originator: undefined,
|
|
1730
|
+
oldValue,
|
|
1731
|
+
newValue: value,
|
|
1732
|
+
reason: "update" /* ChangeReason.UPDATE */,
|
|
1733
|
+
context,
|
|
1734
|
+
});
|
|
1727
1735
|
return this; // for chaining
|
|
1728
1736
|
}
|
|
1729
1737
|
/**
|
|
@@ -1740,7 +1748,13 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1740
1748
|
value = this.validateUserInput(value);
|
|
1741
1749
|
const oldValue = this.value;
|
|
1742
1750
|
this.value = value;
|
|
1743
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1751
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1752
|
+
originator: undefined,
|
|
1753
|
+
oldValue,
|
|
1754
|
+
newValue: value,
|
|
1755
|
+
reason: "event" /* ChangeReason.EVENT */,
|
|
1756
|
+
context,
|
|
1757
|
+
});
|
|
1744
1758
|
return this; // for chaining
|
|
1745
1759
|
}
|
|
1746
1760
|
/**
|
|
@@ -1748,7 +1762,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1748
1762
|
*
|
|
1749
1763
|
* @param connection - The HAP connection from which the request originated from.
|
|
1750
1764
|
* @param context - Deprecated parameter. There for backwards compatibility.
|
|
1751
|
-
* @private
|
|
1765
|
+
* @private
|
|
1752
1766
|
*/
|
|
1753
1767
|
async handleGetRequest(connection, context) {
|
|
1754
1768
|
if (!this.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if we are allowed to read from this characteristic
|
|
@@ -1760,7 +1774,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1760
1774
|
}
|
|
1761
1775
|
if (this.getHandler) {
|
|
1762
1776
|
if (this.listeners("get" /* CharacteristicEventTypes.GET */).length > 0) {
|
|
1763
|
-
this.characteristicWarning(
|
|
1777
|
+
this.characteristicWarning('Ignoring on(\'get\') handler as onGet handler was defined instead');
|
|
1764
1778
|
}
|
|
1765
1779
|
try {
|
|
1766
1780
|
let value = await this.getHandler(context, connection);
|
|
@@ -1776,16 +1790,22 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1776
1790
|
const oldValue = this.value;
|
|
1777
1791
|
this.value = value;
|
|
1778
1792
|
if (oldValue !== value) { // emit a change event if necessary
|
|
1779
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1793
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1794
|
+
originator: connection,
|
|
1795
|
+
oldValue,
|
|
1796
|
+
newValue: value,
|
|
1797
|
+
reason: "read" /* ChangeReason.READ */,
|
|
1798
|
+
context,
|
|
1799
|
+
});
|
|
1780
1800
|
}
|
|
1781
1801
|
return value;
|
|
1782
1802
|
}
|
|
1783
1803
|
catch (error) {
|
|
1784
|
-
if (typeof error ===
|
|
1785
|
-
const hapStatusError = new
|
|
1804
|
+
if (typeof error === 'number') {
|
|
1805
|
+
const hapStatusError = new HapStatusError(error);
|
|
1786
1806
|
this.statusCode = hapStatusError.hapStatus;
|
|
1787
1807
|
}
|
|
1788
|
-
else if (error instanceof
|
|
1808
|
+
else if (error instanceof HapStatusError) {
|
|
1789
1809
|
this.statusCode = error.hapStatus;
|
|
1790
1810
|
}
|
|
1791
1811
|
else {
|
|
@@ -1809,18 +1829,18 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1809
1829
|
}
|
|
1810
1830
|
return new Promise((resolve, reject) => {
|
|
1811
1831
|
try {
|
|
1812
|
-
this.emit("get" /* CharacteristicEventTypes.GET */,
|
|
1832
|
+
this.emit("get" /* CharacteristicEventTypes.GET */, once((status, value) => {
|
|
1813
1833
|
if (status) {
|
|
1814
|
-
if (typeof status ===
|
|
1815
|
-
const hapStatusError = new
|
|
1834
|
+
if (typeof status === 'number') {
|
|
1835
|
+
const hapStatusError = new HapStatusError(status);
|
|
1816
1836
|
this.statusCode = hapStatusError.hapStatus;
|
|
1817
1837
|
}
|
|
1818
|
-
else if (status instanceof
|
|
1838
|
+
else if (status instanceof HapStatusError) {
|
|
1819
1839
|
this.statusCode = status.hapStatus;
|
|
1820
1840
|
}
|
|
1821
1841
|
else {
|
|
1822
|
-
debug(
|
|
1823
|
-
this.statusCode =
|
|
1842
|
+
debug('[%s] Received error from get handler %s', this.displayName, status.stack);
|
|
1843
|
+
this.statusCode = extractHAPStatusFromError(status);
|
|
1824
1844
|
}
|
|
1825
1845
|
reject(this.statusCode);
|
|
1826
1846
|
return;
|
|
@@ -1840,7 +1860,13 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1840
1860
|
this.value = value;
|
|
1841
1861
|
resolve(value);
|
|
1842
1862
|
if (oldValue !== value) { // emit a change event if necessary
|
|
1843
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1863
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1864
|
+
originator: connection,
|
|
1865
|
+
oldValue,
|
|
1866
|
+
newValue: value,
|
|
1867
|
+
reason: "read" /* ChangeReason.READ */,
|
|
1868
|
+
context,
|
|
1869
|
+
});
|
|
1844
1870
|
}
|
|
1845
1871
|
}), context, connection);
|
|
1846
1872
|
}
|
|
@@ -1858,8 +1884,8 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1858
1884
|
* @param connection - The connection from which the request originated from
|
|
1859
1885
|
* @param context - Deprecated parameter. There for backwards compatibility.
|
|
1860
1886
|
* @returns Promise resolve to void in normal operation. When characteristic supports write-response, HAP
|
|
1861
|
-
*
|
|
1862
|
-
*
|
|
1887
|
+
* requests a write-response and the set handler returns a write-response value, the respective
|
|
1888
|
+
* write response value is resolved.
|
|
1863
1889
|
* @private
|
|
1864
1890
|
*/
|
|
1865
1891
|
async handleSetRequest(value, connection, context) {
|
|
@@ -1878,7 +1904,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1878
1904
|
const oldValue = this.value;
|
|
1879
1905
|
if (this.setHandler) {
|
|
1880
1906
|
if (this.listeners("set" /* CharacteristicEventTypes.SET */).length > 0) {
|
|
1881
|
-
this.characteristicWarning(
|
|
1907
|
+
this.characteristicWarning('Ignoring on(\'set\') handler as onSet handler was defined instead');
|
|
1882
1908
|
}
|
|
1883
1909
|
try {
|
|
1884
1910
|
const writeResponse = await this.setHandler(value, context, connection);
|
|
@@ -1889,19 +1915,25 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1889
1915
|
}
|
|
1890
1916
|
else {
|
|
1891
1917
|
if (writeResponse != null) {
|
|
1892
|
-
this.characteristicWarning(
|
|
1918
|
+
this.characteristicWarning('SET handler returned write response value, though the characteristic doesn\'t support write response', "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
|
|
1893
1919
|
}
|
|
1894
1920
|
this.value = value;
|
|
1895
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1921
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1922
|
+
originator: connection,
|
|
1923
|
+
oldValue,
|
|
1924
|
+
newValue: value,
|
|
1925
|
+
reason: "write" /* ChangeReason.WRITE */,
|
|
1926
|
+
context,
|
|
1927
|
+
});
|
|
1896
1928
|
return;
|
|
1897
1929
|
}
|
|
1898
1930
|
}
|
|
1899
1931
|
catch (error) {
|
|
1900
|
-
if (typeof error ===
|
|
1901
|
-
const hapStatusError = new
|
|
1932
|
+
if (typeof error === 'number') {
|
|
1933
|
+
const hapStatusError = new HapStatusError(error);
|
|
1902
1934
|
this.statusCode = hapStatusError.hapStatus;
|
|
1903
1935
|
}
|
|
1904
|
-
else if (error instanceof
|
|
1936
|
+
else if (error instanceof HapStatusError) {
|
|
1905
1937
|
this.statusCode = error.hapStatus;
|
|
1906
1938
|
}
|
|
1907
1939
|
else {
|
|
@@ -1913,24 +1945,30 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1913
1945
|
}
|
|
1914
1946
|
if (this.listeners("set" /* CharacteristicEventTypes.SET */).length === 0) {
|
|
1915
1947
|
this.value = value;
|
|
1916
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1948
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1949
|
+
originator: connection,
|
|
1950
|
+
oldValue,
|
|
1951
|
+
newValue: value,
|
|
1952
|
+
reason: "write" /* ChangeReason.WRITE */,
|
|
1953
|
+
context,
|
|
1954
|
+
});
|
|
1917
1955
|
return Promise.resolve();
|
|
1918
1956
|
}
|
|
1919
1957
|
else {
|
|
1920
1958
|
return new Promise((resolve, reject) => {
|
|
1921
1959
|
try {
|
|
1922
|
-
this.emit("set" /* CharacteristicEventTypes.SET */, value,
|
|
1960
|
+
this.emit("set" /* CharacteristicEventTypes.SET */, value, once((status, writeResponse) => {
|
|
1923
1961
|
if (status) {
|
|
1924
|
-
if (typeof status ===
|
|
1925
|
-
const hapStatusError = new
|
|
1962
|
+
if (typeof status === 'number') {
|
|
1963
|
+
const hapStatusError = new HapStatusError(status);
|
|
1926
1964
|
this.statusCode = hapStatusError.hapStatus;
|
|
1927
1965
|
}
|
|
1928
|
-
else if (status instanceof
|
|
1966
|
+
else if (status instanceof HapStatusError) {
|
|
1929
1967
|
this.statusCode = status.hapStatus;
|
|
1930
1968
|
}
|
|
1931
1969
|
else {
|
|
1932
|
-
debug(
|
|
1933
|
-
this.statusCode =
|
|
1970
|
+
debug('[%s] Received error from set handler %s', this.displayName, status.stack);
|
|
1971
|
+
this.statusCode = extractHAPStatusFromError(status);
|
|
1934
1972
|
}
|
|
1935
1973
|
reject(this.statusCode);
|
|
1936
1974
|
return;
|
|
@@ -1952,11 +1990,17 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1952
1990
|
}
|
|
1953
1991
|
else {
|
|
1954
1992
|
if (writeResponse != null) {
|
|
1955
|
-
this.characteristicWarning(
|
|
1993
|
+
this.characteristicWarning('SET handler returned write response value, though the characteristic doesn\'t support write response', "debug-message" /* CharacteristicWarningType.DEBUG_MESSAGE */);
|
|
1956
1994
|
}
|
|
1957
1995
|
this.value = value;
|
|
1958
1996
|
resolve();
|
|
1959
|
-
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1997
|
+
this.emit("change" /* CharacteristicEventTypes.CHANGE */, {
|
|
1998
|
+
originator: connection,
|
|
1999
|
+
oldValue,
|
|
2000
|
+
newValue: value,
|
|
2001
|
+
reason: "write" /* ChangeReason.WRITE */,
|
|
2002
|
+
context,
|
|
2003
|
+
});
|
|
1960
2004
|
}
|
|
1961
2005
|
}), context, connection);
|
|
1962
2006
|
}
|
|
@@ -1999,20 +2043,20 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
1999
2043
|
case "string" /* Formats.STRING */:
|
|
2000
2044
|
switch (this.UUID) {
|
|
2001
2045
|
case Characteristic.Manufacturer.UUID:
|
|
2002
|
-
return
|
|
2046
|
+
return 'Default-Manufacturer';
|
|
2003
2047
|
case Characteristic.Model.UUID:
|
|
2004
|
-
return
|
|
2048
|
+
return 'Default-Model';
|
|
2005
2049
|
case Characteristic.SerialNumber.UUID:
|
|
2006
|
-
return
|
|
2050
|
+
return 'Default-SerialNumber';
|
|
2007
2051
|
case Characteristic.FirmwareRevision.UUID:
|
|
2008
|
-
return
|
|
2052
|
+
return '0.0.0';
|
|
2009
2053
|
default:
|
|
2010
|
-
return
|
|
2054
|
+
return '';
|
|
2011
2055
|
}
|
|
2012
2056
|
case "data" /* Formats.DATA */:
|
|
2013
|
-
return
|
|
2057
|
+
return ''; // who knows!
|
|
2014
2058
|
case "tlv8" /* Formats.TLV8 */:
|
|
2015
|
-
return
|
|
2059
|
+
return ''; // who knows!
|
|
2016
2060
|
case "int" /* Formats.INT */:
|
|
2017
2061
|
case "float" /* Formats.FLOAT */:
|
|
2018
2062
|
case "uint8" /* Formats.UINT8 */:
|
|
@@ -2023,10 +2067,10 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2023
2067
|
case Characteristic.CurrentTemperature.UUID:
|
|
2024
2068
|
return 0; // some existing integrations expect this to be 0 by default
|
|
2025
2069
|
default: {
|
|
2026
|
-
if (this.props.validValues?.length && typeof this.props.validValues[0] ===
|
|
2070
|
+
if (this.props.validValues?.length && typeof this.props.validValues[0] === 'number') {
|
|
2027
2071
|
return this.props.validValues[0];
|
|
2028
2072
|
}
|
|
2029
|
-
if (typeof this.props.minValue ===
|
|
2073
|
+
if (typeof this.props.minValue === 'number' && Number.isFinite(this.props.minValue)) {
|
|
2030
2074
|
return this.props.minValue;
|
|
2031
2075
|
}
|
|
2032
2076
|
return 0;
|
|
@@ -2048,10 +2092,10 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2048
2092
|
}
|
|
2049
2093
|
switch (this.props.format) {
|
|
2050
2094
|
case "bool" /* Formats.BOOL */: {
|
|
2051
|
-
if (typeof value ===
|
|
2095
|
+
if (typeof value === 'boolean') {
|
|
2052
2096
|
return value;
|
|
2053
2097
|
}
|
|
2054
|
-
if (typeof value ===
|
|
2098
|
+
if (typeof value === 'number' && (value === 1 || value === 0)) {
|
|
2055
2099
|
return Boolean(value);
|
|
2056
2100
|
}
|
|
2057
2101
|
throw new Error(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
|
|
@@ -2062,18 +2106,18 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2062
2106
|
case "uint16" /* Formats.UINT16 */:
|
|
2063
2107
|
case "uint32" /* Formats.UINT32 */:
|
|
2064
2108
|
case "uint64" /* Formats.UINT64 */: {
|
|
2065
|
-
if (typeof value ===
|
|
2109
|
+
if (typeof value === 'boolean') {
|
|
2066
2110
|
value = value ? 1 : 0;
|
|
2067
2111
|
}
|
|
2068
|
-
if (typeof value !==
|
|
2069
|
-
throw new
|
|
2112
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
2113
|
+
throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
|
|
2070
2114
|
}
|
|
2071
|
-
const numericMin = maxWithUndefined(this.props.minValue,
|
|
2072
|
-
const numericMax = minWithUndefined(this.props.maxValue,
|
|
2073
|
-
if (typeof numericMin ===
|
|
2115
|
+
const numericMin = maxWithUndefined(this.props.minValue, numericLowerBound(this.props.format));
|
|
2116
|
+
const numericMax = minWithUndefined(this.props.maxValue, numericUpperBound(this.props.format));
|
|
2117
|
+
if (typeof numericMin === 'number' && value < numericMin) {
|
|
2074
2118
|
throw new Error(`Client supplied value of ${value} is less than the minimum allowed value of ${numericMin}`);
|
|
2075
2119
|
}
|
|
2076
|
-
if (typeof numericMax ===
|
|
2120
|
+
if (typeof numericMax === 'number' && value > numericMax) {
|
|
2077
2121
|
throw new Error(`Client supplied value of ${value} is greater than the maximum allowed value of ${numericMax}`);
|
|
2078
2122
|
}
|
|
2079
2123
|
if (this.props.validValues && !this.props.validValues.includes(value)) {
|
|
@@ -2090,29 +2134,29 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2090
2134
|
return value;
|
|
2091
2135
|
}
|
|
2092
2136
|
case "string" /* Formats.STRING */: {
|
|
2093
|
-
if (typeof value !==
|
|
2094
|
-
throw new
|
|
2137
|
+
if (typeof value !== 'string') {
|
|
2138
|
+
throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
|
|
2095
2139
|
}
|
|
2096
|
-
const maxLength = this.props.maxLen
|
|
2140
|
+
const maxLength = this.props.maxLen ?? 64; // default is 64; max is 256 which is set in setProps
|
|
2097
2141
|
if (value.length > maxLength) {
|
|
2098
2142
|
throw new Error(`Client supplied value length of ${value.length} exceeds maximum length allowed of ${maxLength}`);
|
|
2099
2143
|
}
|
|
2100
2144
|
return value;
|
|
2101
2145
|
}
|
|
2102
2146
|
case "data" /* Formats.DATA */: {
|
|
2103
|
-
if (typeof value !==
|
|
2104
|
-
throw new
|
|
2147
|
+
if (typeof value !== 'string') {
|
|
2148
|
+
throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
|
|
2105
2149
|
}
|
|
2106
2150
|
// we don't validate base64 here
|
|
2107
|
-
const maxLength = this.props.maxDataLen
|
|
2151
|
+
const maxLength = this.props.maxDataLen ?? 0x200000; // default is 0x200000
|
|
2108
2152
|
if (value.length > maxLength) {
|
|
2109
2153
|
throw new Error(`Client supplied value length of ${value.length} exceeds maximum length allowed of ${maxLength}`);
|
|
2110
2154
|
}
|
|
2111
2155
|
return value;
|
|
2112
2156
|
}
|
|
2113
2157
|
case "tlv8" /* Formats.TLV8 */:
|
|
2114
|
-
if (typeof value !==
|
|
2115
|
-
throw new
|
|
2158
|
+
if (typeof value !== 'string') {
|
|
2159
|
+
throw new TypeError(`Client supplied invalid type for ${this.props.format}: "${value}" (${typeof value})`);
|
|
2116
2160
|
}
|
|
2117
2161
|
return value;
|
|
2118
2162
|
}
|
|
@@ -2129,7 +2173,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2129
2173
|
validateUserInput(value, warningType = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */) {
|
|
2130
2174
|
if (value === null) {
|
|
2131
2175
|
if (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID) { // mirrors the statement in case: Formats.STRING
|
|
2132
|
-
this.characteristicWarning(
|
|
2176
|
+
this.characteristicWarning('characteristic must have a non null value otherwise HomeKit will reject this accessory, ignoring new value', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
|
|
2133
2177
|
return this.value; // don't change the value
|
|
2134
2178
|
}
|
|
2135
2179
|
if (this.props.format === "data" /* Formats.DATA */ || this.props.format === "tlv8" /* Formats.TLV8 */) {
|
|
@@ -2145,11 +2189,11 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2145
2189
|
* As an intermediate step we kept the behavior but added a warning printed to the console.
|
|
2146
2190
|
* In a future update we will do the breaking change of return null below!
|
|
2147
2191
|
*/
|
|
2148
|
-
if (this.UUID.endsWith(
|
|
2192
|
+
if (this.UUID.endsWith(BASE_UUID)) { // we have an apple defined characteristic (at least assuming nobody else uses the UUID namespace)
|
|
2149
2193
|
if (this.UUID === Characteristic.ProgrammableSwitchEvent.UUID) {
|
|
2150
2194
|
return value; // null is allowed as a value for ProgrammableSwitchEvent
|
|
2151
2195
|
}
|
|
2152
|
-
this.characteristicWarning(
|
|
2196
|
+
this.characteristicWarning('characteristic was supplied illegal value: null! Home App will reject null for Apple defined characteristics', warningType);
|
|
2153
2197
|
// if the value has been set previously, return it now, otherwise continue with validation to have a default value set.
|
|
2154
2198
|
if (this.value !== null) {
|
|
2155
2199
|
return this.value;
|
|
@@ -2162,16 +2206,16 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2162
2206
|
}
|
|
2163
2207
|
switch (this.props.format) {
|
|
2164
2208
|
case "bool" /* Formats.BOOL */: {
|
|
2165
|
-
if (typeof value ===
|
|
2209
|
+
if (typeof value === 'boolean') {
|
|
2166
2210
|
return value;
|
|
2167
2211
|
}
|
|
2168
|
-
if (typeof value ===
|
|
2212
|
+
if (typeof value === 'number') {
|
|
2169
2213
|
return value === 1;
|
|
2170
2214
|
}
|
|
2171
|
-
if (typeof value ===
|
|
2172
|
-
return value ===
|
|
2215
|
+
if (typeof value === 'string') {
|
|
2216
|
+
return value === '1' || value === 'true';
|
|
2173
2217
|
}
|
|
2174
|
-
this.characteristicWarning(
|
|
2218
|
+
this.characteristicWarning(`characteristic value expected boolean and received ${typeof value}`, warningType);
|
|
2175
2219
|
return false;
|
|
2176
2220
|
}
|
|
2177
2221
|
case "int" /* Formats.INT */:
|
|
@@ -2180,18 +2224,22 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2180
2224
|
case "uint16" /* Formats.UINT16 */:
|
|
2181
2225
|
case "uint32" /* Formats.UINT32 */:
|
|
2182
2226
|
case "uint64" /* Formats.UINT64 */: {
|
|
2183
|
-
if (typeof value ===
|
|
2227
|
+
if (typeof value === 'boolean') {
|
|
2184
2228
|
value = value ? 1 : 0;
|
|
2185
2229
|
}
|
|
2186
|
-
if (typeof value ===
|
|
2187
|
-
value = this.props.format === "float" /* Formats.FLOAT */
|
|
2230
|
+
if (typeof value === 'string') {
|
|
2231
|
+
value = this.props.format === "float" /* Formats.FLOAT */
|
|
2232
|
+
? Number.parseFloat(value)
|
|
2233
|
+
: parseInt(value, 10);
|
|
2188
2234
|
}
|
|
2189
|
-
if (typeof value !==
|
|
2235
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
2190
2236
|
this.characteristicWarning(`characteristic value expected valid finite number and received "${value}" (${typeof value})`, warningType);
|
|
2191
|
-
value = typeof this.value ===
|
|
2237
|
+
value = typeof this.value === 'number'
|
|
2238
|
+
? this.value
|
|
2239
|
+
: this.props.minValue || 0;
|
|
2192
2240
|
}
|
|
2193
|
-
const numericMin = maxWithUndefined(this.props.minValue,
|
|
2194
|
-
let numericMax = minWithUndefined(this.props.maxValue,
|
|
2241
|
+
const numericMin = maxWithUndefined(this.props.minValue, numericLowerBound(this.props.format));
|
|
2242
|
+
let numericMax = minWithUndefined(this.props.maxValue, numericUpperBound(this.props.format));
|
|
2195
2243
|
let stepValue;
|
|
2196
2244
|
if (this.props.format === "float" /* Formats.FLOAT */) {
|
|
2197
2245
|
stepValue = this.props.minStep;
|
|
@@ -2200,7 +2248,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2200
2248
|
stepValue = maxWithUndefined(this.props.minStep, 1);
|
|
2201
2249
|
}
|
|
2202
2250
|
if (stepValue != null && stepValue > 0) {
|
|
2203
|
-
const minValue = this.props.minValue
|
|
2251
|
+
const minValue = this.props.minValue ?? 0;
|
|
2204
2252
|
if (numericMax != null) {
|
|
2205
2253
|
numericMax = stepValue * Math.floor((numericMax - minValue) / stepValue) + minValue;
|
|
2206
2254
|
}
|
|
@@ -2216,7 +2264,9 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2216
2264
|
}
|
|
2217
2265
|
if (this.props.validValues && !this.props.validValues.includes(value)) {
|
|
2218
2266
|
this.characteristicWarning(`characteristic value ${value} is not contained in valid values array`, warningType);
|
|
2219
|
-
return this.props.validValues.includes(this.value)
|
|
2267
|
+
return this.props.validValues.includes(this.value)
|
|
2268
|
+
? this.value
|
|
2269
|
+
: (this.props.validValues[0] || 0);
|
|
2220
2270
|
}
|
|
2221
2271
|
if (this.props.validValueRanges && this.props.validValueRanges.length === 2) {
|
|
2222
2272
|
if (value < this.props.validValueRanges[0]) {
|
|
@@ -2233,14 +2283,16 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2233
2283
|
return value;
|
|
2234
2284
|
}
|
|
2235
2285
|
case "string" /* Formats.STRING */: {
|
|
2236
|
-
if (typeof value ===
|
|
2237
|
-
this.characteristicWarning(
|
|
2238
|
-
|
|
2286
|
+
if (typeof value === 'number') {
|
|
2287
|
+
this.characteristicWarning('characteristic was supplied illegal value: number instead of string, '
|
|
2288
|
+
+ 'supplying illegal values will throw errors in the future', warningType);
|
|
2239
2289
|
value = String(value);
|
|
2240
2290
|
}
|
|
2241
|
-
if (typeof value !==
|
|
2242
|
-
this.characteristicWarning(
|
|
2243
|
-
value = typeof this.value ===
|
|
2291
|
+
if (typeof value !== 'string') {
|
|
2292
|
+
this.characteristicWarning(`characteristic value expected string and received ${typeof value}`, warningType);
|
|
2293
|
+
value = typeof this.value === 'string'
|
|
2294
|
+
? this.value
|
|
2295
|
+
: `${value}`;
|
|
2244
2296
|
}
|
|
2245
2297
|
// mirrors the case value = null at the beginning
|
|
2246
2298
|
if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) {
|
|
@@ -2256,30 +2308,30 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2256
2308
|
return value;
|
|
2257
2309
|
}
|
|
2258
2310
|
case "data" /* Formats.DATA */:
|
|
2259
|
-
if (typeof value !==
|
|
2260
|
-
throw new
|
|
2311
|
+
if (typeof value !== 'string') {
|
|
2312
|
+
throw new TypeError('characteristic with DATA format must have string value');
|
|
2261
2313
|
}
|
|
2262
2314
|
if (this.props.maxDataLen != null && value.length > this.props.maxDataLen) {
|
|
2263
2315
|
// can't cut it as we would basically set binary rubbish afterwards
|
|
2264
|
-
throw new Error(
|
|
2316
|
+
throw new Error('characteristic with DATA format exceeds specified maxDataLen');
|
|
2265
2317
|
}
|
|
2266
2318
|
return value;
|
|
2267
2319
|
case "tlv8" /* Formats.TLV8 */:
|
|
2268
2320
|
if (value === undefined) {
|
|
2269
|
-
this.characteristicWarning(
|
|
2321
|
+
this.characteristicWarning('characteristic was supplied illegal value: undefined', warningType);
|
|
2270
2322
|
return this.value;
|
|
2271
2323
|
}
|
|
2272
2324
|
return value; // we trust that this is valid tlv8
|
|
2273
2325
|
}
|
|
2274
2326
|
// hopefully it shouldn't get to this point
|
|
2275
2327
|
if (value === undefined) {
|
|
2276
|
-
this.characteristicWarning(
|
|
2328
|
+
this.characteristicWarning('characteristic was supplied illegal value: undefined', "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */);
|
|
2277
2329
|
return this.value;
|
|
2278
2330
|
}
|
|
2279
2331
|
return value;
|
|
2280
2332
|
}
|
|
2281
2333
|
/**
|
|
2282
|
-
* @private
|
|
2334
|
+
* @private
|
|
2283
2335
|
*/
|
|
2284
2336
|
_assignID(identifierCache, accessoryName, serviceUUID, serviceSubtype) {
|
|
2285
2337
|
// generate our IID based on our UUID
|
|
@@ -2295,12 +2347,14 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2295
2347
|
* (see {@link validateUserInput}), and on something like {@link Characteristic.PasswordSetting} that value is the secret itself, so those keep the
|
|
2296
2348
|
* long-standing behaviour of going nowhere until an accessory is listening.
|
|
2297
2349
|
*/
|
|
2298
|
-
characteristicWarning(message, type = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */,
|
|
2350
|
+
characteristicWarning(message, type = "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */,
|
|
2351
|
+
// eslint-disable-next-line unicorn/error-message -- only here to capture the stack
|
|
2352
|
+
stack = new Error().stack, reportWhenUnheard = false) {
|
|
2299
2353
|
const heard = this.emit("characteristic-warning" /* CharacteristicEventTypes.CHARACTERISTIC_WARNING */, type, message, stack);
|
|
2300
2354
|
if (!heard && reportWhenUnheard) {
|
|
2301
2355
|
// The stack the subscribers would have received goes with it: a characteristic with no service carries no accessory or service name, so it is
|
|
2302
2356
|
// the only thing that locates the fault.
|
|
2303
|
-
console.warn(`HAP-NodeJS WARNING: [${this.displayName} (${this.UUID})] ${message}\nThrown at: ${stack ??
|
|
2357
|
+
console.warn(`HAP-NodeJS WARNING: [${this.displayName} (${this.UUID})] ${message}\nThrown at: ${stack ?? 'unknown'}`);
|
|
2304
2358
|
}
|
|
2305
2359
|
}
|
|
2306
2360
|
/**
|
|
@@ -2344,7 +2398,7 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2344
2398
|
}
|
|
2345
2399
|
/**
|
|
2346
2400
|
* Returns a JSON representation of this characteristic suitable for delivering to HAP clients.
|
|
2347
|
-
* @private
|
|
2401
|
+
* @private
|
|
2348
2402
|
*/
|
|
2349
2403
|
async toHAP(connection, contactGetHandlers = true) {
|
|
2350
2404
|
const object = this.internalHAPRepresentation();
|
|
@@ -2359,63 +2413,63 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2359
2413
|
const value = contactGetHandlers
|
|
2360
2414
|
? await this.handleGetRequest(connection).catch(() => {
|
|
2361
2415
|
const value = this.getDefaultValue();
|
|
2362
|
-
debug(
|
|
2416
|
+
debug('[%s] Error getting value for characteristic on /accessories request. Returning default value instead: %s', this.displayName, `${value}`);
|
|
2363
2417
|
return value; // use default value
|
|
2364
2418
|
})
|
|
2365
2419
|
: this.value;
|
|
2366
|
-
object.value =
|
|
2420
|
+
object.value = formatOutgoingCharacteristicValue(value, this.props);
|
|
2367
2421
|
}
|
|
2368
2422
|
return object;
|
|
2369
2423
|
}
|
|
2370
2424
|
/**
|
|
2371
2425
|
* Returns a JSON representation of this characteristic without the value.
|
|
2372
|
-
* @private
|
|
2426
|
+
* @private
|
|
2373
2427
|
*/
|
|
2374
2428
|
internalHAPRepresentation() {
|
|
2375
|
-
(
|
|
2429
|
+
assert(this.iid, `iid cannot be undefined for characteristic '${this.displayName}'`);
|
|
2376
2430
|
// TODO include the value for characteristics of the AccessoryInformation service
|
|
2377
2431
|
return {
|
|
2378
|
-
type:
|
|
2379
|
-
iid: this.iid,
|
|
2380
|
-
value: null,
|
|
2381
|
-
perms: this.props.perms,
|
|
2382
|
-
description: this.props.description || this.displayName,
|
|
2383
|
-
format: this.props.format,
|
|
2384
|
-
unit: this.props.unit,
|
|
2385
|
-
minValue: this.props.minValue,
|
|
2386
|
-
maxValue: this.props.maxValue,
|
|
2387
|
-
minStep: this.props.minStep,
|
|
2388
|
-
maxLen: this.props.maxLen,
|
|
2389
|
-
maxDataLen: this.props.maxDataLen,
|
|
2390
|
-
|
|
2391
|
-
|
|
2432
|
+
'type': toShortForm(this.UUID),
|
|
2433
|
+
'iid': this.iid,
|
|
2434
|
+
'value': null,
|
|
2435
|
+
'perms': this.props.perms,
|
|
2436
|
+
'description': this.props.description || this.displayName,
|
|
2437
|
+
'format': this.props.format,
|
|
2438
|
+
'unit': this.props.unit,
|
|
2439
|
+
'minValue': this.props.minValue,
|
|
2440
|
+
'maxValue': this.props.maxValue,
|
|
2441
|
+
'minStep': this.props.minStep,
|
|
2442
|
+
'maxLen': this.props.maxLen,
|
|
2443
|
+
'maxDataLen': this.props.maxDataLen,
|
|
2444
|
+
'valid-values': this.props.validValues,
|
|
2445
|
+
'valid-values-range': this.props.validValueRanges,
|
|
2392
2446
|
};
|
|
2393
2447
|
}
|
|
2394
2448
|
/**
|
|
2395
2449
|
* Serialize characteristic into json string.
|
|
2396
2450
|
*
|
|
2397
2451
|
* @param characteristic - Characteristic object.
|
|
2398
|
-
* @private
|
|
2452
|
+
* @private
|
|
2399
2453
|
*/
|
|
2400
2454
|
static serialize(characteristic) {
|
|
2401
2455
|
let constructorName;
|
|
2402
|
-
if (characteristic.constructor.name !==
|
|
2456
|
+
if (characteristic.constructor.name !== 'Characteristic') {
|
|
2403
2457
|
constructorName = characteristic.constructor.name;
|
|
2404
2458
|
}
|
|
2405
2459
|
return {
|
|
2406
2460
|
displayName: characteristic.displayName,
|
|
2407
2461
|
UUID: characteristic.UUID,
|
|
2408
2462
|
eventOnlyCharacteristic: characteristic.UUID === Characteristic.ProgrammableSwitchEvent.UUID, // support downgrades for now
|
|
2409
|
-
constructorName
|
|
2463
|
+
constructorName,
|
|
2410
2464
|
value: characteristic.value,
|
|
2411
|
-
props:
|
|
2465
|
+
props: clone({}, characteristic.props),
|
|
2412
2466
|
};
|
|
2413
2467
|
}
|
|
2414
2468
|
/**
|
|
2415
2469
|
* Deserialize characteristic from json string.
|
|
2416
2470
|
*
|
|
2417
2471
|
* @param json - Json string representing a characteristic.
|
|
2418
|
-
* @private
|
|
2472
|
+
* @private
|
|
2419
2473
|
*/
|
|
2420
2474
|
static deserialize(json) {
|
|
2421
2475
|
let characteristic;
|
|
@@ -2433,9 +2487,4 @@ class Characteristic extends events_1.EventEmitter {
|
|
|
2433
2487
|
return characteristic;
|
|
2434
2488
|
}
|
|
2435
2489
|
}
|
|
2436
|
-
exports.Characteristic = Characteristic;
|
|
2437
|
-
// We have a cyclic dependency problem. Within this file we have the definitions of "./definitions" as
|
|
2438
|
-
// type imports only (in order to define the static properties). Setting those properties is done outside
|
|
2439
|
-
// this file, within the definition files. Therefore, we import it at the end of this file. Seems weird, but is important.
|
|
2440
|
-
require("./definitions/CharacteristicDefinitions");
|
|
2441
2490
|
//# sourceMappingURL=Characteristic.js.map
|