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