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.
Files changed (175) hide show
  1. package/README.md +1 -0
  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 +292 -373
  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 +36 -47
  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 +5 -28
  41. package/dist/index.js.map +1 -1
  42. package/dist/lib/Accessory.d.ts +1 -58
  43. package/dist/lib/Accessory.d.ts.map +1 -1
  44. package/dist/lib/Accessory.js +747 -1149
  45. package/dist/lib/Accessory.js.map +1 -1
  46. package/dist/lib/Advertiser.d.ts +1 -2
  47. package/dist/lib/Advertiser.d.ts.map +1 -1
  48. package/dist/lib/Advertiser.js +392 -524
  49. package/dist/lib/Advertiser.js.map +1 -1
  50. package/dist/lib/Bridge.js +6 -10
  51. package/dist/lib/Bridge.js.map +1 -1
  52. package/dist/lib/Characteristic.d.ts +2 -133
  53. package/dist/lib/Characteristic.d.ts.map +1 -1
  54. package/dist/lib/Characteristic.js +1467 -669
  55. package/dist/lib/Characteristic.js.map +1 -1
  56. package/dist/lib/HAPServer.d.ts +0 -10
  57. package/dist/lib/HAPServer.d.ts.map +1 -1
  58. package/dist/lib/HAPServer.js +216 -280
  59. package/dist/lib/HAPServer.js.map +1 -1
  60. package/dist/lib/Service.d.ts +1 -51
  61. package/dist/lib/Service.d.ts.map +1 -1
  62. package/dist/lib/Service.js +474 -322
  63. package/dist/lib/Service.js.map +1 -1
  64. package/dist/lib/camera/RTPProxy.js +112 -104
  65. package/dist/lib/camera/RTPProxy.js.map +1 -1
  66. package/dist/lib/camera/RTPStreamManagement.d.ts +0 -65
  67. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
  68. package/dist/lib/camera/RTPStreamManagement.js +255 -278
  69. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  70. package/dist/lib/camera/RecordingManagement.js +318 -381
  71. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  72. package/dist/lib/camera/index.d.ts +0 -1
  73. package/dist/lib/camera/index.d.ts.map +1 -1
  74. package/dist/lib/camera/index.js +1 -2
  75. package/dist/lib/camera/index.js.map +1 -1
  76. package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -3
  77. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
  78. package/dist/lib/controller/AdaptiveLightingController.js +217 -218
  79. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  80. package/dist/lib/controller/CameraController.d.ts +0 -4
  81. package/dist/lib/controller/CameraController.d.ts.map +1 -1
  82. package/dist/lib/controller/CameraController.js +189 -256
  83. package/dist/lib/controller/CameraController.js.map +1 -1
  84. package/dist/lib/controller/DoorbellController.js +38 -39
  85. package/dist/lib/controller/DoorbellController.js.map +1 -1
  86. package/dist/lib/controller/RemoteController.d.ts +0 -14
  87. package/dist/lib/controller/RemoteController.d.ts.map +1 -1
  88. package/dist/lib/controller/RemoteController.js +340 -415
  89. package/dist/lib/controller/RemoteController.js.map +1 -1
  90. package/dist/lib/controller/index.js +1 -1
  91. package/dist/lib/datastream/DataStreamManagement.js +56 -57
  92. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  93. package/dist/lib/datastream/DataStreamParser.js +259 -304
  94. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  95. package/dist/lib/datastream/DataStreamServer.d.ts +0 -5
  96. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  97. package/dist/lib/datastream/DataStreamServer.js +252 -269
  98. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  99. package/dist/lib/datastream/index.js +1 -1
  100. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -106
  101. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
  102. package/dist/lib/definitions/CharacteristicDefinitions.js +2000 -2995
  103. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  104. package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -32
  105. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
  106. package/dist/lib/definitions/ServiceDefinitions.js +820 -1147
  107. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  108. package/dist/lib/definitions/generate-definitions.js +383 -679
  109. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  110. package/dist/lib/definitions/generator-configuration.js +29 -29
  111. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  112. package/dist/lib/definitions/index.js +1 -1
  113. package/dist/lib/model/AccessoryInfo.js +101 -136
  114. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  115. package/dist/lib/model/ControllerStorage.js +86 -89
  116. package/dist/lib/model/ControllerStorage.js.map +1 -1
  117. package/dist/lib/model/HAPStorage.js +15 -16
  118. package/dist/lib/model/HAPStorage.js.map +1 -1
  119. package/dist/lib/model/IdentifierCache.js +49 -49
  120. package/dist/lib/model/IdentifierCache.js.map +1 -1
  121. package/dist/lib/tv/AccessControlManagement.js +40 -44
  122. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  123. package/dist/lib/util/checkName.d.ts +2 -1
  124. package/dist/lib/util/checkName.d.ts.map +1 -1
  125. package/dist/lib/util/checkName.js +7 -11
  126. package/dist/lib/util/checkName.js.map +1 -1
  127. package/dist/lib/util/clone.js +5 -27
  128. package/dist/lib/util/clone.js.map +1 -1
  129. package/dist/lib/util/color-utils.js +8 -12
  130. package/dist/lib/util/color-utils.js.map +1 -1
  131. package/dist/lib/util/eventedhttp.d.ts.map +1 -1
  132. package/dist/lib/util/eventedhttp.js +301 -409
  133. package/dist/lib/util/eventedhttp.js.map +1 -1
  134. package/dist/lib/util/hapCrypto.js +31 -32
  135. package/dist/lib/util/hapCrypto.js.map +1 -1
  136. package/dist/lib/util/hapStatusError.js +9 -12
  137. package/dist/lib/util/hapStatusError.js.map +1 -1
  138. package/dist/lib/util/net-utils.js +32 -53
  139. package/dist/lib/util/net-utils.js.map +1 -1
  140. package/dist/lib/util/once.js +3 -8
  141. package/dist/lib/util/once.js.map +1 -1
  142. package/dist/lib/util/promise-utils.js +8 -13
  143. package/dist/lib/util/promise-utils.js.map +1 -1
  144. package/dist/lib/util/request-util.js +2 -3
  145. package/dist/lib/util/request-util.js.map +1 -1
  146. package/dist/lib/util/time.js +5 -5
  147. package/dist/lib/util/time.js.map +1 -1
  148. package/dist/lib/util/tlv.d.ts +0 -27
  149. package/dist/lib/util/tlv.d.ts.map +1 -1
  150. package/dist/lib/util/tlv.js +71 -113
  151. package/dist/lib/util/tlv.js.map +1 -1
  152. package/dist/lib/util/uuid.d.ts +0 -9
  153. package/dist/lib/util/uuid.d.ts.map +1 -1
  154. package/dist/lib/util/uuid.js +15 -33
  155. package/dist/lib/util/uuid.js.map +1 -1
  156. package/dist/types.d.ts +0 -35
  157. package/dist/types.d.ts.map +1 -1
  158. package/dist/types.js.map +1 -1
  159. package/package.json +10 -10
  160. package/dist/BridgedCore.d.ts +0 -2
  161. package/dist/BridgedCore.d.ts.map +0 -1
  162. package/dist/BridgedCore.js +0 -43
  163. package/dist/BridgedCore.js.map +0 -1
  164. package/dist/Core.d.ts +0 -2
  165. package/dist/Core.d.ts.map +0 -1
  166. package/dist/Core.js +0 -52
  167. package/dist/Core.js.map +0 -1
  168. package/dist/lib/AccessoryLoader.d.ts +0 -28
  169. package/dist/lib/AccessoryLoader.d.ts.map +0 -1
  170. package/dist/lib/AccessoryLoader.js +0 -166
  171. package/dist/lib/AccessoryLoader.js.map +0 -1
  172. package/dist/lib/camera/Camera.d.ts +0 -43
  173. package/dist/lib/camera/Camera.d.ts.map +0 -1
  174. package/dist/lib/camera/Camera.js +0 -36
  175. package/dist/lib/camera/Camera.js.map +0 -1
@@ -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
- 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 checkName_1 = require("./util/checkName");
11
- 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");
12
12
  /**
13
13
  * HAP spec allows a maximum of 100 characteristics per service!
14
14
  */
15
- var MAX_CHARACTERISTICS = 100;
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
- var Service = /** @class */ (function (_super) {
49
- tslib_1.__extends(Service, _super);
50
- function Service(displayName, UUID, subtype) {
51
- if (displayName === void 0) { displayName = ""; }
52
- var _this = _super.call(this) || this;
53
- _this.iid = null; // assigned later by our containing Accessory
54
- _this.name = null;
55
- _this.characteristics = [];
56
- _this.optionalCharacteristics = [];
57
- /**
58
- * @private
59
- */
60
- _this.isHiddenService = false;
61
- /**
62
- * @private
63
- */
64
- _this.isPrimaryService = false; // do not write to this directly
65
- /**
66
- * @private
67
- */
68
- _this.linkedServices = [];
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
- _this.displayName = displayName;
71
- _this.UUID = UUID;
72
- _this.subtype = subtype;
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)(_this.displayName, "Name", displayName);
79
- var nameCharacteristic = _this.getCharacteristic(Characteristic_1.Characteristic.Name) ||
80
- _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);
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
- Service.prototype.getServiceId = function () {
389
+ getServiceId() {
93
390
  return this.UUID + (this.subtype || "");
94
- };
391
+ }
95
392
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- Service.prototype.addCharacteristic = function (input) {
393
+ addCharacteristic(input, ...constructorArgs) {
97
394
  // characteristic might be a constructor like `Characteristic.Brightness` instead of an instance of Characteristic. Coerce if necessary.
98
- var e_1, _a;
99
- var constructorArgs = [];
100
- for (var _i = 1; _i < arguments.length; _i++) {
101
- constructorArgs[_i - 1] = arguments[_i];
102
- }
103
- var characteristic = typeof input === "function" ? new (input.bind.apply(input, tslib_1.__spreadArray([void 0], tslib_1.__read(constructorArgs), false)))() : input;
104
- try {
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
- Service.prototype.setPrimaryService = function (isPrimary) {
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
- Service.prototype.setHiddenService = function (isHidden) {
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
- Service.prototype.addLinkedService = function (service) {
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
- Service.prototype.removeLinkedService = function (service) {
453
+ removeLinkedService(service) {
174
454
  //TODO: Add a check if the service is on the same accessory.
175
- var index = this.linkedServices.indexOf(service);
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
- Service.prototype.removeCharacteristic = function (characteristic) {
182
- var index = this.characteristics.indexOf(characteristic);
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
- Service.prototype.getCharacteristic = function (name) {
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
- var e_2, _a, e_3, _b;
194
- try {
195
- for (var _c = tslib_1.__values(this.characteristics), _d = _c.next(); !_d.done; _d = _c.next()) {
196
- var characteristic = _d.value;
197
- if (typeof name === "string" && characteristic.displayName === name) {
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
- try {
217
- for (var _e = tslib_1.__values(this.optionalCharacteristics), _f = _e.next(); !_f.done; _f = _e.next()) {
218
- var characteristic = _f.value;
219
- // @ts-expect-error ('UUID' does not exist on type 'never')
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
- var instance = this.addCharacteristic(name);
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
- Service.prototype.testCharacteristic = function (name) {
241
- var e_4, _a;
242
- try {
243
- // checks for the existence of a characteristic object in the service
244
- for (var _b = tslib_1.__values(this.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
245
- var characteristic = _c.value;
246
- if (typeof name === "string" && characteristic.displayName === name) {
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
- Service.prototype.setCharacteristic = function (name, value) {
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
- Service.prototype.updateCharacteristic = function (name, value) {
518
+ }
519
+ updateCharacteristic(name, value) {
272
520
  this.getCharacteristic(name).updateValue(value);
273
521
  return this;
274
- };
275
- Service.prototype.addOptionalCharacteristic = function (characteristic) {
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
- Service.prototype.replaceCharacteristicsFromService = function (service) {
295
- var _this = this;
542
+ replaceCharacteristicsFromService(service) {
296
543
  if (this.UUID !== service.UUID) {
297
- 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}`);
298
545
  }
299
- var foreignCharacteristics = {}; // index foreign characteristics by UUID
300
- service.characteristics.forEach(function (characteristic) { return foreignCharacteristics[characteristic.UUID] = characteristic; });
301
- this.characteristics.forEach(function (characteristic) {
302
- 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];
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(function (characteristic) { return _this.addCharacteristic(characteristic); });
313
- };
559
+ Object.values(foreignCharacteristics).forEach(characteristic => this.addCharacteristic(characteristic));
560
+ }
314
561
  /**
315
562
  * @private
316
563
  */
317
- Service.prototype.getCharacteristicByIID = function (iid) {
318
- var e_5, _a;
319
- try {
320
- for (var _b = tslib_1.__values(this.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- Service.prototype._assignIDs = function (identifierCache, accessoryName, baseIID) {
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
- try {
350
- // assign IIDs to our Characteristics
351
- for (var _b = tslib_1.__values(this.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- Service.prototype.toHAP = function (connection, contactGetHandlers) {
369
- var _this = this;
370
- if (contactGetHandlers === void 0) { contactGetHandlers = true; }
371
- return new Promise(function (resolve) {
372
- var e_7, _a, e_8, _b;
373
- (0, assert_1.default)(_this.iid, "iid cannot be undefined for service '" + _this.displayName + "'");
374
- (0, assert_1.default)(_this.characteristics.length, "service '" + _this.displayName + "' does not have any characteristics!");
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: _this.isHiddenService ? true : undefined,
380
- primary: _this.isPrimaryService ? true : undefined,
600
+ hidden: this.isHiddenService ? true : undefined,
601
+ primary: this.isPrimaryService ? true : undefined,
381
602
  };
382
- if (_this.linkedServices.length) {
603
+ if (this.linkedServices.length) {
383
604
  service.linked = [];
384
- try {
385
- for (var _c = tslib_1.__values(_this.linkedServices), _d = _c.next(); !_d.done; _d = _c.next()) {
386
- var linked = _d.value;
387
- if (!linked.iid) {
388
- // we got a linked service which is not added to the accessory
389
- // as it doesn't "exists" we just ignore it.
390
- // we have some (at least one) plugins on homebridge which link to the AccessoryInformation service.
391
- // homebridge always creates its own AccessoryInformation service and ignores the user supplied one
392
- // thus the link is automatically broken.
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
- finally { if (e_7) throw e_7.error; }
615
+ service.linked.push(linked.iid);
405
616
  }
406
617
  }
407
- var missingCharacteristics = new Set();
408
- var timeout = setTimeout(function () {
409
- var e_9, _a;
410
- try {
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
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
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
- try {
427
- for (var missingCharacteristics_2 = tslib_1.__values(missingCharacteristics), missingCharacteristics_2_1 = missingCharacteristics_2.next(); !missingCharacteristics_2_1.done; missingCharacteristics_2_1 = missingCharacteristics_2.next()) {
428
- var characteristic = missingCharacteristics_2_1.value;
429
- _this.emitCharacteristicWarningEvent(characteristic, "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */, "The read handler for the characteristic '" + (characteristic === null || characteristic === void 0 ? void 0 : characteristic.displayName) +
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
- var _loop_1 = function (characteristic) {
634
+ for (const characteristic of this.characteristics) {
446
635
  missingCharacteristics.add(characteristic);
447
- characteristic.toHAP(connection, contactGetHandlers).then(function (value) {
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
- Service.prototype.internalHAPRepresentation = function () {
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
- var service = {
660
+ const service = {
486
661
  type: (0, uuid_1.toShortForm)(this.UUID),
487
662
  iid: this.iid,
488
- characteristics: this.characteristics.map(function (characteristic) { return characteristic.internalHAPRepresentation(); }),
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
- try {
495
- for (var _b = tslib_1.__values(this.linkedServices), _c = _b.next(); !_c.done; _c = _b.next()) {
496
- var linked = _c.value;
497
- if (!linked.iid) {
498
- // we got a linked service which is not added to the accessory
499
- // as it doesn't "exists" we just ignore it.
500
- // we have some (at least one) plugins on homebridge which link to the AccessoryInformation service.
501
- // homebridge always creates its own AccessoryInformation service and ignores the user supplied one
502
- // thus the link is automatically broken.
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
- Service.prototype.setupCharacteristicEventHandlers = function (characteristic) {
523
- var _this = this;
687
+ setupCharacteristicEventHandlers(characteristic) {
524
688
  // listen for changes in characteristics and bubble them up
525
- characteristic.on("change" /* CharacteristicEventTypes.CHANGE */, function (change) {
526
- _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 });
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
- Service.prototype.emitCharacteristicWarningEvent = function (characteristic, type, message, stack) {
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
- Service.prototype._sideloadCharacteristics = function (targetCharacteristics) {
546
- var e_12, _a;
547
- try {
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
- Service.serialize = function (service) {
566
- var constructorName;
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(function (characteristic) { return Characteristic_1.Characteristic.serialize(characteristic); }),
578
- 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)),
579
732
  };
580
- };
733
+ }
581
734
  /**
582
735
  * @private
583
736
  */
584
- Service.deserialize = function (json) {
585
- var service;
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
- var constructor = Service[json.constructorName];
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
- 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));
597
750
  service._sideloadCharacteristics(characteristics);
598
751
  if (json.optionalCharacteristics) {
599
- 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));
600
753
  }
601
754
  return service;
602
- };
603
- return Service;
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