hap-nodejs 0.11.0-beta.9 → 0.11.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 (214) hide show
  1. package/README.md +1 -0
  2. package/dist/BridgedCore.js +4 -4
  3. package/dist/BridgedCore.js.map +1 -1
  4. package/dist/Core.js +2 -2
  5. package/dist/Core.js.map +1 -1
  6. package/dist/accessories/AirConditioner_accessory.js +18 -18
  7. package/dist/accessories/AirConditioner_accessory.js.map +1 -1
  8. package/dist/accessories/AppleTVRemote_accessory.js +6 -6
  9. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
  10. package/dist/accessories/Camera_accessory.js +96 -87
  11. package/dist/accessories/Camera_accessory.js.map +1 -1
  12. package/dist/accessories/Fan_accessory.js +6 -6
  13. package/dist/accessories/Fan_accessory.js.map +1 -1
  14. package/dist/accessories/GarageDoorOpener_accessory.js +4 -4
  15. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
  16. package/dist/accessories/Light-AdaptiveLighting_accessory.js +2 -2
  17. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
  18. package/dist/accessories/Light_accessory.js +11 -11
  19. package/dist/accessories/Light_accessory.js.map +1 -1
  20. package/dist/accessories/Lock_accessory.js +4 -4
  21. package/dist/accessories/Lock_accessory.js.map +1 -1
  22. package/dist/accessories/MotionSensor_accessory.js +3 -3
  23. package/dist/accessories/MotionSensor_accessory.js.map +1 -1
  24. package/dist/accessories/Outlet_accessory.js +4 -4
  25. package/dist/accessories/Outlet_accessory.js.map +1 -1
  26. package/dist/accessories/SmartSpeaker_accessory.js +5 -5
  27. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
  28. package/dist/accessories/Sprinkler_accessory.js +7 -7
  29. package/dist/accessories/Sprinkler_accessory.js.map +1 -1
  30. package/dist/accessories/TV_accessory.js +9 -9
  31. package/dist/accessories/TV_accessory.js.map +1 -1
  32. package/dist/accessories/TemperatureSensor_accessory.js +2 -2
  33. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
  34. package/dist/accessories/Wi-FiRouter_accessory.js +2 -2
  35. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
  36. package/dist/accessories/Wi-FiSatellite_accessory.js +2 -2
  37. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
  38. package/dist/accessories/gstreamer-audioProducer.d.ts +2 -2
  39. package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
  40. package/dist/accessories/gstreamer-audioProducer.js +20 -20
  41. package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
  42. package/dist/index.d.ts +30 -6
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +39 -25
  45. package/dist/index.js.map +1 -1
  46. package/dist/internal-types.d.ts +65 -126
  47. package/dist/internal-types.d.ts.map +1 -1
  48. package/dist/internal-types.js +66 -5
  49. package/dist/internal-types.js.map +1 -1
  50. package/dist/lib/Accessory.d.ts +97 -21
  51. package/dist/lib/Accessory.d.ts.map +1 -1
  52. package/dist/lib/Accessory.js +315 -327
  53. package/dist/lib/Accessory.js.map +1 -1
  54. package/dist/lib/AccessoryLoader.d.ts +12 -0
  55. package/dist/lib/AccessoryLoader.d.ts.map +1 -1
  56. package/dist/lib/AccessoryLoader.js +18 -6
  57. package/dist/lib/AccessoryLoader.js.map +1 -1
  58. package/dist/lib/Advertiser.d.ts +32 -0
  59. package/dist/lib/Advertiser.d.ts.map +1 -1
  60. package/dist/lib/Advertiser.js +136 -58
  61. package/dist/lib/Advertiser.js.map +1 -1
  62. package/dist/lib/Bridge.d.ts +2 -0
  63. package/dist/lib/Bridge.d.ts.map +1 -1
  64. package/dist/lib/Bridge.js +3 -1
  65. package/dist/lib/Bridge.js.map +1 -1
  66. package/dist/lib/Characteristic.d.ts +872 -40
  67. package/dist/lib/Characteristic.d.ts.map +1 -1
  68. package/dist/lib/Characteristic.js +172 -141
  69. package/dist/lib/Characteristic.js.map +1 -1
  70. package/dist/lib/HAPServer.d.ts +113 -20
  71. package/dist/lib/HAPServer.d.ts.map +1 -1
  72. package/dist/lib/HAPServer.js +226 -231
  73. package/dist/lib/HAPServer.js.map +1 -1
  74. package/dist/lib/Service.d.ts +329 -13
  75. package/dist/lib/Service.d.ts.map +1 -1
  76. package/dist/lib/Service.js +45 -40
  77. package/dist/lib/Service.js.map +1 -1
  78. package/dist/lib/camera/Camera.d.ts +13 -4
  79. package/dist/lib/camera/Camera.d.ts.map +1 -1
  80. package/dist/lib/camera/Camera.js +3 -0
  81. package/dist/lib/camera/Camera.js.map +1 -1
  82. package/dist/lib/camera/RTPProxy.d.ts +5 -0
  83. package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
  84. package/dist/lib/camera/RTPProxy.js +2 -1
  85. package/dist/lib/camera/RTPProxy.js.map +1 -1
  86. package/dist/lib/camera/RTPStreamManagement.d.ts +156 -33
  87. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
  88. package/dist/lib/camera/RTPStreamManagement.js +204 -164
  89. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  90. package/dist/lib/camera/RecordingManagement.d.ts +61 -11
  91. package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
  92. package/dist/lib/camera/RecordingManagement.js +171 -138
  93. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  94. package/dist/lib/camera/index.js +4 -4
  95. package/dist/lib/camera/index.js.map +1 -1
  96. package/dist/lib/controller/AdaptiveLightingController.d.ts +28 -2
  97. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
  98. package/dist/lib/controller/AdaptiveLightingController.js +77 -68
  99. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  100. package/dist/lib/controller/CameraController.d.ts +44 -13
  101. package/dist/lib/controller/CameraController.d.ts.map +1 -1
  102. package/dist/lib/controller/CameraController.js +43 -34
  103. package/dist/lib/controller/CameraController.js.map +1 -1
  104. package/dist/lib/controller/Controller.d.ts +28 -7
  105. package/dist/lib/controller/Controller.d.ts.map +1 -1
  106. package/dist/lib/controller/Controller.js +7 -0
  107. package/dist/lib/controller/Controller.js.map +1 -1
  108. package/dist/lib/controller/DoorbellController.d.ts +5 -1
  109. package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
  110. package/dist/lib/controller/DoorbellController.js +5 -3
  111. package/dist/lib/controller/DoorbellController.js.map +1 -1
  112. package/dist/lib/controller/RemoteController.d.ts +108 -39
  113. package/dist/lib/controller/RemoteController.d.ts.map +1 -1
  114. package/dist/lib/controller/RemoteController.js +190 -175
  115. package/dist/lib/controller/RemoteController.js.map +1 -1
  116. package/dist/lib/controller/index.js +5 -5
  117. package/dist/lib/controller/index.js.map +1 -1
  118. package/dist/lib/datastream/DataStreamManagement.d.ts +25 -19
  119. package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
  120. package/dist/lib/datastream/DataStreamManagement.js +36 -30
  121. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  122. package/dist/lib/datastream/DataStreamParser.d.ts +39 -0
  123. package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
  124. package/dist/lib/datastream/DataStreamParser.js +125 -88
  125. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  126. package/dist/lib/datastream/DataStreamServer.d.ts +121 -46
  127. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  128. package/dist/lib/datastream/DataStreamServer.js +134 -100
  129. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  130. package/dist/lib/datastream/index.js +3 -3
  131. package/dist/lib/datastream/index.js.map +1 -1
  132. package/dist/lib/definitions/CharacteristicDefinitions.js +799 -799
  133. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  134. package/dist/lib/definitions/ServiceDefinitions.js +77 -77
  135. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  136. package/dist/lib/definitions/generate-definitions.js +60 -59
  137. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  138. package/dist/lib/definitions/generator-configuration.js +15 -15
  139. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  140. package/dist/lib/definitions/index.js +2 -2
  141. package/dist/lib/definitions/index.js.map +1 -1
  142. package/dist/lib/model/AccessoryInfo.d.ts +10 -4
  143. package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
  144. package/dist/lib/model/AccessoryInfo.js +21 -17
  145. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  146. package/dist/lib/model/ControllerStorage.d.ts +3 -0
  147. package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
  148. package/dist/lib/model/ControllerStorage.js +8 -5
  149. package/dist/lib/model/ControllerStorage.js.map +1 -1
  150. package/dist/lib/model/HAPStorage.d.ts +3 -0
  151. package/dist/lib/model/HAPStorage.d.ts.map +1 -1
  152. package/dist/lib/model/HAPStorage.js +4 -1
  153. package/dist/lib/model/HAPStorage.js.map +1 -1
  154. package/dist/lib/model/IdentifierCache.d.ts +1 -0
  155. package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
  156. package/dist/lib/model/IdentifierCache.js +3 -2
  157. package/dist/lib/model/IdentifierCache.js.map +1 -1
  158. package/dist/lib/tv/AccessControlManagement.d.ts +11 -0
  159. package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
  160. package/dist/lib/tv/AccessControlManagement.js +15 -7
  161. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  162. package/dist/lib/util/clone.d.ts +2 -1
  163. package/dist/lib/util/clone.d.ts.map +1 -1
  164. package/dist/lib/util/clone.js +5 -4
  165. package/dist/lib/util/clone.js.map +1 -1
  166. package/dist/lib/util/color-utils.d.ts +4 -1
  167. package/dist/lib/util/color-utils.d.ts.map +1 -1
  168. package/dist/lib/util/color-utils.js +5 -2
  169. package/dist/lib/util/color-utils.js.map +1 -1
  170. package/dist/lib/util/eventedhttp.d.ts +52 -9
  171. package/dist/lib/util/eventedhttp.d.ts.map +1 -1
  172. package/dist/lib/util/eventedhttp.js +141 -135
  173. package/dist/lib/util/eventedhttp.js.map +1 -1
  174. package/dist/lib/util/hapCrypto.d.ts +30 -2
  175. package/dist/lib/util/hapCrypto.d.ts.map +1 -1
  176. package/dist/lib/util/hapCrypto.js +28 -4
  177. package/dist/lib/util/hapCrypto.js.map +1 -1
  178. package/dist/lib/util/hapStatusError.d.ts +2 -0
  179. package/dist/lib/util/hapStatusError.d.ts.map +1 -1
  180. package/dist/lib/util/hapStatusError.js +4 -2
  181. package/dist/lib/util/hapStatusError.js.map +1 -1
  182. package/dist/lib/util/net-utils.d.ts +7 -0
  183. package/dist/lib/util/net-utils.d.ts.map +1 -1
  184. package/dist/lib/util/net-utils.js +11 -4
  185. package/dist/lib/util/net-utils.js.map +1 -1
  186. package/dist/lib/util/once.d.ts +5 -0
  187. package/dist/lib/util/once.d.ts.map +1 -1
  188. package/dist/lib/util/once.js +6 -1
  189. package/dist/lib/util/once.js.map +1 -1
  190. package/dist/lib/util/promise-utils.d.ts +13 -0
  191. package/dist/lib/util/promise-utils.d.ts.map +1 -1
  192. package/dist/lib/util/promise-utils.js +27 -1
  193. package/dist/lib/util/promise-utils.js.map +1 -1
  194. package/dist/lib/util/request-util.d.ts +16 -0
  195. package/dist/lib/util/request-util.d.ts.map +1 -1
  196. package/dist/lib/util/request-util.js +42 -27
  197. package/dist/lib/util/request-util.js.map +1 -1
  198. package/dist/lib/util/time.d.ts +6 -0
  199. package/dist/lib/util/time.d.ts.map +1 -1
  200. package/dist/lib/util/time.js +8 -2
  201. package/dist/lib/util/time.js.map +1 -1
  202. package/dist/lib/util/tlv.d.ts +95 -5
  203. package/dist/lib/util/tlv.d.ts.map +1 -1
  204. package/dist/lib/util/tlv.js +90 -21
  205. package/dist/lib/util/tlv.js.map +1 -1
  206. package/dist/lib/util/uuid.d.ts +2 -3
  207. package/dist/lib/util/uuid.d.ts.map +1 -1
  208. package/dist/lib/util/uuid.js +1 -1
  209. package/dist/lib/util/uuid.js.map +1 -1
  210. package/dist/types.d.ts +267 -19
  211. package/dist/types.d.ts.map +1 -1
  212. package/dist/types.js +8 -0
  213. package/dist/types.js.map +1 -1
  214. package/package.json +10 -7
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Accessory = exports.AccessoryEventTypes = exports.MDNSAdvertiser = exports.CharacteristicWarningType = exports.Categories = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var assert_1 = (0, tslib_1.__importDefault)(require("assert"));
6
- var crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
7
- var debug_1 = (0, tslib_1.__importDefault)(require("debug"));
5
+ var assert_1 = tslib_1.__importDefault(require("assert"));
6
+ var crypto_1 = tslib_1.__importDefault(require("crypto"));
7
+ var debug_1 = tslib_1.__importDefault(require("debug"));
8
8
  var events_1 = require("events");
9
- var net_1 = (0, tslib_1.__importDefault)(require("net"));
9
+ var net_1 = tslib_1.__importDefault(require("net"));
10
10
  var Advertiser_1 = require("./Advertiser");
11
11
  // noinspection JSDeprecatedSymbols
12
12
  var camera_1 = require("./camera");
@@ -19,12 +19,16 @@ var IdentifierCache_1 = require("./model/IdentifierCache");
19
19
  var Service_1 = require("./Service");
20
20
  var clone_1 = require("./util/clone");
21
21
  var request_util_1 = require("./util/request-util");
22
- var uuid = (0, tslib_1.__importStar)(require("./util/uuid"));
22
+ var uuid = tslib_1.__importStar(require("./util/uuid"));
23
23
  var uuid_1 = require("./util/uuid");
24
24
  var debug = (0, debug_1.default)("HAP-NodeJS:Accessory");
25
25
  var MAX_ACCESSORIES = 149; // Maximum number of bridged accessories per bridge.
26
26
  var MAX_SERVICES = 100;
27
- // Known category values. Category is a hint to iOS clients about what "type" of Accessory this represents, for UI only.
27
+ /**
28
+ * Known category values. Category is a hint to iOS clients about what "type" of Accessory this represents, for UI only.
29
+ *
30
+ * @group Accessory
31
+ */
28
32
  var Categories;
29
33
  (function (Categories) {
30
34
  // noinspection JSUnusedGlobalSymbols
@@ -67,6 +71,9 @@ var Categories;
67
71
  Categories[Categories["TV_SET_TOP_BOX"] = 35] = "TV_SET_TOP_BOX";
68
72
  Categories[Categories["TV_STREAMING_STICK"] = 36] = "TV_STREAMING_STICK";
69
73
  })(Categories = exports.Categories || (exports.Categories = {}));
74
+ /**
75
+ * @group Accessory
76
+ */
70
77
  var CharacteristicWarningType;
71
78
  (function (CharacteristicWarningType) {
72
79
  CharacteristicWarningType["SLOW_WRITE"] = "slow-write";
@@ -77,6 +84,9 @@ var CharacteristicWarningType;
77
84
  CharacteristicWarningType["ERROR_MESSAGE"] = "error-message";
78
85
  CharacteristicWarningType["DEBUG_MESSAGE"] = "debug-message";
79
86
  })(CharacteristicWarningType = exports.CharacteristicWarningType || (exports.CharacteristicWarningType = {}));
87
+ /**
88
+ * @group Accessory
89
+ */
80
90
  var MDNSAdvertiser;
81
91
  (function (MDNSAdvertiser) {
82
92
  /**
@@ -106,6 +116,9 @@ var WriteRequestState;
106
116
  WriteRequestState[WriteRequestState["TIMED_WRITE_AUTHENTICATED"] = 1] = "TIMED_WRITE_AUTHENTICATED";
107
117
  WriteRequestState[WriteRequestState["TIMED_WRITE_REJECTED"] = 2] = "TIMED_WRITE_REJECTED";
108
118
  })(WriteRequestState || (WriteRequestState = {}));
119
+ /**
120
+ * @group Accessory
121
+ */
109
122
  var AccessoryEventTypes;
110
123
  (function (AccessoryEventTypes) {
111
124
  /**
@@ -144,9 +157,11 @@ var AccessoryEventTypes;
144
157
  * are hosted by the Bridge. This UUID must be "stable" and unchanging, even when the server is restarted. This
145
158
  * is required so that the Bridge can provide consistent "Accessory IDs" (aid) and "Instance IDs" (iid) for all
146
159
  * Accessories, Services, and Characteristics for iOS clients to reference later.
160
+ *
161
+ * @group Accessory
147
162
  */
148
163
  var Accessory = /** @class */ (function (_super) {
149
- (0, tslib_1.__extends)(Accessory, _super);
164
+ tslib_1.__extends(Accessory, _super);
150
165
  function Accessory(displayName, UUID) {
151
166
  var _this = _super.call(this) || this;
152
167
  _this.displayName = displayName;
@@ -157,7 +172,7 @@ var Accessory = /** @class */ (function (_super) {
157
172
  _this.bridged = false; // true if we are hosted "behind" a Bridge Accessory
158
173
  _this.bridgedAccessories = []; // If we are a Bridge, these are the Accessories we are bridging
159
174
  _this.reachable = true;
160
- _this.category = 1 /* OTHER */;
175
+ _this.category = 1 /* Categories.OTHER */;
161
176
  _this.services = [];
162
177
  _this.shouldPurgeUnusedIDs = true; // Purge unused ids by default
163
178
  /**
@@ -167,7 +182,13 @@ var Accessory = /** @class */ (function (_super) {
167
182
  */
168
183
  _this.initialized = false;
169
184
  _this.controllers = {};
185
+ /**
186
+ * @private Private API.
187
+ */
170
188
  _this._setupID = null;
189
+ /**
190
+ * @private Private API.
191
+ */
171
192
  _this.controllerStorage = new ControllerStorage_1.ControllerStorage(_this);
172
193
  /**
173
194
  * This property captures the time when we last served a /accessories request.
@@ -176,7 +197,7 @@ var Accessory = /** @class */ (function (_super) {
176
197
  _this.lastAccessoriesRequest = 0;
177
198
  /**
178
199
  * Returns the bridging accessory if this accessory is bridged.
179
- * Otherwise returns itself.
200
+ * Otherwise, returns itself.
180
201
  *
181
202
  * @returns the primary accessory
182
203
  */
@@ -194,7 +215,7 @@ var Accessory = /** @class */ (function (_super) {
194
215
  // for us to identify ourselves (as opposed to an unpaired device - that case is handled by HAPServer 'identify' event)
195
216
  _this.getService(Service_1.Service.AccessoryInformation)
196
217
  .getCharacteristic(Characteristic_1.Characteristic.Identify)
197
- .on("set" /* SET */, function (value, callback) {
218
+ .on("set" /* CharacteristicEventTypes.SET */, function (value, callback) {
198
219
  if (value) {
199
220
  var paired = true;
200
221
  _this.identificationRequest(paired, callback);
@@ -204,10 +225,10 @@ var Accessory = /** @class */ (function (_super) {
204
225
  }
205
226
  Accessory.prototype.identificationRequest = function (paired, callback) {
206
227
  debug("[%s] Identification request", this.displayName);
207
- if (this.listeners("identify" /* IDENTIFY */).length > 0) {
228
+ if (this.listeners("identify" /* AccessoryEventTypes.IDENTIFY */).length > 0) {
208
229
  // allow implementors to identify this Accessory in whatever way is appropriate, and pass along
209
230
  // the standard callback for completion.
210
- this.emit("identify" /* IDENTIFY */, paired, callback);
231
+ this.emit("identify" /* AccessoryEventTypes.IDENTIFY */, paired, callback);
211
232
  }
212
233
  else {
213
234
  debug("[%s] Identification request ignored; no listeners to 'identify' event", this.displayName);
@@ -228,7 +249,7 @@ var Accessory = /** @class */ (function (_super) {
228
249
  : serviceParam;
229
250
  try {
230
251
  // check for UUID+subtype conflict
231
- for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
252
+ for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
232
253
  var existing = _c.value;
233
254
  if (existing.UUID === service.UUID) {
234
255
  // OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
@@ -264,7 +285,7 @@ var Accessory = /** @class */ (function (_super) {
264
285
  this.enqueueConfigurationUpdate();
265
286
  }
266
287
  else {
267
- this.emit("service-configurationChange" /* SERVICE_CONFIGURATION_CHANGE */, { service: service });
288
+ this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service: service });
268
289
  }
269
290
  this.setupServiceEventHandlers(service);
270
291
  return service;
@@ -287,7 +308,7 @@ var Accessory = /** @class */ (function (_super) {
287
308
  this.enqueueConfigurationUpdate();
288
309
  }
289
310
  else {
290
- this.emit("service-configurationChange" /* SERVICE_CONFIGURATION_CHANGE */, { service: service });
311
+ this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service: service });
291
312
  }
292
313
  service.removeAllListeners();
293
314
  }
@@ -295,7 +316,7 @@ var Accessory = /** @class */ (function (_super) {
295
316
  Accessory.prototype.removeLinkedService = function (removed) {
296
317
  var e_2, _a;
297
318
  try {
298
- for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
319
+ for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
299
320
  var service = _c.value;
300
321
  service.removeLinkedService(removed);
301
322
  }
@@ -311,11 +332,10 @@ var Accessory = /** @class */ (function (_super) {
311
332
  Accessory.prototype.getService = function (name) {
312
333
  var e_3, _a;
313
334
  try {
314
- for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
335
+ for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
315
336
  var service = _c.value;
316
337
  if (typeof name === "string" && (service.displayName === name || service.name === name || service.subtype === name)) {
317
338
  return service;
318
- // @ts-expect-error: UUID property
319
339
  }
320
340
  else if (typeof name === "function" && ((service instanceof name) || (name.UUID === service.UUID))) {
321
341
  return service;
@@ -334,11 +354,10 @@ var Accessory = /** @class */ (function (_super) {
334
354
  Accessory.prototype.getServiceById = function (uuid, subType) {
335
355
  var e_4, _a;
336
356
  try {
337
- for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
357
+ for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
338
358
  var service = _c.value;
339
359
  if (typeof uuid === "string" && (service.displayName === uuid || service.name === uuid) && service.subtype === subType) {
340
360
  return service;
341
- // @ts-expect-error: UUID property
342
361
  }
343
362
  else if (typeof uuid === "function" && ((service instanceof uuid) || (uuid.UUID === service.UUID)) && service.subtype === subType) {
344
363
  return service;
@@ -365,35 +384,25 @@ var Accessory = /** @class */ (function (_super) {
365
384
  debug("Reachability update is no longer being supported.");
366
385
  };
367
386
  Accessory.prototype.addBridgedAccessory = function (accessory, deferUpdate) {
368
- var e_5, _a;
369
387
  var _this = this;
370
388
  if (deferUpdate === void 0) { deferUpdate = false; }
371
- if (accessory._isBridge) {
372
- throw new Error("Cannot Bridge another Bridge!");
389
+ if (accessory._isBridge || accessory === this) {
390
+ throw new Error("Illegal state: either trying to bridge a bridge or trying to bridge itself!");
373
391
  }
374
- try {
375
- // check for UUID conflict
376
- for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
377
- var existing = _c.value;
378
- if (existing.UUID === accessory.UUID) {
379
- throw new Error("Cannot add a bridged Accessory with the same UUID as another bridged Accessory: " + existing.UUID);
380
- }
381
- }
392
+ if (accessory.initialized) {
393
+ throw new Error("Tried to bridge an accessory which was already published once!");
382
394
  }
383
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
384
- finally {
385
- try {
386
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
387
- }
388
- finally { if (e_5) throw e_5.error; }
395
+ if (accessory.bridge != null) {
396
+ // this also prevents that we bridge the same accessory twice!
397
+ throw new Error("Tried to bridge " + accessory.displayName + " while it was already bridged by " + accessory.bridge.displayName);
389
398
  }
390
399
  if (this.bridgedAccessories.length >= MAX_ACCESSORIES) {
391
400
  throw new Error("Cannot Bridge more than " + MAX_ACCESSORIES + " Accessories");
392
401
  }
393
402
  // listen for changes in ANY characteristics of ANY services on this Accessory
394
- accessory.on("service-characteristic-change" /* SERVICE_CHARACTERISTIC_CHANGE */, function (change) { return _this.handleCharacteristicChangeEvent(accessory, change.service, change); });
395
- accessory.on("service-configurationChange" /* SERVICE_CONFIGURATION_CHANGE */, this.enqueueConfigurationUpdate.bind(this));
396
- accessory.on("characteristic-warning" /* CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
403
+ accessory.on("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, function (change) { return _this.handleCharacteristicChangeEvent(accessory, change.service, change); });
404
+ accessory.on("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, this.enqueueConfigurationUpdate.bind(this));
405
+ accessory.on("characteristic-warning" /* AccessoryEventTypes.CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
397
406
  accessory.bridged = true;
398
407
  accessory.bridge = this;
399
408
  this.bridgedAccessories.push(accessory);
@@ -404,53 +413,51 @@ var Accessory = /** @class */ (function (_super) {
404
413
  return accessory;
405
414
  };
406
415
  Accessory.prototype.addBridgedAccessories = function (accessories) {
407
- var e_6, _a;
416
+ var e_5, _a;
408
417
  try {
409
- for (var accessories_1 = (0, tslib_1.__values)(accessories), accessories_1_1 = accessories_1.next(); !accessories_1_1.done; accessories_1_1 = accessories_1.next()) {
418
+ for (var accessories_1 = tslib_1.__values(accessories), accessories_1_1 = accessories_1.next(); !accessories_1_1.done; accessories_1_1 = accessories_1.next()) {
410
419
  var accessory = accessories_1_1.value;
411
420
  this.addBridgedAccessory(accessory, true);
412
421
  }
413
422
  }
414
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
423
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
415
424
  finally {
416
425
  try {
417
426
  if (accessories_1_1 && !accessories_1_1.done && (_a = accessories_1.return)) _a.call(accessories_1);
418
427
  }
419
- finally { if (e_6) throw e_6.error; }
428
+ finally { if (e_5) throw e_5.error; }
420
429
  }
421
430
  this.enqueueConfigurationUpdate();
422
431
  };
423
432
  Accessory.prototype.removeBridgedAccessory = function (accessory, deferUpdate) {
424
- if (accessory._isBridge) {
425
- throw new Error("Cannot Bridge another Bridge!");
426
- }
433
+ if (deferUpdate === void 0) { deferUpdate = false; }
427
434
  // check for UUID conflict
428
- var foundMatchAccessory = this.bridgedAccessories.findIndex(function (existing) {
429
- return existing.UUID === accessory.UUID;
430
- });
431
- if (foundMatchAccessory === -1) {
435
+ var accessoryIndex = this.bridgedAccessories.indexOf(accessory);
436
+ if (accessoryIndex === -1) {
432
437
  throw new Error("Cannot find the bridged Accessory to remove.");
433
438
  }
434
- this.bridgedAccessories.splice(foundMatchAccessory, 1);
439
+ this.bridgedAccessories.splice(accessoryIndex, 1);
440
+ accessory.bridged = false;
441
+ accessory.bridge = undefined;
435
442
  accessory.removeAllListeners();
436
443
  if (!deferUpdate) {
437
444
  this.enqueueConfigurationUpdate();
438
445
  }
439
446
  };
440
447
  Accessory.prototype.removeBridgedAccessories = function (accessories) {
441
- var e_7, _a;
448
+ var e_6, _a;
442
449
  try {
443
- for (var accessories_2 = (0, tslib_1.__values)(accessories), accessories_2_1 = accessories_2.next(); !accessories_2_1.done; accessories_2_1 = accessories_2.next()) {
450
+ for (var accessories_2 = tslib_1.__values(accessories), accessories_2_1 = accessories_2.next(); !accessories_2_1.done; accessories_2_1 = accessories_2.next()) {
444
451
  var accessory = accessories_2_1.value;
445
452
  this.removeBridgedAccessory(accessory, true);
446
453
  }
447
454
  }
448
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
455
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
449
456
  finally {
450
457
  try {
451
458
  if (accessories_2_1 && !accessories_2_1.done && (_a = accessories_2.return)) _a.call(accessories_2);
452
459
  }
453
- finally { if (e_7) throw e_7.error; }
460
+ finally { if (e_6) throw e_6.error; }
454
461
  }
455
462
  this.enqueueConfigurationUpdate();
456
463
  };
@@ -461,9 +468,9 @@ var Accessory = /** @class */ (function (_super) {
461
468
  this.enqueueConfigurationUpdate();
462
469
  };
463
470
  Accessory.prototype.getCharacteristicByIID = function (iid) {
464
- var e_8, _a;
471
+ var e_7, _a;
465
472
  try {
466
- for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
473
+ for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
467
474
  var service = _c.value;
468
475
  var characteristic = service.getCharacteristicByIID(iid);
469
476
  if (characteristic) {
@@ -471,35 +478,19 @@ var Accessory = /** @class */ (function (_super) {
471
478
  }
472
479
  }
473
480
  }
474
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
481
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
475
482
  finally {
476
483
  try {
477
484
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
478
485
  }
479
- finally { if (e_8) throw e_8.error; }
486
+ finally { if (e_7) throw e_7.error; }
480
487
  }
481
488
  };
482
489
  Accessory.prototype.getAccessoryByAID = function (aid) {
483
- var e_9, _a;
484
- if (aid === 1) {
490
+ if (this.aid === aid) {
485
491
  return this;
486
492
  }
487
- try {
488
- for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
489
- var accessory = _c.value;
490
- if (accessory.aid === aid) {
491
- return accessory;
492
- }
493
- }
494
- }
495
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
496
- finally {
497
- try {
498
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
499
- }
500
- finally { if (e_9) throw e_9.error; }
501
- }
502
- return undefined;
493
+ return this.bridgedAccessories.find(function (value) { return value.aid === aid; });
503
494
  };
504
495
  Accessory.prototype.findCharacteristic = function (aid, iid) {
505
496
  var accessory = this.getAccessoryByAID(aid);
@@ -525,8 +516,8 @@ var Accessory = /** @class */ (function (_super) {
525
516
  * - CameraOperatingMode
526
517
  * - CameraEventRecordingManagement
527
518
  *
528
- * @param cameraSource {LegacyCameraSource}
529
- * @deprecated please refer to the new {@see CameraController} API and {@link configureController}
519
+ * @param cameraSource - The instance of the legacy camera source
520
+ * @deprecated please refer to the new {@link CameraController} API and {@link configureController}
530
521
  */
531
522
  Accessory.prototype.configureCameraSource = function (cameraSource) {
532
523
  var _this = this;
@@ -557,7 +548,7 @@ var Accessory = /** @class */ (function (_super) {
557
548
  return cameraController; // return the reference for the controller (maybe this could be useful?)
558
549
  };
559
550
  /**
560
- * This method is used to setup a new Controller for this accessory. See {@see Controller} for a more detailed
551
+ * This method is used to set up a new Controller for this accessory. See {@link Controller} for a more detailed
561
552
  * explanation what a Controller is and what it is capable of.
562
553
  *
563
554
  * The controller can be passed as an instance of the class or as a constructor (without any necessary parameters)
@@ -565,10 +556,10 @@ var Accessory = /** @class */ (function (_super) {
565
556
  * Only one Controller of a given {@link ControllerIdentifier} can be configured for a given Accessory.
566
557
  *
567
558
  * When called, it will be checked if there are any services and persistent data the Controller (for the given
568
- * {@link ControllerIdentifier}) can be restored from. Otherwise the Controller will be created with new services.
559
+ * {@link ControllerIdentifier}) can be restored from. Otherwise, the Controller will be created with new services.
569
560
  *
570
561
  *
571
- * @param controllerConstructor {Controller | ControllerConstructor}
562
+ * @param controllerConstructor - The Controller instance or constructor to the Controller with no required arguments.
572
563
  */
573
564
  Accessory.prototype.configureController = function (controllerConstructor) {
574
565
  var _this = this;
@@ -632,7 +623,7 @@ var Accessory = /** @class */ (function (_super) {
632
623
  if (storedController) {
633
624
  if (storedController.controller !== controller) {
634
625
  throw new Error("[" + this.displayName + "] tried removing a controller with the id/type '" + id +
635
- "' though provided controller isn't the same which is registered!");
626
+ "' though provided controller isn't the same instance that is registered!");
636
627
  }
637
628
  if ((0, controller_1.isSerializableController)(controller)) {
638
629
  // this will reset the state change delegate before we call handleControllerRemoved()
@@ -657,9 +648,9 @@ var Accessory = /** @class */ (function (_super) {
657
648
  }
658
649
  };
659
650
  Accessory.prototype.handleAccessoryUnpairedForControllers = function () {
660
- var e_10, _a;
651
+ var e_8, _a;
661
652
  try {
662
- for (var _b = (0, tslib_1.__values)(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
653
+ for (var _b = tslib_1.__values(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
663
654
  var context = _c.value;
664
655
  var controller = context.controller;
665
656
  if (controller.handleFactoryReset) { // if the controller implements handleFactoryReset, setup event handlers for this controller
@@ -670,12 +661,12 @@ var Accessory = /** @class */ (function (_super) {
670
661
  }
671
662
  }
672
663
  }
673
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
664
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
674
665
  finally {
675
666
  try {
676
667
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
677
668
  }
678
- finally { if (e_10) throw e_10.error; }
669
+ finally { if (e_8) throw e_8.error; }
679
670
  }
680
671
  };
681
672
  Accessory.prototype.handleUpdatedControllerServiceMap = function (originalServiceMap, updatedServiceMap) {
@@ -685,8 +676,8 @@ var Accessory = /** @class */ (function (_super) {
685
676
  var service = originalServiceMap[name];
686
677
  var updatedService = updatedServiceMap[name];
687
678
  if (service && updatedService) { // we check all names contained in both ServiceMaps for changes
688
- delete originalServiceMap[name]; // delete from original ServiceMap so it will only contain deleted services at the end
689
- delete updatedServiceMap[name]; // delete from updated ServiceMap so it will only contain added services at the end
679
+ delete originalServiceMap[name]; // delete from original ServiceMap, so it will only contain deleted services at the end
680
+ delete updatedServiceMap[name]; // delete from updated ServiceMap, so it will only contain added services at the end
690
681
  if (service !== updatedService) {
691
682
  _this.removeService(service);
692
683
  _this.addService(updatedService);
@@ -709,17 +700,17 @@ var Accessory = /** @class */ (function (_super) {
709
700
  if (this._setupURI) {
710
701
  return this._setupURI;
711
702
  }
703
+ (0, assert_1.default)(!!this._accessoryInfo, "Cannot generate setupURI on an accessory that isn't published yet!");
712
704
  var buffer = Buffer.alloc(8);
713
- var setupCode = this._accessoryInfo && parseInt(this._accessoryInfo.pincode.replace(/-/g, ""), 10);
714
- var value_low = setupCode;
715
- var value_high = this._accessoryInfo && this._accessoryInfo.category >> 1;
705
+ var value_low = parseInt(this._accessoryInfo.pincode.replace(/-/g, ""), 10);
706
+ var value_high = this._accessoryInfo.category >> 1;
716
707
  value_low |= 1 << 28; // Supports IP;
717
708
  buffer.writeUInt32BE(value_low, 4);
718
- if (this._accessoryInfo && this._accessoryInfo.category & 1) {
709
+ if (this._accessoryInfo.category & 1) {
719
710
  buffer[4] = buffer[4] | 1 << 7;
720
711
  }
721
712
  buffer.writeUInt32BE(value_high, 0);
722
- var encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) * Math.pow(2, 32))).toString(36).toUpperCase();
713
+ var encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) * 0x100000000)).toString(36).toUpperCase();
723
714
  if (encodedPayload.length !== 9) {
724
715
  for (var i = 0; i <= 9 - encodedPayload.length; i++) {
725
716
  encodedPayload = "0" + encodedPayload;
@@ -769,9 +760,10 @@ var Accessory = /** @class */ (function (_super) {
769
760
  /**
770
761
  * Assigns aid/iid to ourselves, any Accessories we are bridging, and all associated Services+Characteristics. Uses
771
762
  * the provided identifierCache to keep IDs stable.
763
+ * @private Private API
772
764
  */
773
765
  Accessory.prototype._assignIDs = function (identifierCache) {
774
- var e_11, _a, e_12, _b;
766
+ var e_9, _a, e_10, _b;
775
767
  // if we are responsible for our own identifierCache, start the expiration process
776
768
  // also check weather we want to have an expiration process
777
769
  if (this._identifierCache && this.shouldPurgeUnusedIDs) {
@@ -788,7 +780,7 @@ var Accessory = /** @class */ (function (_super) {
788
780
  this.aid = 1;
789
781
  }
790
782
  try {
791
- for (var _c = (0, tslib_1.__values)(this.services), _d = _c.next(); !_d.done; _d = _c.next()) {
783
+ for (var _c = tslib_1.__values(this.services), _d = _c.next(); !_d.done; _d = _c.next()) {
792
784
  var service = _d.value;
793
785
  if (this._isBridge) {
794
786
  service._assignIDs(identifierCache, this.UUID, 2000000000);
@@ -798,26 +790,26 @@ var Accessory = /** @class */ (function (_super) {
798
790
  }
799
791
  }
800
792
  }
801
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
793
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
802
794
  finally {
803
795
  try {
804
796
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
805
797
  }
806
- finally { if (e_11) throw e_11.error; }
798
+ finally { if (e_9) throw e_9.error; }
807
799
  }
808
800
  try {
809
801
  // now assign IDs for any Accessories we are bridging
810
- for (var _e = (0, tslib_1.__values)(this.bridgedAccessories), _f = _e.next(); !_f.done; _f = _e.next()) {
802
+ for (var _e = tslib_1.__values(this.bridgedAccessories), _f = _e.next(); !_f.done; _f = _e.next()) {
811
803
  var accessory = _f.value;
812
804
  accessory._assignIDs(identifierCache);
813
805
  }
814
806
  }
815
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
807
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
816
808
  finally {
817
809
  try {
818
810
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
819
811
  }
820
- finally { if (e_12) throw e_12.error; }
812
+ finally { if (e_10) throw e_10.error; }
821
813
  }
822
814
  // expire any now-unused cache keys (for Accessories, Services, or Characteristics
823
815
  // that have been removed since the last call to assignIDs())
@@ -838,7 +830,7 @@ var Accessory = /** @class */ (function (_super) {
838
830
  };
839
831
  /**
840
832
  * Manually purge the unused ids if you like, comes handy
841
- * when you have disabled auto purge so you can do it manually
833
+ * when you have disabled auto purge, so you can do it manually
842
834
  */
843
835
  Accessory.prototype.purgeUnusedIDs = function () {
844
836
  //Cache the state of the purge mechanism and set it to true
@@ -854,10 +846,10 @@ var Accessory = /** @class */ (function (_super) {
854
846
  */
855
847
  Accessory.prototype.toHAP = function (connection, contactGetHandlers) {
856
848
  if (contactGetHandlers === void 0) { contactGetHandlers = true; }
857
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
849
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
858
850
  var accessory, accessories, _a, _b, _c, _d;
859
851
  var _e;
860
- return (0, tslib_1.__generator)(this, function (_f) {
852
+ return tslib_1.__generator(this, function (_f) {
861
853
  switch (_f.label) {
862
854
  case 0:
863
855
  (0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
@@ -888,7 +880,7 @@ var Accessory = /** @class */ (function (_super) {
888
880
  * Returns a JSON representation of this accessory without characteristic values.
889
881
  */
890
882
  Accessory.prototype.internalHAPRepresentation = function (assignIds) {
891
- var e_13, _a;
883
+ var e_11, _a;
892
884
  if (assignIds === void 0) { assignIds = true; }
893
885
  if (assignIds) {
894
886
  this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
@@ -902,17 +894,17 @@ var Accessory = /** @class */ (function (_super) {
902
894
  var accessories = [accessory];
903
895
  if (!this.bridged) {
904
896
  try {
905
- for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
897
+ for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
906
898
  var accessory_1 = _c.value;
907
899
  accessories.push(accessory_1.internalHAPRepresentation(false)[0]);
908
900
  }
909
901
  }
910
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
902
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
911
903
  finally {
912
904
  try {
913
905
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
914
906
  }
915
- finally { if (e_13) throw e_13.error; }
907
+ finally { if (e_11) throw e_11.error; }
916
908
  }
917
909
  }
918
910
  return accessories;
@@ -932,23 +924,26 @@ var Accessory = /** @class */ (function (_super) {
932
924
  * new Accessory.
933
925
  */
934
926
  Accessory.prototype.publish = function (info, allowInsecureRequest) {
935
- var _a, _b;
936
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
937
- var service, config, parsed, selectedAdvertiser, _c, _d, _e;
927
+ var _a, _b, _c;
928
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
929
+ var service, config, parsed, selectedAdvertiser, _d, _e, _f;
938
930
  var _this = this;
939
- return (0, tslib_1.__generator)(this, function (_f) {
940
- switch (_f.label) {
931
+ return tslib_1.__generator(this, function (_g) {
932
+ switch (_g.label) {
941
933
  case 0:
934
+ if (this.bridged) {
935
+ throw new Error("Can't publish in accessory which is bridged by another accessory. Bridged by " + ((_a = this.bridge) === null || _a === void 0 ? void 0 : _a.displayName));
936
+ }
942
937
  // noinspection JSDeprecatedSymbols
943
938
  if (!info.advertiser && info.useLegacyAdvertiser != null) {
944
939
  // noinspection JSDeprecatedSymbols
945
- info.advertiser = info.useLegacyAdvertiser ? "bonjour-hap" /* BONJOUR */ : "ciao" /* CIAO */;
940
+ info.advertiser = info.useLegacyAdvertiser ? "bonjour-hap" /* MDNSAdvertiser.BONJOUR */ : "ciao" /* MDNSAdvertiser.CIAO */;
946
941
  console.warn("DEPRECATED The PublishInfo.useLegacyAdvertiser option has been removed. " +
947
942
  "Please use the PublishInfo.advertiser property to enable \"ciao\" (useLegacyAdvertiser=false) " +
948
943
  "or \"bonjour-hap\" (useLegacyAdvertiser=true) mdns advertiser libraries!");
949
944
  }
950
945
  // noinspection JSDeprecatedSymbols
951
- if (info.mdns && info.advertiser !== "bonjour-hap" /* BONJOUR */) {
946
+ if (info.mdns && info.advertiser !== "bonjour-hap" /* MDNSAdvertiser.BONJOUR */) {
952
947
  console.log("DEPRECATED user supplied a custom 'mdns' option. This option is deprecated and ignored. " +
953
948
  "Please move to the new 'bind' option.");
954
949
  }
@@ -960,8 +955,8 @@ var Accessory = /** @class */ (function (_super) {
960
955
  if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
961
956
  Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
962
957
  }
963
- if (!this.initialized && ((_a = info.addIdentifyingMaterial) !== null && _a !== void 0 ? _a : true)) {
964
- // adding some identifying material to our displayName if its our first publish() call
958
+ if (!this.initialized && ((_b = info.addIdentifyingMaterial) !== null && _b !== void 0 ? _b : true)) {
959
+ // adding some identifying material to our displayName if it's our first publish() call
965
960
  this.displayName = this.displayName + " " + crypto_1.default.createHash("sha512")
966
961
  .update(info.username, "utf8")
967
962
  .digest("hex").slice(0, 4).toUpperCase();
@@ -987,20 +982,20 @@ var Accessory = /** @class */ (function (_super) {
987
982
  // make sure we have up-to-date values in AccessoryInfo, then save it in case they changed (or if we just created it)
988
983
  this._accessoryInfo.displayName = this.displayName;
989
984
  this._accessoryInfo.model = this.getService(Service_1.Service.AccessoryInformation).getCharacteristic(Characteristic_1.Characteristic.Model).value;
990
- this._accessoryInfo.category = info.category || 1 /* OTHER */;
985
+ this._accessoryInfo.category = info.category || 1 /* Categories.OTHER */;
991
986
  this._accessoryInfo.pincode = info.pincode;
992
987
  this._accessoryInfo.save();
993
- // create our IdentifierCache so we can provide clients with stable aid/iid's
988
+ // create our IdentifierCache, so we can provide clients with stable aid/iid's
994
989
  this._identifierCache = IdentifierCache_1.IdentifierCache.load(info.username);
995
990
  // if we don't have one, create a new one.
996
991
  if (!this._identifierCache) {
997
992
  debug("[%s] Creating new IdentifierCache", this.displayName);
998
993
  this._identifierCache = new IdentifierCache_1.IdentifierCache(info.username);
999
994
  }
1000
- //If it's bridge and there are not accessories already assigned to the bridge
1001
- //probably purge is not needed since it's going to delete all the ids
1002
- //of accessories that might be added later. Useful when dynamically adding
1003
- //accessories.
995
+ // If it's bridge and there are no accessories already assigned to the bridge
996
+ // probably purge is not needed since it's going to delete all the ids
997
+ // of accessories that might be added later. Useful when dynamically adding
998
+ // accessories.
1004
999
  if (this._isBridge && this.bridgedAccessories.length === 0) {
1005
1000
  this.disableUnusedIDPurge();
1006
1001
  this.controllerStorage.purgeUnidentifiedAccessoryData = false;
@@ -1016,33 +1011,33 @@ var Accessory = /** @class */ (function (_super) {
1016
1011
  this._accessoryInfo.checkForCurrentConfigurationNumberIncrement(config, true);
1017
1012
  this.validateAccessory(true);
1018
1013
  parsed = Accessory.parseBindOption(info);
1019
- selectedAdvertiser = (_b = info.advertiser) !== null && _b !== void 0 ? _b : "bonjour-hap" /* BONJOUR */;
1020
- _d = info.advertiser === "avahi" /* AVAHI */;
1021
- if (!_d) return [3 /*break*/, 2];
1014
+ selectedAdvertiser = (_c = info.advertiser) !== null && _c !== void 0 ? _c : "bonjour-hap" /* MDNSAdvertiser.BONJOUR */;
1015
+ _e = info.advertiser === "avahi" /* MDNSAdvertiser.AVAHI */;
1016
+ if (!_e) return [3 /*break*/, 2];
1022
1017
  return [4 /*yield*/, Advertiser_1.AvahiAdvertiser.isAvailable()];
1023
1018
  case 1:
1024
- _d = !(_f.sent());
1025
- _f.label = 2;
1019
+ _e = !(_g.sent());
1020
+ _g.label = 2;
1026
1021
  case 2:
1027
- _c = (_d);
1028
- if (_c) return [3 /*break*/, 5];
1029
- _e = info.advertiser === "resolved" /* RESOLVED */;
1030
- if (!_e) return [3 /*break*/, 4];
1022
+ _d = (_e);
1023
+ if (_d) return [3 /*break*/, 5];
1024
+ _f = info.advertiser === "resolved" /* MDNSAdvertiser.RESOLVED */;
1025
+ if (!_f) return [3 /*break*/, 4];
1031
1026
  return [4 /*yield*/, Advertiser_1.ResolvedAdvertiser.isAvailable()];
1032
1027
  case 3:
1033
- _e = !(_f.sent());
1034
- _f.label = 4;
1028
+ _f = !(_g.sent());
1029
+ _g.label = 4;
1035
1030
  case 4:
1036
- _c = (_e);
1037
- _f.label = 5;
1031
+ _d = (_f);
1032
+ _g.label = 5;
1038
1033
  case 5:
1039
- if (_c) {
1034
+ if (_d) {
1040
1035
  console.error("[".concat(this.displayName, "] The selected advertiser, \"").concat(info.advertiser, "\", isn't available on this platform. ") +
1041
- "Reverting to \"".concat("bonjour-hap" /* BONJOUR */, "\""));
1042
- selectedAdvertiser = "bonjour-hap" /* BONJOUR */;
1036
+ "Reverting to \"".concat("bonjour-hap" /* MDNSAdvertiser.BONJOUR */, "\""));
1037
+ selectedAdvertiser = "bonjour-hap" /* MDNSAdvertiser.BONJOUR */;
1043
1038
  }
1044
1039
  switch (selectedAdvertiser) {
1045
- case "ciao" /* CIAO */:
1040
+ case "ciao" /* MDNSAdvertiser.CIAO */:
1046
1041
  this._advertiser = new Advertiser_1.CiaoAdvertiser(this._accessoryInfo, {
1047
1042
  interface: parsed.advertiserAddress,
1048
1043
  }, {
@@ -1050,23 +1045,23 @@ var Accessory = /** @class */ (function (_super) {
1050
1045
  disabledIpv6: parsed.serviceDisableIpv6,
1051
1046
  });
1052
1047
  break;
1053
- case "bonjour-hap" /* BONJOUR */:
1048
+ case "bonjour-hap" /* MDNSAdvertiser.BONJOUR */:
1054
1049
  // noinspection JSDeprecatedSymbols
1055
1050
  this._advertiser = new Advertiser_1.BonjourHAPAdvertiser(this._accessoryInfo, info.mdns, {
1056
1051
  restrictedAddresses: parsed.serviceRestrictedAddress,
1057
1052
  disabledIpv6: parsed.serviceDisableIpv6,
1058
1053
  });
1059
1054
  break;
1060
- case "avahi" /* AVAHI */:
1055
+ case "avahi" /* MDNSAdvertiser.AVAHI */:
1061
1056
  this._advertiser = new Advertiser_1.AvahiAdvertiser(this._accessoryInfo);
1062
1057
  break;
1063
- case "resolved" /* RESOLVED */:
1058
+ case "resolved" /* MDNSAdvertiser.RESOLVED */:
1064
1059
  this._advertiser = new Advertiser_1.ResolvedAdvertiser(this._accessoryInfo);
1065
1060
  break;
1066
1061
  default:
1067
1062
  throw new Error("Unsupported advertiser setting: '" + info.advertiser + "'");
1068
1063
  }
1069
- this._advertiser.on("updated-name" /* UPDATED_NAME */, function (name) {
1064
+ this._advertiser.on("updated-name" /* AdvertiserEvent.UPDATED_NAME */, function (name) {
1070
1065
  _this.displayName = name;
1071
1066
  if (_this._accessoryInfo) {
1072
1067
  _this._accessoryInfo.displayName = name;
@@ -1079,17 +1074,17 @@ var Accessory = /** @class */ (function (_super) {
1079
1074
  // create our HAP server which handles all communication between iOS devices and us
1080
1075
  this._server = new HAPServer_1.HAPServer(this._accessoryInfo);
1081
1076
  this._server.allowInsecureRequest = !!allowInsecureRequest;
1082
- this._server.on("listening" /* LISTENING */, this.onListening.bind(this));
1083
- this._server.on("identify" /* IDENTIFY */, this.identificationRequest.bind(this, false));
1084
- this._server.on("pair" /* PAIR */, this.handleInitialPairSetupFinished.bind(this));
1085
- this._server.on("add-pairing" /* ADD_PAIRING */, this.handleAddPairing.bind(this));
1086
- this._server.on("remove-pairing" /* REMOVE_PAIRING */, this.handleRemovePairing.bind(this));
1087
- this._server.on("list-pairings" /* LIST_PAIRINGS */, this.handleListPairings.bind(this));
1088
- this._server.on("accessories" /* ACCESSORIES */, this.handleAccessories.bind(this));
1089
- this._server.on("get-characteristics" /* GET_CHARACTERISTICS */, this.handleGetCharacteristics.bind(this));
1090
- this._server.on("set-characteristics" /* SET_CHARACTERISTICS */, this.handleSetCharacteristics.bind(this));
1091
- this._server.on("connection-closed" /* CONNECTION_CLOSED */, this.handleHAPConnectionClosed.bind(this));
1092
- this._server.on("request-resource" /* REQUEST_RESOURCE */, this.handleResource.bind(this));
1077
+ this._server.on("listening" /* HAPServerEventTypes.LISTENING */, this.onListening.bind(this));
1078
+ this._server.on("identify" /* HAPServerEventTypes.IDENTIFY */, this.identificationRequest.bind(this, false));
1079
+ this._server.on("pair" /* HAPServerEventTypes.PAIR */, this.handleInitialPairSetupFinished.bind(this));
1080
+ this._server.on("add-pairing" /* HAPServerEventTypes.ADD_PAIRING */, this.handleAddPairing.bind(this));
1081
+ this._server.on("remove-pairing" /* HAPServerEventTypes.REMOVE_PAIRING */, this.handleRemovePairing.bind(this));
1082
+ this._server.on("list-pairings" /* HAPServerEventTypes.LIST_PAIRINGS */, this.handleListPairings.bind(this));
1083
+ this._server.on("accessories" /* HAPServerEventTypes.ACCESSORIES */, this.handleAccessories.bind(this));
1084
+ this._server.on("get-characteristics" /* HAPServerEventTypes.GET_CHARACTERISTICS */, this.handleGetCharacteristics.bind(this));
1085
+ this._server.on("set-characteristics" /* HAPServerEventTypes.SET_CHARACTERISTICS */, this.handleSetCharacteristics.bind(this));
1086
+ this._server.on("connection-closed" /* HAPServerEventTypes.CONNECTION_CLOSED */, this.handleHAPConnectionClosed.bind(this));
1087
+ this._server.on("request-resource" /* HAPServerEventTypes.REQUEST_RESOURCE */, this.handleResource.bind(this));
1093
1088
  this._server.listen(info.port, parsed.serverAddress);
1094
1089
  this.initialized = true;
1095
1090
  return [2 /*return*/];
@@ -1114,8 +1109,8 @@ var Accessory = /** @class */ (function (_super) {
1114
1109
  return promise;
1115
1110
  };
1116
1111
  Accessory.prototype.unpublish = function () {
1117
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
1118
- return (0, tslib_1.__generator)(this, function (_a) {
1112
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1113
+ return tslib_1.__generator(this, function (_a) {
1119
1114
  switch (_a.label) {
1120
1115
  case 0:
1121
1116
  if (this._server) {
@@ -1154,8 +1149,8 @@ var Accessory = /** @class */ (function (_super) {
1154
1149
  }
1155
1150
  }, 1000);
1156
1151
  this.configurationChangeDebounceTimeout.unref();
1157
- // 1d is fine, HomeKit is built that with configuration updates no iid or aid conflicts occur.
1158
- // Thus the only thing happening when the txt update arrives late is already removed accessories/services
1152
+ // 1s is fine, HomeKit is built that with configuration updates no iid or aid conflicts occur.
1153
+ // Thus, the only thing happening when the txt update arrives late is already removed accessories/services
1159
1154
  // not responding or new accessories/services not yet shown
1160
1155
  };
1161
1156
  Accessory.prototype.onListening = function (port, hostname) {
@@ -1164,32 +1159,32 @@ var Accessory = /** @class */ (function (_super) {
1164
1159
  // the HAP server is listening, so we can now start advertising our presence.
1165
1160
  this._advertiser.initPort(port);
1166
1161
  this._advertiser.startAdvertising()
1167
- .then(function () { return _this.emit("advertised" /* ADVERTISED */); })
1162
+ .then(function () { return _this.emit("advertised" /* AccessoryEventTypes.ADVERTISED */); })
1168
1163
  .catch(function (reason) { return console.error("Could not create mDNS advertisement. The HAP-Server won't be discoverable: " + reason); });
1169
- this.emit("listening" /* LISTENING */, port, hostname);
1164
+ this.emit("listening" /* AccessoryEventTypes.LISTENING */, port, hostname);
1170
1165
  };
1171
1166
  Accessory.prototype.handleInitialPairSetupFinished = function (username, publicKey, callback) {
1172
1167
  debug("[%s] Paired with client %s", this.displayName, username);
1173
- this._accessoryInfo && this._accessoryInfo.addPairedClient(username, publicKey, 1 /* ADMIN */);
1168
+ this._accessoryInfo && this._accessoryInfo.addPairedClient(username, publicKey, 1 /* PermissionTypes.ADMIN */);
1174
1169
  this._accessoryInfo && this._accessoryInfo.save();
1175
- // update our advertisement so it can pick up on the paired status of AccessoryInfo
1170
+ // update our advertisement, so it can pick up on the paired status of AccessoryInfo
1176
1171
  this._advertiser && this._advertiser.updateAdvertisement();
1177
1172
  callback();
1178
- this.emit("paired" /* PAIRED */);
1173
+ this.emit("paired" /* AccessoryEventTypes.PAIRED */);
1179
1174
  };
1180
1175
  Accessory.prototype.handleAddPairing = function (connection, username, publicKey, permission, callback) {
1181
1176
  if (!this._accessoryInfo) {
1182
- callback(6 /* UNAVAILABLE */);
1177
+ callback(6 /* TLVErrorCode.UNAVAILABLE */);
1183
1178
  return;
1184
1179
  }
1185
1180
  if (!this._accessoryInfo.hasAdminPermissions(connection.username)) {
1186
- callback(2 /* AUTHENTICATION */);
1181
+ callback(2 /* TLVErrorCode.AUTHENTICATION */);
1187
1182
  return;
1188
1183
  }
1189
1184
  var existingKey = this._accessoryInfo.getClientPublicKey(username);
1190
1185
  if (existingKey) {
1191
1186
  if (existingKey.toString() !== publicKey.toString()) {
1192
- callback(1 /* UNKNOWN */);
1187
+ callback(1 /* TLVErrorCode.UNKNOWN */);
1193
1188
  return;
1194
1189
  }
1195
1190
  this._accessoryInfo.updatePermission(username, permission);
@@ -1202,13 +1197,13 @@ var Accessory = /** @class */ (function (_super) {
1202
1197
  callback(0);
1203
1198
  };
1204
1199
  Accessory.prototype.handleRemovePairing = function (connection, username, callback) {
1205
- var e_14, _a;
1200
+ var e_12, _a;
1206
1201
  if (!this._accessoryInfo) {
1207
- callback(6 /* UNAVAILABLE */);
1202
+ callback(6 /* TLVErrorCode.UNAVAILABLE */);
1208
1203
  return;
1209
1204
  }
1210
1205
  if (!this._accessoryInfo.hasAdminPermissions(connection.username)) {
1211
- callback(2 /* AUTHENTICATION */);
1206
+ callback(2 /* TLVErrorCode.AUTHENTICATION */);
1212
1207
  return;
1213
1208
  }
1214
1209
  this._accessoryInfo.removePairedClient(connection, username);
@@ -1216,30 +1211,30 @@ var Accessory = /** @class */ (function (_super) {
1216
1211
  callback(0); // first of all ensure the pairing is removed before we advertise availability again
1217
1212
  if (!this._accessoryInfo.paired()) {
1218
1213
  this._advertiser && this._advertiser.updateAdvertisement();
1219
- this.emit("unpaired" /* UNPAIRED */);
1214
+ this.emit("unpaired" /* AccessoryEventTypes.UNPAIRED */);
1220
1215
  this.handleAccessoryUnpairedForControllers();
1221
1216
  try {
1222
- for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
1217
+ for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
1223
1218
  var accessory = _c.value;
1224
1219
  accessory.handleAccessoryUnpairedForControllers();
1225
1220
  }
1226
1221
  }
1227
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1222
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1228
1223
  finally {
1229
1224
  try {
1230
1225
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1231
1226
  }
1232
- finally { if (e_14) throw e_14.error; }
1227
+ finally { if (e_12) throw e_12.error; }
1233
1228
  }
1234
1229
  }
1235
1230
  };
1236
1231
  Accessory.prototype.handleListPairings = function (connection, callback) {
1237
1232
  if (!this._accessoryInfo) {
1238
- callback(6 /* UNAVAILABLE */);
1233
+ callback(6 /* TLVErrorCode.UNAVAILABLE */);
1239
1234
  return;
1240
1235
  }
1241
1236
  if (!this._accessoryInfo.hasAdminPermissions(connection.username)) {
1242
- callback(2 /* AUTHENTICATION */);
1237
+ callback(2 /* TLVErrorCode.AUTHENTICATION */);
1243
1238
  return;
1244
1239
  }
1245
1240
  callback(0, this._accessoryInfo.listPairings());
@@ -1248,7 +1243,7 @@ var Accessory = /** @class */ (function (_super) {
1248
1243
  var _this = this;
1249
1244
  this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
1250
1245
  var now = Date.now();
1251
- var contactGetHandlers = now - this.lastAccessoriesRequest > 5000; // we query latest value if last /accessories was more than 5s ago
1246
+ var contactGetHandlers = now - this.lastAccessoriesRequest > 5000; // we query the latest value if last /accessories was more than 5s ago
1252
1247
  this.lastAccessoriesRequest = now;
1253
1248
  this.toHAP(connection, contactGetHandlers).then(function (value) {
1254
1249
  callback(undefined, {
@@ -1256,86 +1251,86 @@ var Accessory = /** @class */ (function (_super) {
1256
1251
  });
1257
1252
  }, function (reason) {
1258
1253
  console.error("[" + _this.displayName + "] /accessories request error with: " + reason.stack);
1259
- callback({ httpCode: 500 /* INTERNAL_SERVER_ERROR */, status: -70402 /* SERVICE_COMMUNICATION_FAILURE */ });
1254
+ callback({ httpCode: 500 /* HAPHTTPCode.INTERNAL_SERVER_ERROR */, status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */ });
1260
1255
  });
1261
1256
  };
1262
1257
  Accessory.prototype.handleGetCharacteristics = function (connection, request, callback) {
1263
- var e_15, _a;
1258
+ var e_13, _a;
1264
1259
  var _this = this;
1265
1260
  var characteristics = [];
1266
1261
  var response = { characteristics: characteristics };
1267
1262
  var missingCharacteristics = new Set(request.ids.map(function (id) { return id.aid + "." + id.iid; }));
1268
1263
  if (missingCharacteristics.size !== request.ids.length) {
1269
1264
  // if those sizes differ, we have duplicates and can't properly handle that
1270
- callback({ httpCode: 422 /* UNPROCESSABLE_ENTITY */, status: -70410 /* INVALID_VALUE_IN_REQUEST */ });
1265
+ callback({ httpCode: 422 /* HAPHTTPCode.UNPROCESSABLE_ENTITY */, status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ });
1271
1266
  return;
1272
1267
  }
1273
1268
  var timeout = setTimeout(function () {
1274
- var e_16, _a;
1269
+ var e_14, _a;
1275
1270
  try {
1276
- for (var missingCharacteristics_1 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_1_1 = missingCharacteristics_1.next(); !missingCharacteristics_1_1.done; missingCharacteristics_1_1 = missingCharacteristics_1.next()) {
1271
+ for (var missingCharacteristics_1 = tslib_1.__values(missingCharacteristics), missingCharacteristics_1_1 = missingCharacteristics_1.next(); !missingCharacteristics_1_1.done; missingCharacteristics_1_1 = missingCharacteristics_1.next()) {
1277
1272
  var id = missingCharacteristics_1_1.value;
1278
1273
  var split = id.split(".");
1279
1274
  var aid = parseInt(split[0], 10);
1280
1275
  var iid = parseInt(split[1], 10);
1281
1276
  var accessory = _this.getAccessoryByAID(aid);
1282
1277
  var characteristic = accessory.getCharacteristicByIID(iid);
1283
- _this.sendCharacteristicWarning(characteristic, "slow-read" /* SLOW_READ */, "The read handler for the characteristic '" +
1278
+ _this.sendCharacteristicWarning(characteristic, "slow-read" /* CharacteristicWarningType.SLOW_READ */, "The read handler for the characteristic '" +
1284
1279
  characteristic.displayName + "' on the accessory '" + accessory.displayName + "' was slow to respond!");
1285
1280
  }
1286
1281
  }
1287
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
1282
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
1288
1283
  finally {
1289
1284
  try {
1290
1285
  if (missingCharacteristics_1_1 && !missingCharacteristics_1_1.done && (_a = missingCharacteristics_1.return)) _a.call(missingCharacteristics_1);
1291
1286
  }
1292
- finally { if (e_16) throw e_16.error; }
1287
+ finally { if (e_14) throw e_14.error; }
1293
1288
  }
1294
- // after a total of 10s we do not longer wait for a request to appear and just return status code timeout
1289
+ // after a total of 10s we do no longer wait for a request to appear and just return status code timeout
1295
1290
  timeout = setTimeout(function () {
1296
- var e_17, _a;
1291
+ var e_15, _a;
1297
1292
  timeout = undefined;
1298
1293
  try {
1299
- for (var missingCharacteristics_2 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_2_1 = missingCharacteristics_2.next(); !missingCharacteristics_2_1.done; missingCharacteristics_2_1 = missingCharacteristics_2.next()) {
1294
+ for (var missingCharacteristics_2 = tslib_1.__values(missingCharacteristics), missingCharacteristics_2_1 = missingCharacteristics_2.next(); !missingCharacteristics_2_1.done; missingCharacteristics_2_1 = missingCharacteristics_2.next()) {
1300
1295
  var id = missingCharacteristics_2_1.value;
1301
1296
  var split = id.split(".");
1302
1297
  var aid = parseInt(split[0], 10);
1303
1298
  var iid = parseInt(split[1], 10);
1304
1299
  var accessory = _this.getAccessoryByAID(aid);
1305
1300
  var characteristic = accessory.getCharacteristicByIID(iid);
1306
- _this.sendCharacteristicWarning(characteristic, "timeout-read" /* TIMEOUT_READ */, "The read handler for the characteristic '" +
1301
+ _this.sendCharacteristicWarning(characteristic, "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */, "The read handler for the characteristic '" +
1307
1302
  characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!. " +
1308
1303
  "Please check that you properly call the callback!");
1309
1304
  characteristics.push({
1310
1305
  aid: aid,
1311
1306
  iid: iid,
1312
- status: -70408 /* OPERATION_TIMED_OUT */,
1307
+ status: -70408 /* HAPStatus.OPERATION_TIMED_OUT */,
1313
1308
  });
1314
1309
  }
1315
1310
  }
1316
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1311
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1317
1312
  finally {
1318
1313
  try {
1319
1314
  if (missingCharacteristics_2_1 && !missingCharacteristics_2_1.done && (_a = missingCharacteristics_2.return)) _a.call(missingCharacteristics_2);
1320
1315
  }
1321
- finally { if (e_17) throw e_17.error; }
1316
+ finally { if (e_15) throw e_15.error; }
1322
1317
  }
1323
1318
  missingCharacteristics.clear();
1324
1319
  callback(undefined, response);
1325
- }, 6000);
1320
+ }, Accessory.TIMEOUT_AFTER_WARNING);
1326
1321
  timeout.unref();
1327
- }, 3000);
1322
+ }, Accessory.TIMEOUT_WARNING);
1328
1323
  timeout.unref();
1329
1324
  var _loop_1 = function (id) {
1330
1325
  var name = id.aid + "." + id.iid;
1331
1326
  this_1.handleCharacteristicRead(connection, id, request).then(function (value) {
1332
- return (0, tslib_1.__assign)({ aid: id.aid, iid: id.iid }, value);
1327
+ return tslib_1.__assign({ aid: id.aid, iid: id.iid }, value);
1333
1328
  }, function (reason) {
1334
1329
  console.error("[".concat(_this.displayName, "] Read request for characteristic ").concat(name, " encountered an error: ").concat(reason.stack));
1335
1330
  return {
1336
1331
  aid: id.aid,
1337
1332
  iid: id.iid,
1338
- status: -70402 /* SERVICE_COMMUNICATION_FAILURE */,
1333
+ status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */,
1339
1334
  };
1340
1335
  }).then(function (value) {
1341
1336
  if (!timeout) {
@@ -1354,41 +1349,40 @@ var Accessory = /** @class */ (function (_super) {
1354
1349
  };
1355
1350
  var this_1 = this;
1356
1351
  try {
1357
- for (var _b = (0, tslib_1.__values)(request.ids), _c = _b.next(); !_c.done; _c = _b.next()) {
1352
+ for (var _b = tslib_1.__values(request.ids), _c = _b.next(); !_c.done; _c = _b.next()) {
1358
1353
  var id = _c.value;
1359
1354
  _loop_1(id);
1360
1355
  }
1361
1356
  }
1362
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1357
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1363
1358
  finally {
1364
1359
  try {
1365
1360
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1366
1361
  }
1367
- finally { if (e_15) throw e_15.error; }
1362
+ finally { if (e_13) throw e_13.error; }
1368
1363
  }
1369
1364
  };
1370
1365
  Accessory.prototype.handleCharacteristicRead = function (connection, id, request) {
1371
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
1366
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1372
1367
  var characteristic, verifiable;
1373
1368
  var _this = this;
1374
- return (0, tslib_1.__generator)(this, function (_a) {
1369
+ return tslib_1.__generator(this, function (_a) {
1375
1370
  characteristic = this.findCharacteristic(id.aid, id.iid);
1376
1371
  if (!characteristic) {
1377
1372
  debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, id.aid, id.iid);
1378
- return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
1373
+ return [2 /*return*/, { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }];
1379
1374
  }
1380
- if (!characteristic.props.perms.includes("pr" /* PAIRED_READ */)) { // check if read is allowed for this characteristic
1375
+ if (!characteristic.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if read is allowed for this characteristic
1381
1376
  debug("[%s] Tried reading from characteristic which does not allow reading (aid of %s and iid of %s)", this.displayName, id.aid, id.iid);
1382
- return [2 /*return*/, { status: -70405 /* WRITE_ONLY_CHARACTERISTIC */ }];
1377
+ return [2 /*return*/, { status: -70405 /* HAPStatus.WRITE_ONLY_CHARACTERISTIC */ }];
1383
1378
  }
1384
- if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(0 /* READ */)) {
1385
- verifiable = true;
1386
- if (!connection.username || !this._accessoryInfo) {
1387
- verifiable = false;
1379
+ if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(0 /* Access.READ */)) {
1380
+ verifiable = this._accessoryInfo && connection.username;
1381
+ if (!verifiable) {
1388
1382
  debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for reading (aid of %s and iid of %s)", this.displayName, id.aid, id.iid);
1389
1383
  }
1390
1384
  if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1391
- return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
1385
+ return [2 /*return*/, { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }];
1392
1386
  }
1393
1387
  }
1394
1388
  return [2 /*return*/, characteristic.handleGetRequest(connection).then(function (value) {
@@ -1409,14 +1403,14 @@ var Accessory = /** @class */ (function (_super) {
1409
1403
  data.perms = characteristic.props.perms;
1410
1404
  }
1411
1405
  if (request.includeType) {
1412
- data.type = (0, uuid_1.toShortForm)(_this.UUID);
1406
+ data.type = (0, uuid_1.toShortForm)(characteristic.UUID);
1413
1407
  }
1414
1408
  if (request.includeEvent) {
1415
1409
  data.ev = connection.hasEventNotifications(id.aid, id.iid);
1416
1410
  }
1417
1411
  return data;
1418
1412
  }, function (reason) {
1419
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1413
+ // @ts-expect-error: preserveConstEnums compiler option
1420
1414
  debug("[%s] Error getting value for characteristic \"%s\": %s", _this.displayName, characteristic.displayName, HAPServer_1.HAPStatus[reason]);
1421
1415
  return { status: reason };
1422
1416
  })];
@@ -1424,20 +1418,20 @@ var Accessory = /** @class */ (function (_super) {
1424
1418
  });
1425
1419
  };
1426
1420
  Accessory.prototype.handleSetCharacteristics = function (connection, writeRequest, callback) {
1427
- var e_18, _a;
1421
+ var e_16, _a;
1428
1422
  var _this = this;
1429
1423
  debug("[%s] Processing characteristic set: %s", this.displayName, JSON.stringify(writeRequest));
1430
- var writeState = 0 /* REGULAR_REQUEST */;
1424
+ var writeState = 0 /* WriteRequestState.REGULAR_REQUEST */;
1431
1425
  if (writeRequest.pid !== undefined) { // check for timed writes
1432
1426
  if (connection.timedWritePid === writeRequest.pid) {
1433
- writeState = 1 /* TIMED_WRITE_AUTHENTICATED */;
1427
+ writeState = 1 /* WriteRequestState.TIMED_WRITE_AUTHENTICATED */;
1434
1428
  clearTimeout(connection.timedWriteTimeout);
1435
1429
  connection.timedWritePid = undefined;
1436
1430
  connection.timedWriteTimeout = undefined;
1437
1431
  debug("[%s] Timed write request got acknowledged for pid %d", this.displayName, writeRequest.pid);
1438
1432
  }
1439
1433
  else {
1440
- writeState = 2 /* TIMED_WRITE_REJECTED */;
1434
+ writeState = 2 /* WriteRequestState.TIMED_WRITE_REJECTED */;
1441
1435
  debug("[%s] TTL for timed write request has probably expired for pid %d", this.displayName, writeRequest.pid);
1442
1436
  }
1443
1437
  }
@@ -1447,75 +1441,75 @@ var Accessory = /** @class */ (function (_super) {
1447
1441
  .map(function (characteristic) { return characteristic.aid + "." + characteristic.iid; }));
1448
1442
  if (missingCharacteristics.size !== writeRequest.characteristics.length) {
1449
1443
  // if those sizes differ, we have duplicates and can't properly handle that
1450
- callback({ httpCode: 422 /* UNPROCESSABLE_ENTITY */, status: -70410 /* INVALID_VALUE_IN_REQUEST */ });
1444
+ callback({ httpCode: 422 /* HAPHTTPCode.UNPROCESSABLE_ENTITY */, status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ });
1451
1445
  return;
1452
1446
  }
1453
1447
  var timeout = setTimeout(function () {
1454
- var e_19, _a;
1448
+ var e_17, _a;
1455
1449
  try {
1456
- for (var missingCharacteristics_3 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_3_1 = missingCharacteristics_3.next(); !missingCharacteristics_3_1.done; missingCharacteristics_3_1 = missingCharacteristics_3.next()) {
1450
+ for (var missingCharacteristics_3 = tslib_1.__values(missingCharacteristics), missingCharacteristics_3_1 = missingCharacteristics_3.next(); !missingCharacteristics_3_1.done; missingCharacteristics_3_1 = missingCharacteristics_3.next()) {
1457
1451
  var id = missingCharacteristics_3_1.value;
1458
1452
  var split = id.split(".");
1459
1453
  var aid = parseInt(split[0], 10);
1460
1454
  var iid = parseInt(split[1], 10);
1461
1455
  var accessory = _this.getAccessoryByAID(aid);
1462
1456
  var characteristic = accessory.getCharacteristicByIID(iid);
1463
- _this.sendCharacteristicWarning(characteristic, "slow-write" /* SLOW_WRITE */, "The write handler for the characteristic '" +
1457
+ _this.sendCharacteristicWarning(characteristic, "slow-write" /* CharacteristicWarningType.SLOW_WRITE */, "The write handler for the characteristic '" +
1464
1458
  characteristic.displayName + "' on the accessory '" + accessory.displayName + "' was slow to respond!");
1465
1459
  }
1466
1460
  }
1467
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1461
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1468
1462
  finally {
1469
1463
  try {
1470
1464
  if (missingCharacteristics_3_1 && !missingCharacteristics_3_1.done && (_a = missingCharacteristics_3.return)) _a.call(missingCharacteristics_3);
1471
1465
  }
1472
- finally { if (e_19) throw e_19.error; }
1466
+ finally { if (e_17) throw e_17.error; }
1473
1467
  }
1474
- // after a total of 10s we do not longer wait for a request to appear and just return status code timeout
1468
+ // after a total of 10s we do no longer wait for a request to appear and just return status code timeout
1475
1469
  timeout = setTimeout(function () {
1476
- var e_20, _a;
1470
+ var e_18, _a;
1477
1471
  timeout = undefined;
1478
1472
  try {
1479
- for (var missingCharacteristics_4 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_4_1 = missingCharacteristics_4.next(); !missingCharacteristics_4_1.done; missingCharacteristics_4_1 = missingCharacteristics_4.next()) {
1473
+ for (var missingCharacteristics_4 = tslib_1.__values(missingCharacteristics), missingCharacteristics_4_1 = missingCharacteristics_4.next(); !missingCharacteristics_4_1.done; missingCharacteristics_4_1 = missingCharacteristics_4.next()) {
1480
1474
  var id = missingCharacteristics_4_1.value;
1481
1475
  var split = id.split(".");
1482
1476
  var aid = parseInt(split[0], 10);
1483
1477
  var iid = parseInt(split[1], 10);
1484
1478
  var accessory = _this.getAccessoryByAID(aid);
1485
1479
  var characteristic = accessory.getCharacteristicByIID(iid);
1486
- _this.sendCharacteristicWarning(characteristic, "timeout-write" /* TIMEOUT_WRITE */, "The write handler for the characteristic '" +
1480
+ _this.sendCharacteristicWarning(characteristic, "timeout-write" /* CharacteristicWarningType.TIMEOUT_WRITE */, "The write handler for the characteristic '" +
1487
1481
  characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!. " +
1488
1482
  "Please check that you properly call the callback!");
1489
1483
  characteristics.push({
1490
1484
  aid: aid,
1491
1485
  iid: iid,
1492
- status: -70408 /* OPERATION_TIMED_OUT */,
1486
+ status: -70408 /* HAPStatus.OPERATION_TIMED_OUT */,
1493
1487
  });
1494
1488
  }
1495
1489
  }
1496
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1490
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1497
1491
  finally {
1498
1492
  try {
1499
1493
  if (missingCharacteristics_4_1 && !missingCharacteristics_4_1.done && (_a = missingCharacteristics_4.return)) _a.call(missingCharacteristics_4);
1500
1494
  }
1501
- finally { if (e_20) throw e_20.error; }
1495
+ finally { if (e_18) throw e_18.error; }
1502
1496
  }
1503
1497
  missingCharacteristics.clear();
1504
1498
  callback(undefined, response);
1505
- }, 6000);
1499
+ }, Accessory.TIMEOUT_AFTER_WARNING);
1506
1500
  timeout.unref();
1507
- }, 3000);
1501
+ }, Accessory.TIMEOUT_WARNING);
1508
1502
  timeout.unref();
1509
1503
  var _loop_2 = function (data) {
1510
1504
  var name = data.aid + "." + data.iid;
1511
1505
  this_2.handleCharacteristicWrite(connection, data, writeState).then(function (value) {
1512
- return (0, tslib_1.__assign)({ aid: data.aid, iid: data.iid }, value);
1506
+ return tslib_1.__assign({ aid: data.aid, iid: data.iid }, value);
1513
1507
  }, function (reason) {
1514
1508
  console.error("[".concat(_this.displayName, "] Write request for characteristic ").concat(name, " encountered an error: ").concat(reason.stack));
1515
1509
  return {
1516
1510
  aid: data.aid,
1517
1511
  iid: data.iid,
1518
- status: -70402 /* SERVICE_COMMUNICATION_FAILURE */,
1512
+ status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */,
1519
1513
  };
1520
1514
  }).then(function (value) {
1521
1515
  if (!timeout) {
@@ -1534,84 +1528,77 @@ var Accessory = /** @class */ (function (_super) {
1534
1528
  };
1535
1529
  var this_2 = this;
1536
1530
  try {
1537
- for (var _b = (0, tslib_1.__values)(writeRequest.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
1531
+ for (var _b = tslib_1.__values(writeRequest.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
1538
1532
  var data = _c.value;
1539
1533
  _loop_2(data);
1540
1534
  }
1541
1535
  }
1542
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1536
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
1543
1537
  finally {
1544
1538
  try {
1545
1539
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1546
1540
  }
1547
- finally { if (e_18) throw e_18.error; }
1541
+ finally { if (e_16) throw e_16.error; }
1548
1542
  }
1549
1543
  };
1550
1544
  Accessory.prototype.handleCharacteristicWrite = function (connection, data, writeState) {
1551
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
1552
- var characteristic, evResponse, notificationsEnabled, verifiable, verifiable, allowWrite;
1545
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1546
+ var characteristic, verifiable, notificationsEnabled, verifiable, allowWrite;
1553
1547
  var _this = this;
1554
- return (0, tslib_1.__generator)(this, function (_a) {
1548
+ return tslib_1.__generator(this, function (_a) {
1555
1549
  characteristic = this.findCharacteristic(data.aid, data.iid);
1556
- evResponse = undefined;
1557
1550
  if (!characteristic) {
1558
1551
  debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, data.aid, data.iid);
1559
- return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
1552
+ return [2 /*return*/, { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }];
1553
+ }
1554
+ if (writeState === 2 /* WriteRequestState.TIMED_WRITE_REJECTED */) {
1555
+ return [2 /*return*/, { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }];
1560
1556
  }
1561
- if (writeState === 2 /* TIMED_WRITE_REJECTED */) {
1562
- return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
1557
+ if (data.ev == null && data.value == null) {
1558
+ return [2 /*return*/, { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }];
1563
1559
  }
1564
1560
  if (data.ev != null) { // register/unregister event notifications
1565
- notificationsEnabled = connection.hasEventNotifications(data.aid, data.iid);
1566
- // it seems like the Home App sends unregister requests for characteristics which don't have notify permissions
1567
- // see https://github.com/homebridge/HAP-NodeJS/issues/868
1568
- if (notificationsEnabled !== data.ev) {
1569
- if (!characteristic.props.perms.includes("ev" /* NOTIFY */)) { // check if notify is allowed for this characteristic
1570
- debug("[%s] Tried %s notifications for Characteristic which does not allow notify (aid of %s and iid of %s)", this.displayName, data.ev ? "enabling" : "disabling", data.aid, data.iid);
1571
- return [2 /*return*/, { status: -70406 /* NOTIFICATION_NOT_SUPPORTED */ }];
1572
- }
1573
- if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* NOTIFY */)) {
1574
- verifiable = true;
1575
- if (!connection.username || !this._accessoryInfo) {
1576
- verifiable = false;
1577
- debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for notify (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
1578
- }
1579
- if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1580
- return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
1581
- }
1582
- }
1583
- // we already checked that data.ev != notificationsEnabled, thus just do whatever the connection asks for
1584
- if (data.ev) {
1585
- connection.enableEventNotifications(data.aid, data.iid);
1586
- characteristic.subscribe();
1587
- evResponse = true;
1588
- debug("[%s] Registered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
1561
+ if (!characteristic.props.perms.includes("ev" /* Perms.NOTIFY */)) { // check if notify is allowed for this characteristic
1562
+ debug("[%s] Tried %s notifications for Characteristic which does not allow notify (aid of %s and iid of %s)", this.displayName, data.ev ? "enabling" : "disabling", data.aid, data.iid);
1563
+ return [2 /*return*/, { status: -70406 /* HAPStatus.NOTIFICATION_NOT_SUPPORTED */ }];
1564
+ }
1565
+ if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* Access.NOTIFY */)) {
1566
+ verifiable = connection.username && this._accessoryInfo;
1567
+ if (!verifiable) {
1568
+ debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for notify (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
1589
1569
  }
1590
- else {
1591
- characteristic.unsubscribe();
1592
- connection.disableEventNotifications(data.aid, data.iid);
1593
- evResponse = false;
1594
- debug("[%s] Unregistered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
1570
+ if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1571
+ return [2 /*return*/, { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }];
1595
1572
  }
1596
1573
  }
1574
+ notificationsEnabled = connection.hasEventNotifications(data.aid, data.iid);
1575
+ if (data.ev && !notificationsEnabled) {
1576
+ connection.enableEventNotifications(data.aid, data.iid);
1577
+ characteristic.subscribe();
1578
+ debug("[%s] Registered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
1579
+ }
1580
+ else if (!data.ev && notificationsEnabled) {
1581
+ characteristic.unsubscribe();
1582
+ connection.disableEventNotifications(data.aid, data.iid);
1583
+ debug("[%s] Unregistered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
1584
+ }
1597
1585
  // response is returned below in the else block
1598
1586
  }
1599
1587
  if (data.value != null) {
1600
- if (!characteristic.props.perms.includes("pw" /* PAIRED_WRITE */)) { // check if write is allowed for this characteristic
1588
+ if (!characteristic.props.perms.includes("pw" /* Perms.PAIRED_WRITE */)) { // check if write is allowed for this characteristic
1601
1589
  debug("[%s] Tried writing to Characteristic which does not allow writing (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
1602
- return [2 /*return*/, { status: -70404 /* READ_ONLY_CHARACTERISTIC */ }];
1590
+ return [2 /*return*/, { status: -70404 /* HAPStatus.READ_ONLY_CHARACTERISTIC */ }];
1603
1591
  }
1604
- if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(1 /* WRITE */)) {
1605
- verifiable = true;
1606
- if (!connection.username || !this._accessoryInfo) {
1607
- verifiable = false;
1592
+ if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(1 /* Access.WRITE */)) {
1593
+ verifiable = connection.username && this._accessoryInfo;
1594
+ if (!verifiable) {
1608
1595
  debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for write (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
1609
1596
  }
1610
1597
  if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1611
- return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
1598
+ return [2 /*return*/, { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ }];
1612
1599
  }
1613
1600
  }
1614
- if (characteristic.props.perms.includes("aa" /* ADDITIONAL_AUTHORIZATION */) && characteristic.additionalAuthorizationHandler) {
1601
+ if (characteristic.props.perms.includes("aa" /* Perms.ADDITIONAL_AUTHORIZATION */) && characteristic.additionalAuthorizationHandler) {
1615
1602
  allowWrite = void 0;
1616
1603
  try {
1617
1604
  allowWrite = characteristic.additionalAuthorizationHandler(data.authData);
@@ -1621,19 +1608,19 @@ var Accessory = /** @class */ (function (_super) {
1621
1608
  allowWrite = false;
1622
1609
  }
1623
1610
  if (!allowWrite) {
1624
- return [2 /*return*/, { status: -70411 /* INSUFFICIENT_AUTHORIZATION */ }];
1611
+ return [2 /*return*/, { status: -70411 /* HAPStatus.INSUFFICIENT_AUTHORIZATION */ }];
1625
1612
  }
1626
1613
  }
1627
- if (characteristic.props.perms.includes("tw" /* TIMED_WRITE */) && writeState !== 1 /* TIMED_WRITE_AUTHENTICATED */) {
1614
+ if (characteristic.props.perms.includes("tw" /* Perms.TIMED_WRITE */) && writeState !== 1 /* WriteRequestState.TIMED_WRITE_AUTHENTICATED */) {
1628
1615
  debug("[%s] Tried writing to a timed write only Characteristic without properly preparing (iid of %s and aid of %s)", this.displayName, data.aid, data.iid);
1629
- return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
1616
+ return [2 /*return*/, { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ }];
1630
1617
  }
1631
1618
  return [2 /*return*/, characteristic.handleSetRequest(data.value, connection).then(function (value) {
1632
1619
  debug("[%s] Setting Characteristic \"%s\" to value %s", _this.displayName, characteristic.displayName, data.value);
1633
1620
  return {
1634
1621
  // if write response is requests and value is provided, return that
1635
1622
  value: data.r && value ? (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props) : undefined,
1636
- ev: evResponse,
1623
+ status: 0 /* HAPStatus.SUCCESS */,
1637
1624
  };
1638
1625
  }, function (status) {
1639
1626
  // @ts-expect-error: forceConsistentCasingInFileNames compiler option
@@ -1641,16 +1628,13 @@ var Accessory = /** @class */ (function (_super) {
1641
1628
  return { status: status };
1642
1629
  })];
1643
1630
  }
1644
- else {
1645
- return [2 /*return*/, { ev: evResponse }];
1646
- }
1647
- return [2 /*return*/];
1631
+ return [2 /*return*/, { status: 0 /* HAPStatus.SUCCESS */ }];
1648
1632
  });
1649
1633
  });
1650
1634
  };
1651
1635
  Accessory.prototype.handleResource = function (data, callback) {
1652
1636
  var _a;
1653
- if (data["resource-type"] === "image" /* IMAGE */) {
1637
+ if (data["resource-type"] === "image" /* ResourceRequestType.IMAGE */) {
1654
1638
  var aid = data.aid; // aid is optionally supplied by HomeKit (for example when camera is bridged, multiple cams, etc)
1655
1639
  var accessory = undefined;
1656
1640
  var controller = undefined;
@@ -1667,27 +1651,27 @@ var Accessory = /** @class */ (function (_super) {
1667
1651
  }
1668
1652
  if (!controller) {
1669
1653
  debug("[%s] received snapshot request though no camera controller was associated!");
1670
- callback({ httpCode: 404 /* NOT_FOUND */, status: -70409 /* RESOURCE_DOES_NOT_EXIST */ });
1654
+ callback({ httpCode: 404 /* HAPHTTPCode.NOT_FOUND */, status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ });
1671
1655
  return;
1672
1656
  }
1673
1657
  controller.handleSnapshotRequest(data["image-height"], data["image-width"], accessory === null || accessory === void 0 ? void 0 : accessory.displayName, data.reason)
1674
1658
  .then(function (buffer) {
1675
1659
  callback(undefined, buffer);
1676
1660
  }, function (status) {
1677
- callback({ httpCode: 207 /* MULTI_STATUS */, status: status });
1661
+ callback({ httpCode: 207 /* HAPHTTPCode.MULTI_STATUS */, status: status });
1678
1662
  });
1679
1663
  return;
1680
1664
  }
1681
1665
  debug("[%s] received request for unsupported image type: " + data["resource-type"], (_a = this._accessoryInfo) === null || _a === void 0 ? void 0 : _a.username);
1682
- callback({ httpCode: 404 /* NOT_FOUND */, status: -70409 /* RESOURCE_DOES_NOT_EXIST */ });
1666
+ callback({ httpCode: 404 /* HAPHTTPCode.NOT_FOUND */, status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ });
1683
1667
  };
1684
1668
  Accessory.prototype.handleHAPConnectionClosed = function (connection) {
1685
- var e_21, _a;
1669
+ var e_19, _a;
1686
1670
  if (this.activeCameraController) {
1687
1671
  this.activeCameraController.handleCloseConnection(connection.sessionID);
1688
1672
  }
1689
1673
  try {
1690
- for (var _b = (0, tslib_1.__values)(connection.getRegisteredEvents()), _c = _b.next(); !_c.done; _c = _b.next()) {
1674
+ for (var _b = tslib_1.__values(connection.getRegisteredEvents()), _c = _b.next(); !_c.done; _c = _b.next()) {
1691
1675
  var event = _c.value;
1692
1676
  var ids = event.split(".");
1693
1677
  var aid = parseInt(ids[0], 10);
@@ -1698,29 +1682,29 @@ var Accessory = /** @class */ (function (_super) {
1698
1682
  }
1699
1683
  }
1700
1684
  }
1701
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1685
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1702
1686
  finally {
1703
1687
  try {
1704
1688
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1705
1689
  }
1706
- finally { if (e_21) throw e_21.error; }
1690
+ finally { if (e_19) throw e_19.error; }
1707
1691
  }
1708
1692
  connection.clearRegisteredEvents();
1709
1693
  };
1710
1694
  Accessory.prototype.handleServiceConfigurationChangeEvent = function (service) {
1711
1695
  if (!service.isPrimaryService && service === this.primaryService) {
1712
- // service changed form primary to non primary service
1696
+ // service changed form primary to non-primary service
1713
1697
  this.primaryService = undefined;
1714
1698
  }
1715
1699
  else if (service.isPrimaryService && service !== this.primaryService) {
1716
- // service changed from non primary to primary service
1700
+ // service changed from non-primary to primary service
1717
1701
  if (this.primaryService !== undefined) {
1718
1702
  this.primaryService.isPrimaryService = false;
1719
1703
  }
1720
1704
  this.primaryService = service;
1721
1705
  }
1722
1706
  if (this.bridged) {
1723
- this.emit("service-configurationChange" /* SERVICE_CONFIGURATION_CHANGE */, { service: service });
1707
+ this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service: service });
1724
1708
  }
1725
1709
  else {
1726
1710
  this.enqueueConfigurationUpdate();
@@ -1728,7 +1712,7 @@ var Accessory = /** @class */ (function (_super) {
1728
1712
  };
1729
1713
  Accessory.prototype.handleCharacteristicChangeEvent = function (accessory, service, change) {
1730
1714
  if (this.bridged) { // forward this to our main accessory
1731
- this.emit("service-characteristic-change" /* SERVICE_CHARACTERISTIC_CHANGE */, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, change), { service: service }));
1715
+ this.emit("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, tslib_1.__assign(tslib_1.__assign({}, change), { service: service }));
1732
1716
  }
1733
1717
  else {
1734
1718
  if (!this._server) {
@@ -1742,7 +1726,7 @@ var Accessory = /** @class */ (function (_super) {
1742
1726
  debug("[%s] Omitting event updates for %s as specified in the context object!", accessory.displayName, change.characteristic.displayName);
1743
1727
  return;
1744
1728
  }
1745
- if (!(change.reason === "event" /* EVENT */ || change.oldValue !== change.newValue
1729
+ if (!(change.reason === "event" /* ChangeReason.EVENT */ || change.oldValue !== change.newValue
1746
1730
  || change.characteristic.UUID === Characteristic_1.Characteristic.ProgrammableSwitchEvent.UUID // those specific checks are out of backwards compatibility
1747
1731
  || change.characteristic.UUID === Characteristic_1.Characteristic.ButtonEvent.UUID // new characteristics should use sendEventNotification call
1748
1732
  )) {
@@ -1769,12 +1753,12 @@ var Accessory = /** @class */ (function (_super) {
1769
1753
  };
1770
1754
  Accessory.prototype.handleCharacteristicWarning = function (warning) {
1771
1755
  var _a;
1772
- warning.originatorChain = (0, tslib_1.__spreadArray)([this.displayName], (0, tslib_1.__read)(warning.originatorChain), false);
1773
- var emitted = this.emit("characteristic-warning" /* CHARACTERISTIC_WARNING */, warning);
1756
+ warning.originatorChain = tslib_1.__spreadArray([this.displayName], tslib_1.__read(warning.originatorChain), false);
1757
+ var emitted = this.emit("characteristic-warning" /* AccessoryEventTypes.CHARACTERISTIC_WARNING */, warning);
1774
1758
  if (!emitted) {
1775
1759
  var message = "[".concat(warning.originatorChain.join("@"), "] ").concat(warning.message);
1776
- if (warning.type === "error-message" /* ERROR_MESSAGE */
1777
- || warning.type === "timeout-read" /* TIMEOUT_READ */ || warning.type === "timeout-write" /* TIMEOUT_WRITE */) {
1760
+ if (warning.type === "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */
1761
+ || warning.type === "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */ || warning.type === "timeout-write" /* CharacteristicWarningType.TIMEOUT_WRITE */) {
1778
1762
  console.error(message);
1779
1763
  }
1780
1764
  else {
@@ -1784,32 +1768,32 @@ var Accessory = /** @class */ (function (_super) {
1784
1768
  }
1785
1769
  };
1786
1770
  Accessory.prototype.setupServiceEventHandlers = function (service) {
1787
- service.on("service-configurationChange" /* SERVICE_CONFIGURATION_CHANGE */, this.handleServiceConfigurationChangeEvent.bind(this, service));
1788
- service.on("characteristic-change" /* CHARACTERISTIC_CHANGE */, this.handleCharacteristicChangeEvent.bind(this, this, service));
1789
- service.on("characteristic-warning" /* CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
1771
+ service.on("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */, this.handleServiceConfigurationChangeEvent.bind(this, service));
1772
+ service.on("characteristic-change" /* ServiceEventTypes.CHARACTERISTIC_CHANGE */, this.handleCharacteristicChangeEvent.bind(this, this, service));
1773
+ service.on("characteristic-warning" /* ServiceEventTypes.CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
1790
1774
  };
1791
1775
  Accessory.prototype._sideloadServices = function (targetServices) {
1792
- var e_22, _a;
1776
+ var e_20, _a;
1793
1777
  var _this = this;
1794
1778
  try {
1795
- for (var targetServices_1 = (0, tslib_1.__values)(targetServices), targetServices_1_1 = targetServices_1.next(); !targetServices_1_1.done; targetServices_1_1 = targetServices_1.next()) {
1779
+ for (var targetServices_1 = tslib_1.__values(targetServices), targetServices_1_1 = targetServices_1.next(); !targetServices_1_1.done; targetServices_1_1 = targetServices_1.next()) {
1796
1780
  var service = targetServices_1_1.value;
1797
1781
  this.setupServiceEventHandlers(service);
1798
1782
  }
1799
1783
  }
1800
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
1784
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
1801
1785
  finally {
1802
1786
  try {
1803
1787
  if (targetServices_1_1 && !targetServices_1_1.done && (_a = targetServices_1.return)) _a.call(targetServices_1);
1804
1788
  }
1805
- finally { if (e_22) throw e_22.error; }
1789
+ finally { if (e_20) throw e_20.error; }
1806
1790
  }
1807
1791
  this.services = targetServices.slice();
1808
1792
  // Fix Identify
1809
1793
  this
1810
1794
  .getService(Service_1.Service.AccessoryInformation)
1811
1795
  .getCharacteristic(Characteristic_1.Characteristic.Identify)
1812
- .on("set" /* SET */, function (value, callback) {
1796
+ .on("set" /* CharacteristicEventTypes.SET */, function (value, callback) {
1813
1797
  if (value) {
1814
1798
  var paired = true;
1815
1799
  _this.identificationRequest(paired, callback);
@@ -1861,7 +1845,7 @@ var Accessory = /** @class */ (function (_super) {
1861
1845
  });
1862
1846
  // also save controller which didn't get initialized (could lead to service duplication if we throw that data away)
1863
1847
  accessory.serializedControllers && Object.entries(accessory.serializedControllers).forEach(function (_a) {
1864
- var _b = (0, tslib_1.__read)(_a, 2), id = _b[0], serviceMap = _b[1];
1848
+ var _b = tslib_1.__read(_a, 2), id = _b[0], serviceMap = _b[1];
1865
1849
  controllers.push({
1866
1850
  type: id,
1867
1851
  services: Accessory.serializeServiceMap(serviceMap),
@@ -1873,7 +1857,7 @@ var Accessory = /** @class */ (function (_super) {
1873
1857
  return json;
1874
1858
  };
1875
1859
  Accessory.deserialize = function (json) {
1876
- var e_23, _a;
1860
+ var e_21, _a;
1877
1861
  var accessory = new Accessory(json.displayName, json.UUID);
1878
1862
  accessory.lastKnownUsername = json.lastKnownUsername;
1879
1863
  accessory.category = json.category;
@@ -1898,17 +1882,17 @@ var Accessory = /** @class */ (function (_super) {
1898
1882
  });
1899
1883
  };
1900
1884
  try {
1901
- for (var _b = (0, tslib_1.__values)(Object.entries(json.linkedServices)), _c = _b.next(); !_c.done; _c = _b.next()) {
1902
- var _d = (0, tslib_1.__read)(_c.value, 2), serviceId = _d[0], linkedServicesKeys = _d[1];
1885
+ for (var _b = tslib_1.__values(Object.entries(json.linkedServices)), _c = _b.next(); !_c.done; _c = _b.next()) {
1886
+ var _d = tslib_1.__read(_c.value, 2), serviceId = _d[0], linkedServicesKeys = _d[1];
1903
1887
  _loop_3(serviceId, linkedServicesKeys);
1904
1888
  }
1905
1889
  }
1906
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
1890
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
1907
1891
  finally {
1908
1892
  try {
1909
1893
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1910
1894
  }
1911
- finally { if (e_23) throw e_23.error; }
1895
+ finally { if (e_21) throw e_21.error; }
1912
1896
  }
1913
1897
  }
1914
1898
  if (json.controllers) { // just save it for later if it exists {@see configureController}
@@ -1928,7 +1912,7 @@ var Accessory = /** @class */ (function (_super) {
1928
1912
  Accessory.serializeServiceMap = function (serviceMap) {
1929
1913
  var serialized = {};
1930
1914
  Object.entries(serviceMap).forEach(function (_a) {
1931
- var _b = (0, tslib_1.__read)(_a, 2), name = _b[0], service = _b[1];
1915
+ var _b = tslib_1.__read(_a, 2), name = _b[0], service = _b[1];
1932
1916
  if (!service) {
1933
1917
  return;
1934
1918
  }
@@ -1939,7 +1923,7 @@ var Accessory = /** @class */ (function (_super) {
1939
1923
  Accessory.deserializeServiceMap = function (serializedServiceMap, servicesMap) {
1940
1924
  var controllerServiceMap = {};
1941
1925
  Object.entries(serializedServiceMap).forEach(function (_a) {
1942
- var _b = (0, tslib_1.__read)(_a, 2), name = _b[0], serviceId = _b[1];
1926
+ var _b = tslib_1.__read(_a, 2), name = _b[0], serviceId = _b[1];
1943
1927
  var service = servicesMap[serviceId];
1944
1928
  if (service) {
1945
1929
  controllerServiceMap[name] = service;
@@ -1948,9 +1932,9 @@ var Accessory = /** @class */ (function (_super) {
1948
1932
  return controllerServiceMap;
1949
1933
  };
1950
1934
  Accessory.parseBindOption = function (info) {
1951
- var e_24, _a;
1935
+ var e_22, _a;
1952
1936
  var advertiserAddress = undefined;
1953
- var disableIpv6 = false;
1937
+ var disableIpv6 = undefined;
1954
1938
  var serverAddress = undefined;
1955
1939
  if (info.bind) {
1956
1940
  var entries = new Set(Array.isArray(info.bind) ? info.bind : [info.bind]);
@@ -1972,7 +1956,7 @@ var Accessory = /** @class */ (function (_super) {
1972
1956
  else if (entries.size === 1) {
1973
1957
  advertiserAddress = Array.from(entries);
1974
1958
  var entry = entries.values().next().value; // grab the first one
1975
- var version = net_1.default.isIP(entry); // check if ip address was specified or a interface name
1959
+ var version = net_1.default.isIP(entry); // check if ip address was specified or an interface name
1976
1960
  if (version) {
1977
1961
  serverAddress = version === 4 ? "0.0.0.0" : "::"; // we currently bind to unspecified addresses so config-ui always has a connection via loopback
1978
1962
  }
@@ -1984,7 +1968,7 @@ var Accessory = /** @class */ (function (_super) {
1984
1968
  advertiserAddress = Array.from(entries);
1985
1969
  var bindUnspecifiedIpv6 = false; // we bind on "::" if there are interface names, or we detect ipv6 addresses
1986
1970
  try {
1987
- for (var entries_1 = (0, tslib_1.__values)(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
1971
+ for (var entries_1 = tslib_1.__values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
1988
1972
  var entry = entries_1_1.value;
1989
1973
  var version = net_1.default.isIP(entry);
1990
1974
  if (version === 0 || version === 6) {
@@ -1993,12 +1977,12 @@ var Accessory = /** @class */ (function (_super) {
1993
1977
  }
1994
1978
  }
1995
1979
  }
1996
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
1980
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
1997
1981
  finally {
1998
1982
  try {
1999
1983
  if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
2000
1984
  }
2001
- finally { if (e_24) throw e_24.error; }
1985
+ finally { if (e_22) throw e_22.error; }
2002
1986
  }
2003
1987
  if (bindUnspecifiedIpv6) {
2004
1988
  serverAddress = "::";
@@ -2020,6 +2004,10 @@ var Accessory = /** @class */ (function (_super) {
2020
2004
  */
2021
2005
  // @ts-expect-error: forceConsistentCasingInFileNames compiler option
2022
2006
  Accessory.Categories = Categories;
2007
+ /// Timeout in milliseconds until a characteristic warning is issue
2008
+ Accessory.TIMEOUT_WARNING = 3000;
2009
+ /// Timeout in milliseconds after `TIMEOUT_WARNING` until the operation on the characteristic is considered timed out.
2010
+ Accessory.TIMEOUT_AFTER_WARNING = 6000;
2023
2011
  return Accessory;
2024
2012
  }(events_1.EventEmitter));
2025
2013
  exports.Accessory = Accessory;