hap-nodejs 0.12.3-beta.2 → 0.12.3-beta.21
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 +1 -0
- package/dist/accessories/AirConditioner_accessory.js +24 -24
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +23 -23
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +292 -373
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +15 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +31 -21
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +45 -48
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +11 -11
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +8 -8
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +10 -10
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +11 -11
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +19 -19
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +17 -17
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +6 -6
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +36 -47
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.js +2 -2
- package/dist/accessories/types.js.map +1 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -28
- package/dist/index.js.map +1 -1
- package/dist/lib/Accessory.d.ts +1 -58
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +747 -1149
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +1 -2
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +392 -524
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.js +6 -10
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +2 -133
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +1467 -669
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +0 -10
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +216 -280
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +1 -51
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +474 -322
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.js +112 -104
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +0 -65
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +255 -278
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +318 -381
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +0 -1
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +1 -2
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -3
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +217 -218
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +0 -4
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +189 -256
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/DoorbellController.js +38 -39
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +0 -14
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +340 -415
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.js +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +56 -57
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +259 -304
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +0 -5
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +252 -269
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.js +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -106
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +2000 -2995
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -32
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +820 -1147
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +383 -679
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +29 -29
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.js +1 -1
- package/dist/lib/model/AccessoryInfo.js +101 -136
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.js +86 -89
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.js +15 -16
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.js +49 -49
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +40 -44
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -1
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +7 -11
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.js +5 -27
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.js +8 -12
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +301 -409
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.js +31 -32
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.js +9 -12
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +32 -53
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -8
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.js +8 -13
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.js +2 -3
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.js +5 -5
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +0 -27
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +71 -113
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +0 -9
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +15 -33
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +0 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +10 -10
- package/dist/BridgedCore.d.ts +0 -2
- package/dist/BridgedCore.d.ts.map +0 -1
- package/dist/BridgedCore.js +0 -43
- package/dist/BridgedCore.js.map +0 -1
- package/dist/Core.d.ts +0 -2
- package/dist/Core.d.ts.map +0 -1
- package/dist/Core.js +0 -52
- package/dist/Core.js.map +0 -1
- package/dist/lib/AccessoryLoader.d.ts +0 -28
- package/dist/lib/AccessoryLoader.d.ts.map +0 -1
- package/dist/lib/AccessoryLoader.js +0 -166
- package/dist/lib/AccessoryLoader.js.map +0 -1
- package/dist/lib/camera/Camera.d.ts +0 -43
- package/dist/lib/camera/Camera.d.ts.map +0 -1
- package/dist/lib/camera/Camera.js +0 -36
- package/dist/lib/camera/Camera.js.map +0 -1
package/dist/lib/Service.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Service = exports.ServiceEventTypes = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const Characteristic_1 = require("./Characteristic");
|
|
9
|
+
const uuid_1 = require("./util/uuid");
|
|
10
|
+
const checkName_1 = require("./util/checkName");
|
|
11
|
+
const debug = (0, debug_1.default)("HAP-NodeJS:Service");
|
|
12
12
|
/**
|
|
13
13
|
* HAP spec allows a maximum of 100 characteristics per service!
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
const MAX_CHARACTERISTICS = 100;
|
|
16
16
|
/**
|
|
17
17
|
* @group Service
|
|
18
18
|
*/
|
|
@@ -45,42 +45,339 @@ var ServiceEventTypes;
|
|
|
45
45
|
* @group Service
|
|
46
46
|
*/
|
|
47
47
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
class Service extends events_1.EventEmitter {
|
|
49
|
+
// Service MUST NOT have any other static variables
|
|
50
|
+
// Pattern below is for automatic detection of the section of defined services. Used by the generator
|
|
51
|
+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
|
52
|
+
/**
|
|
53
|
+
* @group Service Definitions
|
|
54
|
+
*/
|
|
55
|
+
static AccessCode;
|
|
56
|
+
/**
|
|
57
|
+
* @group Service Definitions
|
|
58
|
+
*/
|
|
59
|
+
static AccessControl;
|
|
60
|
+
/**
|
|
61
|
+
* @group Service Definitions
|
|
62
|
+
*/
|
|
63
|
+
static AccessoryInformation;
|
|
64
|
+
/**
|
|
65
|
+
* @group Service Definitions
|
|
66
|
+
*/
|
|
67
|
+
static AccessoryMetrics;
|
|
68
|
+
/**
|
|
69
|
+
* @group Service Definitions
|
|
70
|
+
*/
|
|
71
|
+
static AccessoryRuntimeInformation;
|
|
72
|
+
/**
|
|
73
|
+
* @group Service Definitions
|
|
74
|
+
*/
|
|
75
|
+
static AirPurifier;
|
|
76
|
+
/**
|
|
77
|
+
* @group Service Definitions
|
|
78
|
+
*/
|
|
79
|
+
static AirQualitySensor;
|
|
80
|
+
/**
|
|
81
|
+
* @group Service Definitions
|
|
82
|
+
*/
|
|
83
|
+
static AssetUpdate;
|
|
84
|
+
/**
|
|
85
|
+
* @group Service Definitions
|
|
86
|
+
*/
|
|
87
|
+
static Assistant;
|
|
88
|
+
/**
|
|
89
|
+
* @group Service Definitions
|
|
90
|
+
*/
|
|
91
|
+
static AudioStreamManagement;
|
|
92
|
+
/**
|
|
93
|
+
* @group Service Definitions
|
|
94
|
+
*/
|
|
95
|
+
static Battery;
|
|
96
|
+
/**
|
|
97
|
+
* @group Service Definitions
|
|
98
|
+
*/
|
|
99
|
+
static CameraOperatingMode;
|
|
100
|
+
/**
|
|
101
|
+
* @group Service Definitions
|
|
102
|
+
*/
|
|
103
|
+
static CameraRecordingManagement;
|
|
104
|
+
/**
|
|
105
|
+
* @group Service Definitions
|
|
106
|
+
*/
|
|
107
|
+
static CameraRTPStreamManagement;
|
|
108
|
+
/**
|
|
109
|
+
* @group Service Definitions
|
|
110
|
+
*/
|
|
111
|
+
static CarbonDioxideSensor;
|
|
112
|
+
/**
|
|
113
|
+
* @group Service Definitions
|
|
114
|
+
*/
|
|
115
|
+
static CarbonMonoxideSensor;
|
|
116
|
+
/**
|
|
117
|
+
* @group Service Definitions
|
|
118
|
+
*/
|
|
119
|
+
static CloudRelay;
|
|
120
|
+
/**
|
|
121
|
+
* @group Service Definitions
|
|
122
|
+
*/
|
|
123
|
+
static ContactSensor;
|
|
124
|
+
/**
|
|
125
|
+
* @group Service Definitions
|
|
126
|
+
*/
|
|
127
|
+
static DataStreamTransportManagement;
|
|
128
|
+
/**
|
|
129
|
+
* @group Service Definitions
|
|
130
|
+
*/
|
|
131
|
+
static Diagnostics;
|
|
132
|
+
/**
|
|
133
|
+
* @group Service Definitions
|
|
134
|
+
*/
|
|
135
|
+
static Door;
|
|
136
|
+
/**
|
|
137
|
+
* @group Service Definitions
|
|
138
|
+
*/
|
|
139
|
+
static Doorbell;
|
|
140
|
+
/**
|
|
141
|
+
* @group Service Definitions
|
|
142
|
+
*/
|
|
143
|
+
static Fan;
|
|
144
|
+
/**
|
|
145
|
+
* @group Service Definitions
|
|
146
|
+
*/
|
|
147
|
+
static Fanv2;
|
|
148
|
+
/**
|
|
149
|
+
* @group Service Definitions
|
|
150
|
+
*/
|
|
151
|
+
static Faucet;
|
|
152
|
+
/**
|
|
153
|
+
* @group Service Definitions
|
|
154
|
+
*/
|
|
155
|
+
static FilterMaintenance;
|
|
156
|
+
/**
|
|
157
|
+
* @group Service Definitions
|
|
158
|
+
*/
|
|
159
|
+
static FirmwareUpdate;
|
|
160
|
+
/**
|
|
161
|
+
* @group Service Definitions
|
|
162
|
+
*/
|
|
163
|
+
static GarageDoorOpener;
|
|
164
|
+
/**
|
|
165
|
+
* @group Service Definitions
|
|
166
|
+
*/
|
|
167
|
+
static HeaterCooler;
|
|
168
|
+
/**
|
|
169
|
+
* @group Service Definitions
|
|
170
|
+
*/
|
|
171
|
+
static HumidifierDehumidifier;
|
|
172
|
+
/**
|
|
173
|
+
* @group Service Definitions
|
|
174
|
+
*/
|
|
175
|
+
static HumiditySensor;
|
|
176
|
+
/**
|
|
177
|
+
* @group Service Definitions
|
|
178
|
+
*/
|
|
179
|
+
static InputSource;
|
|
180
|
+
/**
|
|
181
|
+
* @group Service Definitions
|
|
182
|
+
*/
|
|
183
|
+
static IrrigationSystem;
|
|
184
|
+
/**
|
|
185
|
+
* @group Service Definitions
|
|
186
|
+
*/
|
|
187
|
+
static LeakSensor;
|
|
188
|
+
/**
|
|
189
|
+
* @group Service Definitions
|
|
190
|
+
*/
|
|
191
|
+
static Lightbulb;
|
|
192
|
+
/**
|
|
193
|
+
* @group Service Definitions
|
|
194
|
+
*/
|
|
195
|
+
static LightSensor;
|
|
196
|
+
/**
|
|
197
|
+
* @group Service Definitions
|
|
198
|
+
*/
|
|
199
|
+
static LockManagement;
|
|
200
|
+
/**
|
|
201
|
+
* @group Service Definitions
|
|
202
|
+
*/
|
|
203
|
+
static LockMechanism;
|
|
204
|
+
/**
|
|
205
|
+
* @group Service Definitions
|
|
206
|
+
*/
|
|
207
|
+
static Microphone;
|
|
208
|
+
/**
|
|
209
|
+
* @group Service Definitions
|
|
210
|
+
*/
|
|
211
|
+
static MotionSensor;
|
|
212
|
+
/**
|
|
213
|
+
* @group Service Definitions
|
|
214
|
+
*/
|
|
215
|
+
static NFCAccess;
|
|
216
|
+
/**
|
|
217
|
+
* @group Service Definitions
|
|
218
|
+
*/
|
|
219
|
+
static OccupancySensor;
|
|
220
|
+
/**
|
|
221
|
+
* @group Service Definitions
|
|
222
|
+
*/
|
|
223
|
+
static Outlet;
|
|
224
|
+
/**
|
|
225
|
+
* @group Service Definitions
|
|
226
|
+
*/
|
|
227
|
+
static Pairing;
|
|
228
|
+
/**
|
|
229
|
+
* @group Service Definitions
|
|
230
|
+
*/
|
|
231
|
+
static PowerManagement;
|
|
232
|
+
/**
|
|
233
|
+
* @group Service Definitions
|
|
234
|
+
*/
|
|
235
|
+
static ProtocolInformation;
|
|
236
|
+
/**
|
|
237
|
+
* @group Service Definitions
|
|
238
|
+
*/
|
|
239
|
+
static SecuritySystem;
|
|
240
|
+
/**
|
|
241
|
+
* @group Service Definitions
|
|
242
|
+
*/
|
|
243
|
+
static ServiceLabel;
|
|
244
|
+
/**
|
|
245
|
+
* @group Service Definitions
|
|
246
|
+
*/
|
|
247
|
+
static Siri;
|
|
248
|
+
/**
|
|
249
|
+
* @group Service Definitions
|
|
250
|
+
*/
|
|
251
|
+
static SiriEndpoint;
|
|
252
|
+
/**
|
|
253
|
+
* @group Service Definitions
|
|
254
|
+
*/
|
|
255
|
+
static Slats;
|
|
256
|
+
/**
|
|
257
|
+
* @group Service Definitions
|
|
258
|
+
*/
|
|
259
|
+
static SmartSpeaker;
|
|
260
|
+
/**
|
|
261
|
+
* @group Service Definitions
|
|
262
|
+
*/
|
|
263
|
+
static SmokeSensor;
|
|
264
|
+
/**
|
|
265
|
+
* @group Service Definitions
|
|
266
|
+
*/
|
|
267
|
+
static Speaker;
|
|
268
|
+
/**
|
|
269
|
+
* @group Service Definitions
|
|
270
|
+
*/
|
|
271
|
+
static StatefulProgrammableSwitch;
|
|
272
|
+
/**
|
|
273
|
+
* @group Service Definitions
|
|
274
|
+
*/
|
|
275
|
+
static StatelessProgrammableSwitch;
|
|
276
|
+
/**
|
|
277
|
+
* @group Service Definitions
|
|
278
|
+
*/
|
|
279
|
+
static Switch;
|
|
280
|
+
/**
|
|
281
|
+
* @group Service Definitions
|
|
282
|
+
*/
|
|
283
|
+
static TapManagement;
|
|
284
|
+
/**
|
|
285
|
+
* @group Service Definitions
|
|
286
|
+
*/
|
|
287
|
+
static TargetControl;
|
|
288
|
+
/**
|
|
289
|
+
* @group Service Definitions
|
|
290
|
+
*/
|
|
291
|
+
static TargetControlManagement;
|
|
292
|
+
/**
|
|
293
|
+
* @group Service Definitions
|
|
294
|
+
*/
|
|
295
|
+
static Television;
|
|
296
|
+
/**
|
|
297
|
+
* @group Service Definitions
|
|
298
|
+
*/
|
|
299
|
+
static TelevisionSpeaker;
|
|
300
|
+
/**
|
|
301
|
+
* @group Service Definitions
|
|
302
|
+
*/
|
|
303
|
+
static TemperatureSensor;
|
|
304
|
+
/**
|
|
305
|
+
* @group Service Definitions
|
|
306
|
+
*/
|
|
307
|
+
static Thermostat;
|
|
308
|
+
/**
|
|
309
|
+
* @group Service Definitions
|
|
310
|
+
*/
|
|
311
|
+
static ThreadTransport;
|
|
312
|
+
/**
|
|
313
|
+
* @group Service Definitions
|
|
314
|
+
*/
|
|
315
|
+
static TransferTransportManagement;
|
|
316
|
+
/**
|
|
317
|
+
* @group Service Definitions
|
|
318
|
+
*/
|
|
319
|
+
static Tunnel;
|
|
320
|
+
/**
|
|
321
|
+
* @group Service Definitions
|
|
322
|
+
*/
|
|
323
|
+
static Valve;
|
|
324
|
+
/**
|
|
325
|
+
* @group Service Definitions
|
|
326
|
+
*/
|
|
327
|
+
static WiFiRouter;
|
|
328
|
+
/**
|
|
329
|
+
* @group Service Definitions
|
|
330
|
+
*/
|
|
331
|
+
static WiFiSatellite;
|
|
332
|
+
/**
|
|
333
|
+
* @group Service Definitions
|
|
334
|
+
*/
|
|
335
|
+
static WiFiTransport;
|
|
336
|
+
/**
|
|
337
|
+
* @group Service Definitions
|
|
338
|
+
*/
|
|
339
|
+
static Window;
|
|
340
|
+
/**
|
|
341
|
+
* @group Service Definitions
|
|
342
|
+
*/
|
|
343
|
+
static WindowCovering;
|
|
344
|
+
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
345
|
+
// NOTICE: when adding/changing properties, remember to possibly adjust the serialize/deserialize functions
|
|
346
|
+
displayName;
|
|
347
|
+
UUID;
|
|
348
|
+
subtype;
|
|
349
|
+
iid = null; // assigned later by our containing Accessory
|
|
350
|
+
name = null;
|
|
351
|
+
characteristics = [];
|
|
352
|
+
optionalCharacteristics = [];
|
|
353
|
+
/**
|
|
354
|
+
* @private
|
|
355
|
+
*/
|
|
356
|
+
isHiddenService = false;
|
|
357
|
+
/**
|
|
358
|
+
* @private
|
|
359
|
+
*/
|
|
360
|
+
isPrimaryService = false; // do not write to this directly
|
|
361
|
+
/**
|
|
362
|
+
* @private
|
|
363
|
+
*/
|
|
364
|
+
linkedServices = [];
|
|
365
|
+
constructor(displayName = "", UUID, subtype) {
|
|
366
|
+
super();
|
|
69
367
|
(0, assert_1.default)(UUID, "Services must be created with a valid UUID.");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
368
|
+
this.displayName = displayName;
|
|
369
|
+
this.UUID = UUID;
|
|
370
|
+
this.subtype = subtype;
|
|
73
371
|
// every service has an optional Characteristic.Name property - we'll set it to our displayName
|
|
74
372
|
// if one was given
|
|
75
373
|
// if you don't provide a display name, some HomeKit apps may choose to hide the device.
|
|
76
374
|
if (displayName) {
|
|
77
375
|
// create the characteristic if necessary
|
|
78
|
-
(0, checkName_1.checkName)(
|
|
79
|
-
|
|
80
|
-
|
|
376
|
+
(0, checkName_1.checkName)(this.displayName, "Name", displayName);
|
|
377
|
+
const nameCharacteristic = this.getCharacteristic(Characteristic_1.Characteristic.Name) ||
|
|
378
|
+
this.addCharacteristic(Characteristic_1.Characteristic.Name);
|
|
81
379
|
nameCharacteristic.updateValue(displayName);
|
|
82
380
|
}
|
|
83
|
-
return _this;
|
|
84
381
|
}
|
|
85
382
|
/**
|
|
86
383
|
* Returns an id which uniquely identifies a service on the associated accessory.
|
|
@@ -89,38 +386,23 @@ var Service = /** @class */ (function (_super) {
|
|
|
89
386
|
*
|
|
90
387
|
* @returns the serviceId
|
|
91
388
|
*/
|
|
92
|
-
|
|
389
|
+
getServiceId() {
|
|
93
390
|
return this.UUID + (this.subtype || "");
|
|
94
|
-
}
|
|
391
|
+
}
|
|
95
392
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
-
|
|
393
|
+
addCharacteristic(input, ...constructorArgs) {
|
|
97
394
|
// characteristic might be a constructor like `Characteristic.Brightness` instead of an instance of Characteristic. Coerce if necessary.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
for (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// check for UUID conflict
|
|
106
|
-
for (var _b = tslib_1.__values(this.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
107
|
-
var existing = _c.value;
|
|
108
|
-
if (existing.UUID === characteristic.UUID) {
|
|
109
|
-
if (characteristic.UUID === "00000052-0000-1000-8000-0026BB765291") {
|
|
110
|
-
//This is a special workaround for the Firmware Revision characteristic.
|
|
111
|
-
return existing;
|
|
112
|
-
}
|
|
113
|
-
throw new Error("Cannot add a Characteristic with the same UUID as another Characteristic in this Service: " + existing.UUID);
|
|
395
|
+
const characteristic = typeof input === "function" ? new input(...constructorArgs) : input;
|
|
396
|
+
// check for UUID conflict
|
|
397
|
+
for (const existing of this.characteristics) {
|
|
398
|
+
if (existing.UUID === characteristic.UUID) {
|
|
399
|
+
if (characteristic.UUID === "00000052-0000-1000-8000-0026BB765291") {
|
|
400
|
+
//This is a special workaround for the Firmware Revision characteristic.
|
|
401
|
+
return existing;
|
|
114
402
|
}
|
|
403
|
+
throw new Error("Cannot add a Characteristic with the same UUID as another Characteristic in this Service: " + existing.UUID);
|
|
115
404
|
}
|
|
116
405
|
}
|
|
117
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
118
|
-
finally {
|
|
119
|
-
try {
|
|
120
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
121
|
-
}
|
|
122
|
-
finally { if (e_1) throw e_1.error; }
|
|
123
|
-
}
|
|
124
406
|
if (this.characteristics.length >= MAX_CHARACTERISTICS) {
|
|
125
407
|
throw new Error("Cannot add more than " + MAX_CHARACTERISTICS + " characteristics to a single service!");
|
|
126
408
|
}
|
|
@@ -128,7 +410,7 @@ var Service = /** @class */ (function (_super) {
|
|
|
128
410
|
this.characteristics.push(characteristic);
|
|
129
411
|
this.emit("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */);
|
|
130
412
|
return characteristic;
|
|
131
|
-
}
|
|
413
|
+
}
|
|
132
414
|
/**
|
|
133
415
|
* Sets this service as the new primary service.
|
|
134
416
|
* Any currently active primary service will be reset to be not primary.
|
|
@@ -137,149 +419,115 @@ var Service = /** @class */ (function (_super) {
|
|
|
137
419
|
*
|
|
138
420
|
* @param isPrimary - optional boolean (default true) if the service should be the primary service
|
|
139
421
|
*/
|
|
140
|
-
|
|
141
|
-
if (isPrimary === void 0) { isPrimary = true; }
|
|
422
|
+
setPrimaryService(isPrimary = true) {
|
|
142
423
|
this.isPrimaryService = isPrimary;
|
|
143
424
|
this.emit("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */);
|
|
144
|
-
}
|
|
425
|
+
}
|
|
145
426
|
/**
|
|
146
427
|
* Marks the service as hidden
|
|
147
428
|
*
|
|
148
429
|
* @param isHidden - optional boolean (default true) if the service should be marked hidden
|
|
149
430
|
*/
|
|
150
|
-
|
|
151
|
-
if (isHidden === void 0) { isHidden = true; }
|
|
431
|
+
setHiddenService(isHidden = true) {
|
|
152
432
|
this.isHiddenService = isHidden;
|
|
153
433
|
this.emit("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */);
|
|
154
|
-
}
|
|
434
|
+
}
|
|
155
435
|
/**
|
|
156
436
|
* Adds a new link to the specified service. The service MUST be already added to
|
|
157
437
|
* the SAME accessory.
|
|
158
438
|
*
|
|
159
439
|
* @param service - The service this service should link to
|
|
160
440
|
*/
|
|
161
|
-
|
|
441
|
+
addLinkedService(service) {
|
|
162
442
|
//TODO: Add a check if the service is on the same accessory.
|
|
163
443
|
if (!this.linkedServices.includes(service)) {
|
|
164
444
|
this.linkedServices.push(service);
|
|
165
445
|
}
|
|
166
446
|
this.emit("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */);
|
|
167
|
-
}
|
|
447
|
+
}
|
|
168
448
|
/**
|
|
169
449
|
* Removes a link to the specified service which was previously added with {@link addLinkedService}
|
|
170
450
|
*
|
|
171
451
|
* @param service - Previously linked service
|
|
172
452
|
*/
|
|
173
|
-
|
|
453
|
+
removeLinkedService(service) {
|
|
174
454
|
//TODO: Add a check if the service is on the same accessory.
|
|
175
|
-
|
|
455
|
+
const index = this.linkedServices.indexOf(service);
|
|
176
456
|
if (index !== -1) {
|
|
177
457
|
this.linkedServices.splice(index, 1);
|
|
178
458
|
}
|
|
179
459
|
this.emit("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
460
|
+
}
|
|
461
|
+
removeCharacteristic(characteristic) {
|
|
462
|
+
const index = this.characteristics.indexOf(characteristic);
|
|
183
463
|
if (index !== -1) {
|
|
184
464
|
this.characteristics.splice(index, 1);
|
|
185
465
|
characteristic.removeAllListeners();
|
|
186
466
|
this.emit("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */);
|
|
187
467
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
468
|
+
}
|
|
469
|
+
getCharacteristic(name) {
|
|
190
470
|
// returns a characteristic object from the service
|
|
191
471
|
// If Service.prototype.getCharacteristic(Characteristic.Type) does not find the characteristic,
|
|
192
472
|
// but the type is in optionalCharacteristics, it adds the characteristic.type to the service and returns it.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
473
|
+
for (const characteristic of this.characteristics) {
|
|
474
|
+
if (typeof name === "string" && characteristic.displayName === name) {
|
|
475
|
+
return characteristic;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
479
|
+
if (typeof name === "function" && ((characteristic instanceof name) || (name.UUID === characteristic.UUID))) {
|
|
198
480
|
return characteristic;
|
|
199
481
|
}
|
|
200
|
-
else {
|
|
201
|
-
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
202
|
-
if (typeof name === "function" && ((characteristic instanceof name) || (name.UUID === characteristic.UUID))) {
|
|
203
|
-
return characteristic;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
209
|
-
finally {
|
|
210
|
-
try {
|
|
211
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
212
482
|
}
|
|
213
|
-
finally { if (e_2) throw e_2.error; }
|
|
214
483
|
}
|
|
215
484
|
if (typeof name === "function") {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if ((characteristic instanceof name) || (name.UUID === characteristic.UUID)) {
|
|
221
|
-
return this.addCharacteristic(name);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
226
|
-
finally {
|
|
227
|
-
try {
|
|
228
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
485
|
+
for (const characteristic of this.optionalCharacteristics) {
|
|
486
|
+
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
487
|
+
if ((characteristic instanceof name) || (name.UUID === characteristic.UUID)) {
|
|
488
|
+
return this.addCharacteristic(name);
|
|
229
489
|
}
|
|
230
|
-
finally { if (e_3) throw e_3.error; }
|
|
231
490
|
}
|
|
232
|
-
|
|
491
|
+
const instance = this.addCharacteristic(name);
|
|
233
492
|
// Not found in optional Characteristics. Adding anyway, but warning about it if it isn't the Name.
|
|
234
493
|
if (name.UUID !== Characteristic_1.Characteristic.Name.UUID) {
|
|
235
494
|
this.emitCharacteristicWarningEvent(instance, "warn-message" /* CharacteristicWarningType.WARN_MESSAGE */, "Characteristic not in required or optional characteristic section for service " + this.constructor.name + ". Adding anyway.");
|
|
236
495
|
}
|
|
237
496
|
return instance;
|
|
238
497
|
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
498
|
+
}
|
|
499
|
+
testCharacteristic(name) {
|
|
500
|
+
// checks for the existence of a characteristic object in the service
|
|
501
|
+
for (const characteristic of this.characteristics) {
|
|
502
|
+
if (typeof name === "string" && characteristic.displayName === name) {
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
507
|
+
if (typeof name === "function" && ((characteristic instanceof name) || (name.UUID === characteristic.UUID))) {
|
|
247
508
|
return true;
|
|
248
509
|
}
|
|
249
|
-
else {
|
|
250
|
-
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
251
|
-
if (typeof name === "function" && ((characteristic instanceof name) || (name.UUID === characteristic.UUID))) {
|
|
252
|
-
return true;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
258
|
-
finally {
|
|
259
|
-
try {
|
|
260
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
261
510
|
}
|
|
262
|
-
finally { if (e_4) throw e_4.error; }
|
|
263
511
|
}
|
|
264
512
|
return false;
|
|
265
|
-
}
|
|
266
|
-
|
|
513
|
+
}
|
|
514
|
+
setCharacteristic(name, value) {
|
|
267
515
|
// @ts-expect-error: We know that both overloads exists individually. There is just no publicly exposed type for that!
|
|
268
516
|
this.getCharacteristic(name).setValue(value);
|
|
269
517
|
return this; // for chaining
|
|
270
|
-
}
|
|
271
|
-
|
|
518
|
+
}
|
|
519
|
+
updateCharacteristic(name, value) {
|
|
272
520
|
this.getCharacteristic(name).updateValue(value);
|
|
273
521
|
return this;
|
|
274
|
-
}
|
|
275
|
-
|
|
522
|
+
}
|
|
523
|
+
addOptionalCharacteristic(characteristic) {
|
|
276
524
|
// characteristic might be a constructor like `Characteristic.Brightness` instead of an instance
|
|
277
525
|
// of Characteristic. Coerce if necessary.
|
|
278
526
|
if (typeof characteristic === "function") {
|
|
279
527
|
characteristic = new characteristic();
|
|
280
528
|
}
|
|
281
529
|
this.optionalCharacteristics.push(characteristic);
|
|
282
|
-
}
|
|
530
|
+
}
|
|
283
531
|
// noinspection JSUnusedGlobalSymbols
|
|
284
532
|
/**
|
|
285
533
|
* This method was created to copy all characteristics from another service to this.
|
|
@@ -291,15 +539,14 @@ var Service = /** @class */ (function (_super) {
|
|
|
291
539
|
* @param service
|
|
292
540
|
* @private used by homebridge
|
|
293
541
|
*/
|
|
294
|
-
|
|
295
|
-
var _this = this;
|
|
542
|
+
replaceCharacteristicsFromService(service) {
|
|
296
543
|
if (this.UUID !== service.UUID) {
|
|
297
|
-
throw new Error(
|
|
544
|
+
throw new Error(`Incompatible services. Tried replacing characteristics of ${this.UUID} with characteristics from ${service.UUID}`);
|
|
298
545
|
}
|
|
299
|
-
|
|
300
|
-
service.characteristics.forEach(
|
|
301
|
-
this.characteristics.forEach(
|
|
302
|
-
|
|
546
|
+
const foreignCharacteristics = {}; // index foreign characteristics by UUID
|
|
547
|
+
service.characteristics.forEach(characteristic => foreignCharacteristics[characteristic.UUID] = characteristic);
|
|
548
|
+
this.characteristics.forEach(characteristic => {
|
|
549
|
+
const foreignCharacteristic = foreignCharacteristics[characteristic.UUID];
|
|
303
550
|
if (foreignCharacteristic) {
|
|
304
551
|
delete foreignCharacteristics[characteristic.UUID];
|
|
305
552
|
if (!foreignCharacteristic.value && foreignCharacteristic.value !== 0 && foreignCharacteristic.value !== false) {
|
|
@@ -309,35 +556,22 @@ var Service = /** @class */ (function (_super) {
|
|
|
309
556
|
}
|
|
310
557
|
});
|
|
311
558
|
// add all additional characteristics which where not present already
|
|
312
|
-
Object.values(foreignCharacteristics).forEach(
|
|
313
|
-
}
|
|
559
|
+
Object.values(foreignCharacteristics).forEach(characteristic => this.addCharacteristic(characteristic));
|
|
560
|
+
}
|
|
314
561
|
/**
|
|
315
562
|
* @private
|
|
316
563
|
*/
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
var characteristic = _c.value;
|
|
322
|
-
if (characteristic.iid === iid) {
|
|
323
|
-
return characteristic;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
328
|
-
finally {
|
|
329
|
-
try {
|
|
330
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
564
|
+
getCharacteristicByIID(iid) {
|
|
565
|
+
for (const characteristic of this.characteristics) {
|
|
566
|
+
if (characteristic.iid === iid) {
|
|
567
|
+
return characteristic;
|
|
331
568
|
}
|
|
332
|
-
finally { if (e_5) throw e_5.error; }
|
|
333
569
|
}
|
|
334
|
-
}
|
|
570
|
+
}
|
|
335
571
|
/**
|
|
336
572
|
* @private
|
|
337
573
|
*/
|
|
338
|
-
|
|
339
|
-
var e_6, _a;
|
|
340
|
-
if (baseIID === void 0) { baseIID = 0; }
|
|
574
|
+
_assignIDs(identifierCache, accessoryName, baseIID = 0) {
|
|
341
575
|
// the Accessory Information service must have a (reserved by IdentifierCache) ID of 1
|
|
342
576
|
if (this.UUID === "0000003E-0000-1000-8000-0026BB765291") {
|
|
343
577
|
this.iid = 1;
|
|
@@ -346,105 +580,60 @@ var Service = /** @class */ (function (_super) {
|
|
|
346
580
|
// assign our own ID based on our UUID
|
|
347
581
|
this.iid = baseIID + identifierCache.getIID(accessoryName, this.UUID, this.subtype);
|
|
348
582
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
var characteristic = _c.value;
|
|
353
|
-
characteristic._assignID(identifierCache, accessoryName, this.UUID, this.subtype);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
357
|
-
finally {
|
|
358
|
-
try {
|
|
359
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
360
|
-
}
|
|
361
|
-
finally { if (e_6) throw e_6.error; }
|
|
583
|
+
// assign IIDs to our Characteristics
|
|
584
|
+
for (const characteristic of this.characteristics) {
|
|
585
|
+
characteristic._assignID(identifierCache, accessoryName, this.UUID, this.subtype);
|
|
362
586
|
}
|
|
363
|
-
}
|
|
587
|
+
}
|
|
364
588
|
/**
|
|
365
589
|
* Returns a JSON representation of this service suitable for delivering to HAP clients.
|
|
366
590
|
* @private used to generate response to /accessories query
|
|
367
591
|
*/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
var service = {
|
|
376
|
-
type: (0, uuid_1.toShortForm)(_this.UUID),
|
|
377
|
-
iid: _this.iid,
|
|
592
|
+
toHAP(connection, contactGetHandlers = true) {
|
|
593
|
+
return new Promise(resolve => {
|
|
594
|
+
(0, assert_1.default)(this.iid, "iid cannot be undefined for service '" + this.displayName + "'");
|
|
595
|
+
(0, assert_1.default)(this.characteristics.length, "service '" + this.displayName + "' does not have any characteristics!");
|
|
596
|
+
const service = {
|
|
597
|
+
type: (0, uuid_1.toShortForm)(this.UUID),
|
|
598
|
+
iid: this.iid,
|
|
378
599
|
characteristics: [],
|
|
379
|
-
hidden:
|
|
380
|
-
primary:
|
|
600
|
+
hidden: this.isHiddenService ? true : undefined,
|
|
601
|
+
primary: this.isPrimaryService ? true : undefined,
|
|
381
602
|
};
|
|
382
|
-
if (
|
|
603
|
+
if (this.linkedServices.length) {
|
|
383
604
|
service.linked = [];
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
debug("iid of linked service '".concat(linked.displayName, "' ").concat(linked.UUID, " is undefined on service '").concat(_this.displayName, "'"));
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
service.linked.push(linked.iid);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
400
|
-
finally {
|
|
401
|
-
try {
|
|
402
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
605
|
+
for (const linked of this.linkedServices) {
|
|
606
|
+
if (!linked.iid) {
|
|
607
|
+
// we got a linked service which is not added to the accessory
|
|
608
|
+
// as it doesn't "exists" we just ignore it.
|
|
609
|
+
// we have some (at least one) plugins on homebridge which link to the AccessoryInformation service.
|
|
610
|
+
// homebridge always creates its own AccessoryInformation service and ignores the user supplied one
|
|
611
|
+
// thus the link is automatically broken.
|
|
612
|
+
debug(`iid of linked service '${linked.displayName}' ${linked.UUID} is undefined on service '${this.displayName}'`);
|
|
613
|
+
continue;
|
|
403
614
|
}
|
|
404
|
-
|
|
615
|
+
service.linked.push(linked.iid);
|
|
405
616
|
}
|
|
406
617
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
for (var missingCharacteristics_1 = tslib_1.__values(missingCharacteristics), missingCharacteristics_1_1 = missingCharacteristics_1.next(); !missingCharacteristics_1_1.done; missingCharacteristics_1_1 = missingCharacteristics_1.next()) {
|
|
412
|
-
var characteristic = missingCharacteristics_1_1.value;
|
|
413
|
-
_this.emitCharacteristicWarningEvent(characteristic, "slow-read" /* CharacteristicWarningType.SLOW_READ */, "The read handler for the characteristic '".concat(characteristic.displayName, "' was slow to respond!"));
|
|
414
|
-
}
|
|
618
|
+
const missingCharacteristics = new Set();
|
|
619
|
+
let timeout = setTimeout(() => {
|
|
620
|
+
for (const characteristic of missingCharacteristics) {
|
|
621
|
+
this.emitCharacteristicWarningEvent(characteristic, "slow-read" /* CharacteristicWarningType.SLOW_READ */, `The read handler for the characteristic '${characteristic.displayName}' was slow to respond!`);
|
|
415
622
|
}
|
|
416
|
-
|
|
417
|
-
finally {
|
|
418
|
-
try {
|
|
419
|
-
if (missingCharacteristics_1_1 && !missingCharacteristics_1_1.done && (_a = missingCharacteristics_1.return)) _a.call(missingCharacteristics_1);
|
|
420
|
-
}
|
|
421
|
-
finally { if (e_9) throw e_9.error; }
|
|
422
|
-
}
|
|
423
|
-
timeout = setTimeout(function () {
|
|
424
|
-
var e_10, _a;
|
|
623
|
+
timeout = setTimeout(() => {
|
|
425
624
|
timeout = undefined;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
"' didn't respond at all!. Please check that you properly call the callback!");
|
|
431
|
-
service.characteristics.push(characteristic.internalHAPRepresentation()); // value is set to null
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
435
|
-
finally {
|
|
436
|
-
try {
|
|
437
|
-
if (missingCharacteristics_2_1 && !missingCharacteristics_2_1.done && (_a = missingCharacteristics_2.return)) _a.call(missingCharacteristics_2);
|
|
438
|
-
}
|
|
439
|
-
finally { if (e_10) throw e_10.error; }
|
|
625
|
+
for (const characteristic of missingCharacteristics) {
|
|
626
|
+
this.emitCharacteristicWarningEvent(characteristic, "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */, "The read handler for the characteristic '" + characteristic?.displayName +
|
|
627
|
+
"' didn't respond at all!. Please check that you properly call the callback!");
|
|
628
|
+
service.characteristics.push(characteristic.internalHAPRepresentation()); // value is set to null
|
|
440
629
|
}
|
|
441
630
|
missingCharacteristics.clear();
|
|
442
631
|
resolve(service);
|
|
443
632
|
}, 6000);
|
|
444
633
|
}, 3000);
|
|
445
|
-
|
|
634
|
+
for (const characteristic of this.characteristics) {
|
|
446
635
|
missingCharacteristics.add(characteristic);
|
|
447
|
-
characteristic.toHAP(connection, contactGetHandlers).then(
|
|
636
|
+
characteristic.toHAP(connection, contactGetHandlers).then(value => {
|
|
448
637
|
if (!timeout) {
|
|
449
638
|
return; // if timeout is undefined, response was already sent out
|
|
450
639
|
}
|
|
@@ -458,79 +647,54 @@ var Service = /** @class */ (function (_super) {
|
|
|
458
647
|
resolve(service);
|
|
459
648
|
}
|
|
460
649
|
});
|
|
461
|
-
};
|
|
462
|
-
try {
|
|
463
|
-
for (var _e = tslib_1.__values(_this.characteristics), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
464
|
-
var characteristic = _f.value;
|
|
465
|
-
_loop_1(characteristic);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
469
|
-
finally {
|
|
470
|
-
try {
|
|
471
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
472
|
-
}
|
|
473
|
-
finally { if (e_8) throw e_8.error; }
|
|
474
650
|
}
|
|
475
651
|
});
|
|
476
|
-
}
|
|
652
|
+
}
|
|
477
653
|
/**
|
|
478
654
|
* Returns a JSON representation of this service without characteristic values.
|
|
479
655
|
* @private used to generate the config hash
|
|
480
656
|
*/
|
|
481
|
-
|
|
482
|
-
var e_11, _a;
|
|
657
|
+
internalHAPRepresentation() {
|
|
483
658
|
(0, assert_1.default)(this.iid, "iid cannot be undefined for service '" + this.displayName + "'");
|
|
484
659
|
(0, assert_1.default)(this.characteristics.length, "service '" + this.displayName + "' does not have any characteristics!");
|
|
485
|
-
|
|
660
|
+
const service = {
|
|
486
661
|
type: (0, uuid_1.toShortForm)(this.UUID),
|
|
487
662
|
iid: this.iid,
|
|
488
|
-
characteristics: this.characteristics.map(
|
|
663
|
+
characteristics: this.characteristics.map(characteristic => characteristic.internalHAPRepresentation()),
|
|
489
664
|
hidden: this.isHiddenService ? true : undefined,
|
|
490
665
|
primary: this.isPrimaryService ? true : undefined,
|
|
491
666
|
};
|
|
492
667
|
if (this.linkedServices.length) {
|
|
493
668
|
service.linked = [];
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
debug("iid of linked service '".concat(linked.displayName, "' ").concat(linked.UUID, " is undefined on service '").concat(this.displayName, "'"));
|
|
504
|
-
continue;
|
|
505
|
-
}
|
|
506
|
-
service.linked.push(linked.iid);
|
|
669
|
+
for (const linked of this.linkedServices) {
|
|
670
|
+
if (!linked.iid) {
|
|
671
|
+
// we got a linked service which is not added to the accessory
|
|
672
|
+
// as it doesn't "exists" we just ignore it.
|
|
673
|
+
// we have some (at least one) plugins on homebridge which link to the AccessoryInformation service.
|
|
674
|
+
// homebridge always creates its own AccessoryInformation service and ignores the user supplied one
|
|
675
|
+
// thus the link is automatically broken.
|
|
676
|
+
debug(`iid of linked service '${linked.displayName}' ${linked.UUID} is undefined on service '${this.displayName}'`);
|
|
677
|
+
continue;
|
|
507
678
|
}
|
|
508
|
-
|
|
509
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
510
|
-
finally {
|
|
511
|
-
try {
|
|
512
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
513
|
-
}
|
|
514
|
-
finally { if (e_11) throw e_11.error; }
|
|
679
|
+
service.linked.push(linked.iid);
|
|
515
680
|
}
|
|
516
681
|
}
|
|
517
682
|
return service;
|
|
518
|
-
}
|
|
683
|
+
}
|
|
519
684
|
/**
|
|
520
685
|
* @private
|
|
521
686
|
*/
|
|
522
|
-
|
|
523
|
-
var _this = this;
|
|
687
|
+
setupCharacteristicEventHandlers(characteristic) {
|
|
524
688
|
// listen for changes in characteristics and bubble them up
|
|
525
|
-
characteristic.on("change" /* CharacteristicEventTypes.CHANGE */,
|
|
526
|
-
|
|
689
|
+
characteristic.on("change" /* CharacteristicEventTypes.CHANGE */, (change) => {
|
|
690
|
+
this.emit("characteristic-change" /* ServiceEventTypes.CHARACTERISTIC_CHANGE */, { ...change, characteristic: characteristic });
|
|
527
691
|
});
|
|
528
692
|
characteristic.on("characteristic-warning" /* CharacteristicEventTypes.CHARACTERISTIC_WARNING */, this.emitCharacteristicWarningEvent.bind(this, characteristic));
|
|
529
|
-
}
|
|
693
|
+
}
|
|
530
694
|
/**
|
|
531
695
|
* @private
|
|
532
696
|
*/
|
|
533
|
-
|
|
697
|
+
emitCharacteristicWarningEvent(characteristic, type, message, stack) {
|
|
534
698
|
this.emit("characteristic-warning" /* ServiceEventTypes.CHARACTERISTIC_WARNING */, {
|
|
535
699
|
characteristic: characteristic,
|
|
536
700
|
type: type,
|
|
@@ -538,32 +702,21 @@ var Service = /** @class */ (function (_super) {
|
|
|
538
702
|
originatorChain: [this.displayName, characteristic.displayName],
|
|
539
703
|
stack: stack,
|
|
540
704
|
});
|
|
541
|
-
}
|
|
705
|
+
}
|
|
542
706
|
/**
|
|
543
707
|
* @private
|
|
544
708
|
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
for (var targetCharacteristics_1 = tslib_1.__values(targetCharacteristics), targetCharacteristics_1_1 = targetCharacteristics_1.next(); !targetCharacteristics_1_1.done; targetCharacteristics_1_1 = targetCharacteristics_1.next()) {
|
|
549
|
-
var target = targetCharacteristics_1_1.value;
|
|
550
|
-
this.setupCharacteristicEventHandlers(target);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
554
|
-
finally {
|
|
555
|
-
try {
|
|
556
|
-
if (targetCharacteristics_1_1 && !targetCharacteristics_1_1.done && (_a = targetCharacteristics_1.return)) _a.call(targetCharacteristics_1);
|
|
557
|
-
}
|
|
558
|
-
finally { if (e_12) throw e_12.error; }
|
|
709
|
+
_sideloadCharacteristics(targetCharacteristics) {
|
|
710
|
+
for (const target of targetCharacteristics) {
|
|
711
|
+
this.setupCharacteristicEventHandlers(target);
|
|
559
712
|
}
|
|
560
713
|
this.characteristics = targetCharacteristics.slice();
|
|
561
|
-
}
|
|
714
|
+
}
|
|
562
715
|
/**
|
|
563
716
|
* @private
|
|
564
717
|
*/
|
|
565
|
-
|
|
566
|
-
|
|
718
|
+
static serialize(service) {
|
|
719
|
+
let constructorName;
|
|
567
720
|
if (service.constructor.name !== "Service") {
|
|
568
721
|
constructorName = service.constructor.name;
|
|
569
722
|
}
|
|
@@ -574,18 +727,18 @@ var Service = /** @class */ (function (_super) {
|
|
|
574
727
|
constructorName: constructorName,
|
|
575
728
|
hiddenService: service.isHiddenService,
|
|
576
729
|
primaryService: service.isPrimaryService,
|
|
577
|
-
characteristics: service.characteristics.map(
|
|
578
|
-
optionalCharacteristics: service.optionalCharacteristics.map(
|
|
730
|
+
characteristics: service.characteristics.map(characteristic => Characteristic_1.Characteristic.serialize(characteristic)),
|
|
731
|
+
optionalCharacteristics: service.optionalCharacteristics.map(characteristic => Characteristic_1.Characteristic.serialize(characteristic)),
|
|
579
732
|
};
|
|
580
|
-
}
|
|
733
|
+
}
|
|
581
734
|
/**
|
|
582
735
|
* @private
|
|
583
736
|
*/
|
|
584
|
-
|
|
585
|
-
|
|
737
|
+
static deserialize(json) {
|
|
738
|
+
let service;
|
|
586
739
|
if (json.constructorName && json.constructorName.charAt(0).toUpperCase() === json.constructorName.charAt(0)
|
|
587
740
|
&& Service[json.constructorName]) { // MUST start with uppercase character and must exist on Service object
|
|
588
|
-
|
|
741
|
+
const constructor = Service[json.constructorName];
|
|
589
742
|
service = new constructor(json.displayName, json.subtype);
|
|
590
743
|
}
|
|
591
744
|
else {
|
|
@@ -593,15 +746,14 @@ var Service = /** @class */ (function (_super) {
|
|
|
593
746
|
}
|
|
594
747
|
service.isHiddenService = !!json.hiddenService;
|
|
595
748
|
service.isPrimaryService = !!json.primaryService;
|
|
596
|
-
|
|
749
|
+
const characteristics = json.characteristics.map(serialized => Characteristic_1.Characteristic.deserialize(serialized));
|
|
597
750
|
service._sideloadCharacteristics(characteristics);
|
|
598
751
|
if (json.optionalCharacteristics) {
|
|
599
|
-
service.optionalCharacteristics = json.optionalCharacteristics.map(
|
|
752
|
+
service.optionalCharacteristics = json.optionalCharacteristics.map(serialized => Characteristic_1.Characteristic.deserialize(serialized));
|
|
600
753
|
}
|
|
601
754
|
return service;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
}(events_1.EventEmitter));
|
|
755
|
+
}
|
|
756
|
+
}
|
|
605
757
|
exports.Service = Service;
|
|
606
758
|
// We have a cyclic dependency problem. Within this file we have the definitions of "./definitions" as
|
|
607
759
|
// type imports only (in order to define the static properties). Setting those properties is done outside
|