matter-all-in-one-addon 2.3.1 → 2.3.13

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 (457) hide show
  1. package/README.md +16 -8
  2. package/dist/camera/ai/camera-ai-detector.d.ts +0 -2
  3. package/dist/camera/ai/camera-ai-detector.js +52 -57
  4. package/dist/camera/ai/camera-ai-detector.js.map +1 -1
  5. package/dist/camera/browser-preview.d.ts +9 -0
  6. package/dist/camera/browser-preview.js +135 -0
  7. package/dist/camera/browser-preview.js.map +1 -0
  8. package/dist/camera/camera-source-resolver.js +5 -3
  9. package/dist/camera/camera-source-resolver.js.map +1 -1
  10. package/dist/camera/camera-types.d.ts +0 -2
  11. package/dist/camera/cameraui/cameraui-client.js +91 -30
  12. package/dist/camera/cameraui/cameraui-client.js.map +1 -1
  13. package/dist/camera/cameraui/cameraui-homekit-bridge.js +13 -4
  14. package/dist/camera/cameraui/cameraui-homekit-bridge.js.map +1 -1
  15. package/dist/camera/cameraui/cameraui-storage.js.map +1 -1
  16. package/dist/camera/cameraui/cameraui-types.d.ts +6 -2
  17. package/dist/camera/cameraui/ha-camera-entity.js +5 -2
  18. package/dist/camera/cameraui/ha-camera-entity.js.map +1 -1
  19. package/dist/camera/homekit/ffmpeg-helper.js +17 -35
  20. package/dist/camera/homekit/ffmpeg-helper.js.map +1 -1
  21. package/dist/camera/homekit/hevc/fmp4-hevc.js +3 -1
  22. package/dist/camera/homekit/hevc/fmp4-hevc.js.map +1 -1
  23. package/dist/camera/homekit/hevc/hevc-recording.d.ts +0 -2
  24. package/dist/camera/homekit/hevc/hevc-recording.js +28 -63
  25. package/dist/camera/homekit/hevc/hevc-recording.js.map +1 -1
  26. package/dist/camera/homekit/hevc/multi-tier-rtp.d.ts +1 -15
  27. package/dist/camera/homekit/hevc/multi-tier-rtp.js +70 -228
  28. package/dist/camera/homekit/hevc/multi-tier-rtp.js.map +1 -1
  29. package/dist/camera/homekit/hevc/sframe-rtp.d.ts +0 -2
  30. package/dist/camera/homekit/hevc/sframe-rtp.js +0 -25
  31. package/dist/camera/homekit/hevc/sframe-rtp.js.map +1 -1
  32. package/dist/camera/homekit/hevc/sframe.d.ts +1 -11
  33. package/dist/camera/homekit/hevc/sframe.js +18 -133
  34. package/dist/camera/homekit/hevc/sframe.js.map +1 -1
  35. package/dist/camera/homekit/hevc/types.js +81 -9
  36. package/dist/camera/homekit/hevc/types.js.map +1 -1
  37. package/dist/camera/homekit/hevc/webrtc-session.d.ts +3 -17
  38. package/dist/camera/homekit/hevc/webrtc-session.js +55 -229
  39. package/dist/camera/homekit/hevc/webrtc-session.js.map +1 -1
  40. package/dist/camera/homekit/homekit-camera-recording.delegate.d.ts +0 -1
  41. package/dist/camera/homekit/homekit-camera-recording.delegate.js +115 -43
  42. package/dist/camera/homekit/homekit-camera-recording.delegate.js.map +1 -1
  43. package/dist/camera/homekit/homekit-camera-stream.delegate.d.ts +4 -7
  44. package/dist/camera/homekit/homekit-camera-stream.delegate.js +388 -201
  45. package/dist/camera/homekit/homekit-camera-stream.delegate.js.map +1 -1
  46. package/dist/camera/homekit/homekit-camera.accessory.d.ts +7 -34
  47. package/dist/camera/homekit/homekit-camera.accessory.js +207 -169
  48. package/dist/camera/homekit/homekit-camera.accessory.js.map +1 -1
  49. package/dist/camera/homekit/live-view-telemetry.d.ts +0 -4
  50. package/dist/camera/homekit/live-view-telemetry.js.map +1 -1
  51. package/dist/camera/homekit/tuya-hap-talkback.d.ts +41 -0
  52. package/dist/camera/homekit/tuya-hap-talkback.js +326 -0
  53. package/dist/camera/homekit/tuya-hap-talkback.js.map +1 -0
  54. package/dist/camera/matter/camera-endpoint.builder.js +9 -7
  55. package/dist/camera/matter/camera-endpoint.builder.js.map +1 -1
  56. package/dist/camera/matter/camera-session-manager.d.ts +1 -0
  57. package/dist/camera/matter/camera-session-manager.js +2 -0
  58. package/dist/camera/matter/camera-session-manager.js.map +1 -1
  59. package/dist/camera/matter/camera-webrtc-adapter.js +32 -15
  60. package/dist/camera/matter/camera-webrtc-adapter.js.map +1 -1
  61. package/dist/camera/motion/ffmpeg-motion-detector.js +28 -14
  62. package/dist/camera/motion/ffmpeg-motion-detector.js.map +1 -1
  63. package/dist/camera/nest/nest-camera-adapter.js +9 -5
  64. package/dist/camera/nest/nest-camera-adapter.js.map +1 -1
  65. package/dist/camera/ptz/ptz-capabilities.js +3 -1
  66. package/dist/camera/ptz/ptz-capabilities.js.map +1 -1
  67. package/dist/camera/ptz/ptz-legacy-discovery.js.map +1 -1
  68. package/dist/camera/ptz/ptz-mqtt-publisher.js +50 -12
  69. package/dist/camera/ptz/ptz-mqtt-publisher.js.map +1 -1
  70. package/dist/camera/ptz/ptz-zones-manager.js +6 -1
  71. package/dist/camera/ptz/ptz-zones-manager.js.map +1 -1
  72. package/dist/camera/scrypted/scrypted-camera-card.js +3 -1
  73. package/dist/camera/scrypted/scrypted-camera-card.js.map +1 -1
  74. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js +7 -5
  75. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js.map +1 -1
  76. package/dist/camera/scrypted/scrypted-client-discovery-adapter.js.map +1 -1
  77. package/dist/camera/scrypted/scrypted-client.js +6 -5
  78. package/dist/camera/scrypted/scrypted-client.js.map +1 -1
  79. package/dist/camera/scrypted/scrypted-discovery-provider.js.map +1 -1
  80. package/dist/camera/scrypted/scrypted-homekit-bridge.js +6 -4
  81. package/dist/camera/scrypted/scrypted-homekit-bridge.js.map +1 -1
  82. package/dist/camera/scrypted/scrypted-reconnect-manager.js.map +1 -1
  83. package/dist/camera/scrypted/scrypted-runtime-facade.js +2 -2
  84. package/dist/camera/scrypted/scrypted-runtime-facade.js.map +1 -1
  85. package/dist/camera/scrypted/scrypted-runtime-ingest.js +3 -1
  86. package/dist/camera/scrypted/scrypted-runtime-ingest.js.map +1 -1
  87. package/dist/camera/scrypted/scrypted-storage.js +12 -6
  88. package/dist/camera/scrypted/scrypted-storage.js.map +1 -1
  89. package/dist/camera/scrypted/scrypted-stream-validator.js +25 -7
  90. package/dist/camera/scrypted/scrypted-stream-validator.js.map +1 -1
  91. package/dist/camera/tuya-webrtc-session.d.ts +53 -0
  92. package/dist/camera/tuya-webrtc-session.js +261 -0
  93. package/dist/camera/tuya-webrtc-session.js.map +1 -0
  94. package/dist/converters/sensor.converter.js +4 -1
  95. package/dist/converters/sensor.converter.js.map +1 -1
  96. package/dist/device-profiles.js +3 -1
  97. package/dist/device-profiles.js.map +1 -1
  98. package/dist/entities/air_quality.entity.js +3 -1
  99. package/dist/entities/air_quality.entity.js.map +1 -1
  100. package/dist/entities/base.entity.js +45 -17
  101. package/dist/entities/base.entity.js.map +1 -1
  102. package/dist/entities/camera.entity.d.ts +1 -0
  103. package/dist/entities/camera.entity.js +24 -2
  104. package/dist/entities/camera.entity.js.map +1 -1
  105. package/dist/entities/composite-device.entity.js +37 -13
  106. package/dist/entities/composite-device.entity.js.map +1 -1
  107. package/dist/entities/energy_tariff.entity.js.map +1 -1
  108. package/dist/entities/pet_feeder.entity.d.ts +1 -0
  109. package/dist/entities/pet_feeder.entity.js +12 -0
  110. package/dist/entities/pet_feeder.entity.js.map +1 -1
  111. package/dist/entities/vacuum.entity.js +16 -5
  112. package/dist/entities/vacuum.entity.js.map +1 -1
  113. package/dist/frontend/assets/index-1k-iTL-m.js +26 -0
  114. package/dist/frontend/assets/{index-NrzHqycm.css → index-CJdlkpIy.css} +1 -1
  115. package/dist/frontend/index.html +2 -2
  116. package/dist/hap/hap-generic-accessory.d.ts +4 -0
  117. package/dist/hap/hap-generic-accessory.js +512 -122
  118. package/dist/hap/hap-generic-accessory.js.map +1 -1
  119. package/dist/homeAssistant.d.ts +1 -0
  120. package/dist/homeAssistant.js +23 -5
  121. package/dist/homeAssistant.js.map +1 -1
  122. package/dist/index.js +3 -1
  123. package/dist/index.js.map +1 -1
  124. package/dist/mqtt/mqtt-client.js.map +1 -1
  125. package/dist/mqtt/mqtt.entity.js +41 -17
  126. package/dist/mqtt/mqtt.entity.js.map +1 -1
  127. package/dist/platform.d.ts +1 -0
  128. package/dist/platform.js +83 -13
  129. package/dist/platform.js.map +1 -1
  130. package/dist/utils/atomic-json-store.js +5 -1
  131. package/dist/utils/atomic-json-store.js.map +1 -1
  132. package/dist/utils/ha-state.js +3 -1
  133. package/dist/utils/ha-state.js.map +1 -1
  134. package/dist/utils/light-color.js +3 -5
  135. package/dist/utils/light-color.js.map +1 -1
  136. package/dist/utils/matter-command-response.js.map +1 -1
  137. package/dist/utils/matter-firmware.js +1 -2
  138. package/dist/utils/matter-firmware.js.map +1 -1
  139. package/dist/utils/matter-protocol.d.ts +1 -0
  140. package/dist/utils/matter-protocol.js +30 -0
  141. package/dist/utils/matter-protocol.js.map +1 -0
  142. package/package.json +27 -19
  143. package/dist/camera/camera-entity-control.d.ts +0 -12
  144. package/dist/camera/camera-entity-control.js +0 -24
  145. package/dist/camera/camera-entity-control.js.map +0 -1
  146. package/dist/camera/homekit/hevc/bootstrap.d.ts +0 -9
  147. package/dist/camera/homekit/hevc/bootstrap.js +0 -47
  148. package/dist/camera/homekit/hevc/bootstrap.js.map +0 -1
  149. package/dist/camera/homekit/hevc/recording-output.d.ts +0 -2
  150. package/dist/camera/homekit/hevc/recording-output.js +0 -33
  151. package/dist/camera/homekit/hevc/recording-output.js.map +0 -1
  152. package/dist/camera/homekit/media-policy.d.ts +0 -25
  153. package/dist/camera/homekit/media-policy.js +0 -102
  154. package/dist/camera/homekit/media-policy.js.map +0 -1
  155. package/dist/camera/homekit/route-address.d.ts +0 -2
  156. package/dist/camera/homekit/route-address.js +0 -27
  157. package/dist/camera/homekit/route-address.js.map +0 -1
  158. package/dist/camera/homekit/rtp-relay.d.ts +0 -21
  159. package/dist/camera/homekit/rtp-relay.js +0 -112
  160. package/dist/camera/homekit/rtp-relay.js.map +0 -1
  161. package/dist/camera/homekit/startup-timing.d.ts +0 -8
  162. package/dist/camera/homekit/startup-timing.js +0 -14
  163. package/dist/camera/homekit/startup-timing.js.map +0 -1
  164. package/dist/camera/source-adapter.d.ts +0 -132
  165. package/dist/camera/source-adapter.js +0 -282
  166. package/dist/camera/source-adapter.js.map +0 -1
  167. package/dist/frontend/assets/index-Bka3TVAQ.js +0 -21
  168. package/vendor/hap-nodejs/LICENSE +0 -176
  169. package/vendor/hap-nodejs/MIAO.md +0 -5
  170. package/vendor/hap-nodejs/PATCH.md +0 -37
  171. package/vendor/hap-nodejs/README.md +0 -86
  172. package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts +0 -2
  173. package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
  174. package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js +0 -128
  175. package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js.map +0 -1
  176. package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
  177. package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
  178. package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js +0 -159
  179. package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
  180. package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts +0 -2
  181. package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts.map +0 -1
  182. package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js +0 -545
  183. package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js.map +0 -1
  184. package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts +0 -2
  185. package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts.map +0 -1
  186. package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js +0 -74
  187. package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js.map +0 -1
  188. package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
  189. package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
  190. package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js +0 -78
  191. package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
  192. package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
  193. package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
  194. package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -106
  195. package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
  196. package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts +0 -2
  197. package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts.map +0 -1
  198. package/vendor/hap-nodejs/dist/accessories/Light_accessory.js +0 -145
  199. package/vendor/hap-nodejs/dist/accessories/Light_accessory.js.map +0 -1
  200. package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts +0 -2
  201. package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts.map +0 -1
  202. package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js +0 -76
  203. package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js.map +0 -1
  204. package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts +0 -2
  205. package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
  206. package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js +0 -45
  207. package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js.map +0 -1
  208. package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts +0 -2
  209. package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts.map +0 -1
  210. package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js +0 -79
  211. package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js.map +0 -1
  212. package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
  213. package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
  214. package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js +0 -44
  215. package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
  216. package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts +0 -2
  217. package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
  218. package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js +0 -128
  219. package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js.map +0 -1
  220. package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts +0 -2
  221. package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts.map +0 -1
  222. package/vendor/hap-nodejs/dist/accessories/TV_accessory.js +0 -101
  223. package/vendor/hap-nodejs/dist/accessories/TV_accessory.js.map +0 -1
  224. package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
  225. package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
  226. package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js +0 -44
  227. package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
  228. package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
  229. package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
  230. package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js +0 -17
  231. package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
  232. package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
  233. package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
  234. package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js +0 -19
  235. package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
  236. package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
  237. package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
  238. package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js +0 -145
  239. package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js.map +0 -1
  240. package/vendor/hap-nodejs/dist/accessories/types.d.ts +0 -78
  241. package/vendor/hap-nodejs/dist/accessories/types.d.ts.map +0 -1
  242. package/vendor/hap-nodejs/dist/accessories/types.js +0 -88
  243. package/vendor/hap-nodejs/dist/accessories/types.js.map +0 -1
  244. package/vendor/hap-nodejs/dist/index.d.ts +0 -50
  245. package/vendor/hap-nodejs/dist/index.d.ts.map +0 -1
  246. package/vendor/hap-nodejs/dist/index.js +0 -54
  247. package/vendor/hap-nodejs/dist/index.js.map +0 -1
  248. package/vendor/hap-nodejs/dist/internal-types.d.ts +0 -76
  249. package/vendor/hap-nodejs/dist/internal-types.d.ts.map +0 -1
  250. package/vendor/hap-nodejs/dist/internal-types.js +0 -80
  251. package/vendor/hap-nodejs/dist/internal-types.js.map +0 -1
  252. package/vendor/hap-nodejs/dist/lib/Accessory.d.ts +0 -521
  253. package/vendor/hap-nodejs/dist/lib/Accessory.d.ts.map +0 -1
  254. package/vendor/hap-nodejs/dist/lib/Accessory.js +0 -1762
  255. package/vendor/hap-nodejs/dist/lib/Accessory.js.map +0 -1
  256. package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts +0 -190
  257. package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts.map +0 -1
  258. package/vendor/hap-nodejs/dist/lib/Advertiser.js +0 -592
  259. package/vendor/hap-nodejs/dist/lib/Advertiser.js.map +0 -1
  260. package/vendor/hap-nodejs/dist/lib/Bridge.d.ts +0 -12
  261. package/vendor/hap-nodejs/dist/lib/Bridge.d.ts.map +0 -1
  262. package/vendor/hap-nodejs/dist/lib/Bridge.js +0 -19
  263. package/vendor/hap-nodejs/dist/lib/Bridge.js.map +0 -1
  264. package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts +0 -1768
  265. package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts.map +0 -1
  266. package/vendor/hap-nodejs/dist/lib/Characteristic.js +0 -2532
  267. package/vendor/hap-nodejs/dist/lib/Characteristic.js.map +0 -1
  268. package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts +0 -299
  269. package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts.map +0 -1
  270. package/vendor/hap-nodejs/dist/lib/HAPServer.js +0 -968
  271. package/vendor/hap-nodejs/dist/lib/HAPServer.js.map +0 -1
  272. package/vendor/hap-nodejs/dist/lib/Service.d.ts +0 -598
  273. package/vendor/hap-nodejs/dist/lib/Service.d.ts.map +0 -1
  274. package/vendor/hap-nodejs/dist/lib/Service.js +0 -797
  275. package/vendor/hap-nodejs/dist/lib/Service.js.map +0 -1
  276. package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts +0 -102
  277. package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts.map +0 -1
  278. package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js +0 -317
  279. package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js.map +0 -1
  280. package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts +0 -38
  281. package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts.map +0 -1
  282. package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js +0 -174
  283. package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js.map +0 -1
  284. package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts +0 -59
  285. package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts.map +0 -1
  286. package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js +0 -267
  287. package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js.map +0 -1
  288. package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts +0 -379
  289. package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
  290. package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js +0 -1021
  291. package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js.map +0 -1
  292. package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts +0 -325
  293. package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
  294. package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js +0 -800
  295. package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js.map +0 -1
  296. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts +0 -20
  297. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts.map +0 -1
  298. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js +0 -48
  299. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js.map +0 -1
  300. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts +0 -618
  301. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts.map +0 -1
  302. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js +0 -911
  303. package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js.map +0 -1
  304. package/vendor/hap-nodejs/dist/lib/camera/index.d.ts +0 -8
  305. package/vendor/hap-nodejs/dist/lib/camera/index.d.ts.map +0 -1
  306. package/vendor/hap-nodejs/dist/lib/camera/index.js +0 -11
  307. package/vendor/hap-nodejs/dist/lib/camera/index.js.map +0 -1
  308. package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts +0 -452
  309. package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
  310. package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js +0 -868
  311. package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js.map +0 -1
  312. package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts +0 -410
  313. package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts.map +0 -1
  314. package/vendor/hap-nodejs/dist/lib/controller/CameraController.js +0 -658
  315. package/vendor/hap-nodejs/dist/lib/controller/CameraController.js.map +0 -1
  316. package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts +0 -197
  317. package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts.map +0 -1
  318. package/vendor/hap-nodejs/dist/lib/controller/Controller.js +0 -32
  319. package/vendor/hap-nodejs/dist/lib/controller/Controller.js.map +0 -1
  320. package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts +0 -59
  321. package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts.map +0 -1
  322. package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js +0 -102
  323. package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js.map +0 -1
  324. package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts +0 -434
  325. package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts.map +0 -1
  326. package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js +0 -1178
  327. package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js.map +0 -1
  328. package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts +0 -380
  329. package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts.map +0 -1
  330. package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js +0 -947
  331. package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js.map +0 -1
  332. package/vendor/hap-nodejs/dist/lib/controller/index.d.ts +0 -7
  333. package/vendor/hap-nodejs/dist/lib/controller/index.d.ts.map +0 -1
  334. package/vendor/hap-nodejs/dist/lib/controller/index.js +0 -10
  335. package/vendor/hap-nodejs/dist/lib/controller/index.js.map +0 -1
  336. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts +0 -73
  337. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
  338. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js +0 -205
  339. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js.map +0 -1
  340. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts +0 -186
  341. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
  342. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js +0 -880
  343. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js.map +0 -1
  344. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts +0 -351
  345. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
  346. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js +0 -878
  347. package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js.map +0 -1
  348. package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts +0 -4
  349. package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts.map +0 -1
  350. package/vendor/hap-nodejs/dist/lib/datastream/index.js +0 -7
  351. package/vendor/hap-nodejs/dist/lib/datastream/index.js.map +0 -1
  352. package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts +0 -2245
  353. package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
  354. package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js +0 -4957
  355. package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js.map +0 -1
  356. package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts +0 -584
  357. package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
  358. package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js +0 -1518
  359. package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js.map +0 -1
  360. package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts +0 -34
  361. package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
  362. package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js +0 -624
  363. package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js.map +0 -1
  364. package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts +0 -22
  365. package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
  366. package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js +0 -734
  367. package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js.map +0 -1
  368. package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts +0 -3
  369. package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts.map +0 -1
  370. package/vendor/hap-nodejs/dist/lib/definitions/index.js +0 -6
  371. package/vendor/hap-nodejs/dist/lib/definitions/index.js.map +0 -1
  372. package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts +0 -8
  373. package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts.map +0 -1
  374. package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js +0 -9
  375. package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js.map +0 -1
  376. package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts +0 -91
  377. package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
  378. package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js +0 -311
  379. package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js.map +0 -1
  380. package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts +0 -46
  381. package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts.map +0 -1
  382. package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js +0 -277
  383. package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js.map +0 -1
  384. package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts +0 -75
  385. package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
  386. package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js +0 -190
  387. package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js.map +0 -1
  388. package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts +0 -26
  389. package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts.map +0 -1
  390. package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js +0 -79
  391. package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js.map +0 -1
  392. package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts +0 -33
  393. package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts.map +0 -1
  394. package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js +0 -114
  395. package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js.map +0 -1
  396. package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts +0 -83
  397. package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
  398. package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js +0 -127
  399. package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js.map +0 -1
  400. package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts +0 -8
  401. package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts.map +0 -1
  402. package/vendor/hap-nodejs/dist/lib/util/checkName.js +0 -28
  403. package/vendor/hap-nodejs/dist/lib/util/checkName.js.map +0 -1
  404. package/vendor/hap-nodejs/dist/lib/util/clone.d.ts +0 -7
  405. package/vendor/hap-nodejs/dist/lib/util/clone.d.ts.map +0 -1
  406. package/vendor/hap-nodejs/dist/lib/util/clone.js +0 -22
  407. package/vendor/hap-nodejs/dist/lib/util/clone.js.map +0 -1
  408. package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts +0 -18
  409. package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts.map +0 -1
  410. package/vendor/hap-nodejs/dist/lib/util/color-utils.js +0 -442
  411. package/vendor/hap-nodejs/dist/lib/util/color-utils.js.map +0 -1
  412. package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts +0 -251
  413. package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts.map +0 -1
  414. package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js +0 -714
  415. package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js.map +0 -1
  416. package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts +0 -50
  417. package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts.map +0 -1
  418. package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js +0 -185
  419. package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js.map +0 -1
  420. package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts +0 -16
  421. package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts.map +0 -1
  422. package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js +0 -29
  423. package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js.map +0 -1
  424. package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts +0 -21
  425. package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts.map +0 -1
  426. package/vendor/hap-nodejs/dist/lib/util/net-utils.js +0 -79
  427. package/vendor/hap-nodejs/dist/lib/util/net-utils.js.map +0 -1
  428. package/vendor/hap-nodejs/dist/lib/util/once.d.ts +0 -7
  429. package/vendor/hap-nodejs/dist/lib/util/once.d.ts.map +0 -1
  430. package/vendor/hap-nodejs/dist/lib/util/once.js +0 -22
  431. package/vendor/hap-nodejs/dist/lib/util/once.js.map +0 -1
  432. package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts +0 -14
  433. package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts.map +0 -1
  434. package/vendor/hap-nodejs/dist/lib/util/promise-utils.js +0 -29
  435. package/vendor/hap-nodejs/dist/lib/util/promise-utils.js.map +0 -1
  436. package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts +0 -36
  437. package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts.map +0 -1
  438. package/vendor/hap-nodejs/dist/lib/util/request-util.js +0 -108
  439. package/vendor/hap-nodejs/dist/lib/util/request-util.js.map +0 -1
  440. package/vendor/hap-nodejs/dist/lib/util/time.d.ts +0 -9
  441. package/vendor/hap-nodejs/dist/lib/util/time.d.ts.map +0 -1
  442. package/vendor/hap-nodejs/dist/lib/util/time.js +0 -23
  443. package/vendor/hap-nodejs/dist/lib/util/time.js.map +0 -1
  444. package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts +0 -90
  445. package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts.map +0 -1
  446. package/vendor/hap-nodejs/dist/lib/util/tlv.js +0 -318
  447. package/vendor/hap-nodejs/dist/lib/util/tlv.js.map +0 -1
  448. package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts +0 -23
  449. package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts.map +0 -1
  450. package/vendor/hap-nodejs/dist/lib/util/uuid.js +0 -78
  451. package/vendor/hap-nodejs/dist/lib/util/uuid.js.map +0 -1
  452. package/vendor/hap-nodejs/dist/types.d.ts +0 -276
  453. package/vendor/hap-nodejs/dist/types.d.ts.map +0 -1
  454. package/vendor/hap-nodejs/dist/types.js +0 -11
  455. package/vendor/hap-nodejs/dist/types.js.map +0 -1
  456. package/vendor/hap-nodejs/package.json +0 -53
  457. package/vendor/hap-nodejs/src/lib/util/hapCrypto.ts +0 -208
@@ -1,1762 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Accessory = exports.AccessoryEventTypes = exports.MDNSAdvertiser = exports.CharacteristicWarningType = exports.Categories = void 0;
4
- const tslib_1 = require("tslib");
5
- const assert_1 = tslib_1.__importDefault(require("assert"));
6
- const crypto_1 = tslib_1.__importDefault(require("crypto"));
7
- const debug_1 = tslib_1.__importDefault(require("debug"));
8
- const events_1 = require("events");
9
- const net_1 = tslib_1.__importDefault(require("net"));
10
- const Advertiser_1 = require("./Advertiser");
11
- // noinspection JSDeprecatedSymbols
12
- const Characteristic_1 = require("./Characteristic");
13
- const controller_1 = require("./controller");
14
- const HAPServer_1 = require("./HAPServer");
15
- const AccessoryInfo_1 = require("./model/AccessoryInfo");
16
- const ControllerStorage_1 = require("./model/ControllerStorage");
17
- const IdentifierCache_1 = require("./model/IdentifierCache");
18
- const Service_1 = require("./Service");
19
- const clone_1 = require("./util/clone");
20
- const request_util_1 = require("./util/request-util");
21
- const uuid = tslib_1.__importStar(require("./util/uuid"));
22
- const uuid_1 = require("./util/uuid");
23
- const checkName_1 = require("./util/checkName");
24
- const debug = (0, debug_1.default)("HAP-NodeJS:Accessory");
25
- const hksvDebug = (0, debug_1.default)("HAP-NodeJS:HKSV");
26
- const MAX_ACCESSORIES = 149; // Maximum number of bridged accessories per bridge.
27
- const MAX_SERVICES = 100;
28
- /**
29
- * Known category values. Category is a hint to iOS clients about what "type" of Accessory this represents, for UI only.
30
- *
31
- * @group Accessory
32
- */
33
- var Categories;
34
- (function (Categories) {
35
- // noinspection JSUnusedGlobalSymbols
36
- Categories[Categories["OTHER"] = 1] = "OTHER";
37
- Categories[Categories["BRIDGE"] = 2] = "BRIDGE";
38
- Categories[Categories["FAN"] = 3] = "FAN";
39
- Categories[Categories["GARAGE_DOOR_OPENER"] = 4] = "GARAGE_DOOR_OPENER";
40
- Categories[Categories["LIGHTBULB"] = 5] = "LIGHTBULB";
41
- Categories[Categories["DOOR_LOCK"] = 6] = "DOOR_LOCK";
42
- Categories[Categories["OUTLET"] = 7] = "OUTLET";
43
- Categories[Categories["SWITCH"] = 8] = "SWITCH";
44
- Categories[Categories["THERMOSTAT"] = 9] = "THERMOSTAT";
45
- Categories[Categories["SENSOR"] = 10] = "SENSOR";
46
- Categories[Categories["ALARM_SYSTEM"] = 11] = "ALARM_SYSTEM";
47
- // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
48
- Categories[Categories["SECURITY_SYSTEM"] = 11] = "SECURITY_SYSTEM";
49
- Categories[Categories["DOOR"] = 12] = "DOOR";
50
- Categories[Categories["WINDOW"] = 13] = "WINDOW";
51
- Categories[Categories["WINDOW_COVERING"] = 14] = "WINDOW_COVERING";
52
- Categories[Categories["PROGRAMMABLE_SWITCH"] = 15] = "PROGRAMMABLE_SWITCH";
53
- Categories[Categories["RANGE_EXTENDER"] = 16] = "RANGE_EXTENDER";
54
- Categories[Categories["CAMERA"] = 17] = "CAMERA";
55
- // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
56
- Categories[Categories["IP_CAMERA"] = 17] = "IP_CAMERA";
57
- Categories[Categories["VIDEO_DOORBELL"] = 18] = "VIDEO_DOORBELL";
58
- Categories[Categories["AIR_PURIFIER"] = 19] = "AIR_PURIFIER";
59
- Categories[Categories["AIR_HEATER"] = 20] = "AIR_HEATER";
60
- Categories[Categories["AIR_CONDITIONER"] = 21] = "AIR_CONDITIONER";
61
- Categories[Categories["AIR_HUMIDIFIER"] = 22] = "AIR_HUMIDIFIER";
62
- Categories[Categories["AIR_DEHUMIDIFIER"] = 23] = "AIR_DEHUMIDIFIER";
63
- Categories[Categories["APPLE_TV"] = 24] = "APPLE_TV";
64
- Categories[Categories["HOMEPOD"] = 25] = "HOMEPOD";
65
- Categories[Categories["SPEAKER"] = 26] = "SPEAKER";
66
- Categories[Categories["AIRPORT"] = 27] = "AIRPORT";
67
- Categories[Categories["SPRINKLER"] = 28] = "SPRINKLER";
68
- Categories[Categories["FAUCET"] = 29] = "FAUCET";
69
- Categories[Categories["SHOWER_HEAD"] = 30] = "SHOWER_HEAD";
70
- Categories[Categories["TELEVISION"] = 31] = "TELEVISION";
71
- Categories[Categories["TARGET_CONTROLLER"] = 32] = "TARGET_CONTROLLER";
72
- Categories[Categories["ROUTER"] = 33] = "ROUTER";
73
- Categories[Categories["AUDIO_RECEIVER"] = 34] = "AUDIO_RECEIVER";
74
- Categories[Categories["TV_SET_TOP_BOX"] = 35] = "TV_SET_TOP_BOX";
75
- Categories[Categories["TV_STREAMING_STICK"] = 36] = "TV_STREAMING_STICK";
76
- })(Categories || (exports.Categories = Categories = {}));
77
- /**
78
- * @group Accessory
79
- */
80
- var CharacteristicWarningType;
81
- (function (CharacteristicWarningType) {
82
- CharacteristicWarningType["SLOW_WRITE"] = "slow-write";
83
- CharacteristicWarningType["TIMEOUT_WRITE"] = "timeout-write";
84
- CharacteristicWarningType["SLOW_READ"] = "slow-read";
85
- CharacteristicWarningType["TIMEOUT_READ"] = "timeout-read";
86
- CharacteristicWarningType["WARN_MESSAGE"] = "warn-message";
87
- CharacteristicWarningType["ERROR_MESSAGE"] = "error-message";
88
- CharacteristicWarningType["DEBUG_MESSAGE"] = "debug-message";
89
- })(CharacteristicWarningType || (exports.CharacteristicWarningType = CharacteristicWarningType = {}));
90
- /**
91
- * @group Accessory
92
- */
93
- var MDNSAdvertiser;
94
- (function (MDNSAdvertiser) {
95
- /**
96
- * Use the `@homebridge/ciao` module as advertiser.
97
- */
98
- MDNSAdvertiser["CIAO"] = "ciao";
99
- /**
100
- * Use the `bonjour-hap` module as advertiser.
101
- */
102
- MDNSAdvertiser["BONJOUR"] = "bonjour-hap";
103
- /**
104
- * Use Avahi/D-Bus as advertiser.
105
- */
106
- MDNSAdvertiser["AVAHI"] = "avahi";
107
- /**
108
- * Use systemd-resolved/D-Bus as advertiser.
109
- *
110
- * Note: The systemd-resolved D-Bus interface doesn't provide means to detect restarts of the service.
111
- * Therefore, we can't detect if our advertisement might be lost due to a restart of the systemd-resolved daemon restart.
112
- * Consequentially, treat this feature as an experimental feature.
113
- */
114
- MDNSAdvertiser["RESOLVED"] = "resolved";
115
- })(MDNSAdvertiser || (exports.MDNSAdvertiser = MDNSAdvertiser = {}));
116
- var WriteRequestState;
117
- (function (WriteRequestState) {
118
- WriteRequestState[WriteRequestState["REGULAR_REQUEST"] = 0] = "REGULAR_REQUEST";
119
- WriteRequestState[WriteRequestState["TIMED_WRITE_AUTHENTICATED"] = 1] = "TIMED_WRITE_AUTHENTICATED";
120
- WriteRequestState[WriteRequestState["TIMED_WRITE_REJECTED"] = 2] = "TIMED_WRITE_REJECTED";
121
- })(WriteRequestState || (WriteRequestState = {}));
122
- /**
123
- * @group Accessory
124
- */
125
- var AccessoryEventTypes;
126
- (function (AccessoryEventTypes) {
127
- /**
128
- * Emitted when an iOS device wishes for this Accessory to identify itself. If `paired` is false, then
129
- * this device is currently browsing for Accessories in the system-provided "Add Accessory" screen. If
130
- * `paired` is true, then this is a device that has already paired with us. Note that if `paired` is true,
131
- * listening for this event is a shortcut for the underlying mechanism of setting the `Identify` Characteristic:
132
- * `getService(Service.AccessoryInformation).getCharacteristic(Characteristic.Identify).on('set', ...)`
133
- * You must call the callback for identification to be successful.
134
- */
135
- AccessoryEventTypes["IDENTIFY"] = "identify";
136
- /**
137
- * This event is emitted once the HAP TCP socket is bound.
138
- * At this point the mdns advertisement isn't yet available. Use the {@link ADVERTISED} if you require the accessory to be discoverable.
139
- */
140
- AccessoryEventTypes["LISTENING"] = "listening";
141
- /**
142
- * This event is emitted once the mDNS suite has fully advertised the presence of the accessory.
143
- * This event is guaranteed to be called after {@link LISTENING}.
144
- */
145
- AccessoryEventTypes["ADVERTISED"] = "advertised";
146
- AccessoryEventTypes["SERVICE_CONFIGURATION_CHANGE"] = "service-configurationChange";
147
- /**
148
- * Emitted after a change in the value of one of the provided Service's Characteristics.
149
- */
150
- AccessoryEventTypes["SERVICE_CHARACTERISTIC_CHANGE"] = "service-characteristic-change";
151
- AccessoryEventTypes["PAIRED"] = "paired";
152
- AccessoryEventTypes["UNPAIRED"] = "unpaired";
153
- AccessoryEventTypes["CHARACTERISTIC_WARNING"] = "characteristic-warning";
154
- })(AccessoryEventTypes || (exports.AccessoryEventTypes = AccessoryEventTypes = {}));
155
- /**
156
- * Accessory is a virtual HomeKit device. It can publish an associated HAP server for iOS devices to communicate
157
- * with - or it can run behind another "Bridge" Accessory server.
158
- *
159
- * Bridged Accessories in this implementation must have a UUID that is unique among all other Accessories that
160
- * are hosted by the Bridge. This UUID must be "stable" and unchanging, even when the server is restarted. This
161
- * is required so that the Bridge can provide consistent "Accessory IDs" (aid) and "Instance IDs" (iid) for all
162
- * Accessories, Services, and Characteristics for iOS clients to reference later.
163
- *
164
- * @group Accessory
165
- */
166
- // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
167
- class Accessory extends events_1.EventEmitter {
168
- displayName;
169
- UUID;
170
- // Timeout in milliseconds until a characteristic warning is issue
171
- static TIMEOUT_WARNING = 3000;
172
- // Timeout in milliseconds after `TIMEOUT_WARNING` until the operation on the characteristic is considered timed out.
173
- static TIMEOUT_AFTER_WARNING = 6000;
174
- // NOTICE: when adding/changing properties, remember to possibly adjust the serialize/deserialize functions
175
- aid = null; // assigned by us in assignIDs() or by a Bridge
176
- _isBridge = false; // true if we are a Bridge (creating a new instance of the Bridge subclass sets this to true)
177
- bridged = false; // true if we are hosted "behind" a Bridge Accessory
178
- bridge; // if accessory is bridged, this property points to the bridge which bridges this accessory
179
- bridgedAccessories = []; // If we are a Bridge, these are the Accessories we are bridging
180
- reachable = true;
181
- lastKnownUsername;
182
- category = 1 /* Categories.OTHER */;
183
- services = [];
184
- primaryService;
185
- shouldPurgeUnusedIDs = true; // Purge unused ids by default
186
- /**
187
- * Captures if initialization steps inside {@link publish} have been called.
188
- * This is important when calling {@link publish} multiple times (e.g. after calling {@link unpublish}).
189
- * @private Private API
190
- */
191
- initialized = false;
192
- controllers = {};
193
- serializedControllers; // store uninitialized controller data after a Accessory.deserialize call
194
- activeCameraController;
195
- /**
196
- * @private Private API.
197
- */
198
- _accessoryInfo;
199
- /**
200
- * @private Private API.
201
- */
202
- _setupID = null;
203
- /**
204
- * @private Private API.
205
- */
206
- _identifierCache;
207
- /**
208
- * @private Private API.
209
- */
210
- controllerStorage;
211
- /**
212
- * @private Private API.
213
- */
214
- _advertiser;
215
- /**
216
- * @private Private API.
217
- */
218
- _server;
219
- /**
220
- * @private Private API.
221
- */
222
- _setupURI;
223
- configurationChangeDebounceTimeout;
224
- /**
225
- * This property captures the time when we last served a /accessories request.
226
- * For multiple bursts of /accessories request we don't want to always contact GET handlers
227
- */
228
- lastAccessoriesRequest = 0;
229
- /**
230
- * The result of the last permissions evaluation made by the bridge that hosts this accessory, used solely to tell a transition in or out of quarantine
231
- * from a state that has not changed. It is never consulted to decide what gets served: {@link findPermsViolation}, re-run on every representation build,
232
- * is the truth there.
233
- */
234
- permsQuarantined = false;
235
- constructor(displayName, UUID) {
236
- super();
237
- this.displayName = displayName;
238
- this.UUID = UUID;
239
- (0, assert_1.default)(displayName, "Accessories must be created with a non-empty displayName.");
240
- (0, assert_1.default)(UUID, "Accessories must be created with a valid UUID.");
241
- (0, assert_1.default)(uuid.isValid(UUID), "UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a " +
242
- "valid UUID from any arbitrary string, like a serial number.");
243
- this.controllerStorage = new ControllerStorage_1.ControllerStorage(this);
244
- // create our initial "Accessory Information" Service that all Accessories are expected to have
245
- (0, checkName_1.checkName)(this.displayName, "Name", displayName);
246
- this.addService(Service_1.Service.AccessoryInformation)
247
- .setCharacteristic(Characteristic_1.Characteristic.Name, displayName);
248
- // sign up for when iOS attempts to "set" the `Identify` characteristic - this means a paired device wishes
249
- // for us to identify ourselves (as opposed to an unpaired device - that case is handled by HAPServer 'identify' event)
250
- this.getService(Service_1.Service.AccessoryInformation)
251
- .getCharacteristic(Characteristic_1.Characteristic.Identify)
252
- .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
253
- if (value) {
254
- const paired = true;
255
- this.identificationRequest(paired, callback);
256
- }
257
- });
258
- }
259
- identificationRequest(paired, callback) {
260
- debug("[%s] Identification request", this.displayName);
261
- if (this.listeners("identify" /* AccessoryEventTypes.IDENTIFY */).length > 0) {
262
- // allow implementors to identify this Accessory in whatever way is appropriate, and pass along
263
- // the standard callback for completion.
264
- this.emit("identify" /* AccessoryEventTypes.IDENTIFY */, paired, callback);
265
- }
266
- else {
267
- debug("[%s] Identification request ignored; no listeners to 'identify' event", this.displayName);
268
- callback();
269
- }
270
- }
271
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
- addService(serviceParam, ...constructorArgs) {
273
- // service might be a constructor like `Service.AccessoryInformation` instead of an instance
274
- // of Service. Coerce if necessary.
275
- const service = typeof serviceParam === "function"
276
- ? new serviceParam(constructorArgs[0], constructorArgs[1], constructorArgs[2])
277
- : serviceParam;
278
- // check for UUID+subtype conflict
279
- for (const existing of this.services) {
280
- if (existing.UUID === service.UUID) {
281
- // OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
282
- if (!service.subtype) {
283
- throw new Error("Cannot add a Service with the same UUID '" + existing.UUID +
284
- "' as another Service in this Accessory without also defining a unique 'subtype' property.");
285
- }
286
- if (service.subtype === existing.subtype) {
287
- throw new Error("Cannot add a Service with the same UUID '" + existing.UUID +
288
- "' and subtype '" + existing.subtype + "' as another Service in this Accessory.");
289
- }
290
- }
291
- }
292
- if (this.services.length >= MAX_SERVICES) {
293
- throw new Error("Cannot add more than " + MAX_SERVICES + " services to a single accessory!");
294
- }
295
- this.services.push(service);
296
- if (service.isPrimaryService) { // check if a primary service was added
297
- if (this.primaryService !== undefined) {
298
- this.primaryService.isPrimaryService = false;
299
- }
300
- this.primaryService = service;
301
- }
302
- if (!this.bridged) {
303
- this.enqueueConfigurationUpdate();
304
- }
305
- else {
306
- this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service: service });
307
- }
308
- this.setupServiceEventHandlers(service);
309
- return service;
310
- }
311
- removeService(service) {
312
- const index = this.services.indexOf(service);
313
- if (index >= 0) {
314
- this.services.splice(index, 1);
315
- if (this.primaryService === service) { // check if we are removing out primary service
316
- this.primaryService = undefined;
317
- }
318
- this.removeLinkedService(service); // remove it from linked service entries on the local accessory
319
- if (!this.bridged) {
320
- this.enqueueConfigurationUpdate();
321
- }
322
- else {
323
- this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service: service });
324
- }
325
- service.removeAllListeners();
326
- }
327
- }
328
- removeLinkedService(removed) {
329
- for (const service of this.services) {
330
- service.removeLinkedService(removed);
331
- }
332
- }
333
- getService(name) {
334
- for (const service of this.services) {
335
- if (typeof name === "string" && (service.displayName === name || service.name === name || service.subtype === name)) {
336
- return service;
337
- }
338
- else {
339
- // @ts-expect-error ('UUID' does not exist on type 'never')
340
- if (typeof name === "function" && ((service instanceof name) || (name.UUID === service.UUID))) {
341
- return service;
342
- }
343
- }
344
- }
345
- return undefined;
346
- }
347
- getServiceById(uuid, subType) {
348
- for (const service of this.services) {
349
- if (typeof uuid === "string" && (service.displayName === uuid || service.name === uuid) && service.subtype === subType) {
350
- return service;
351
- }
352
- else {
353
- // @ts-expect-error ('UUID' does not exist on type 'never')
354
- if (typeof uuid === "function" && ((service instanceof uuid) || (uuid.UUID === service.UUID)) && service.subtype === subType) {
355
- return service;
356
- }
357
- }
358
- }
359
- return undefined;
360
- }
361
- /**
362
- * Returns the bridging accessory if this accessory is bridged.
363
- * Otherwise, returns itself.
364
- *
365
- * @returns the primary accessory
366
- */
367
- getPrimaryAccessory = () => {
368
- return this.bridged ? this.bridge : this;
369
- };
370
- addBridgedAccessory(accessory, deferUpdate = false) {
371
- if (accessory._isBridge || accessory === this) {
372
- throw new Error("Illegal state: either trying to bridge a bridge or trying to bridge itself!");
373
- }
374
- if (accessory.initialized) {
375
- throw new Error("Tried to bridge an accessory which was already published once!");
376
- }
377
- if (accessory.bridge != null) {
378
- // this also prevents that we bridge the same accessory twice!
379
- throw new Error("Tried to bridge " + accessory.displayName + " while it was already bridged by " + accessory.bridge.displayName);
380
- }
381
- if (this.bridgedAccessories.length >= MAX_ACCESSORIES) {
382
- throw new Error("Cannot Bridge more than " + MAX_ACCESSORIES + " Accessories");
383
- }
384
- // listen for changes in ANY characteristics of ANY services on this Accessory
385
- accessory.on("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, change => this.handleCharacteristicChangeEvent(accessory, change.service, change));
386
- accessory.on("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, this.enqueueConfigurationUpdate.bind(this));
387
- accessory.on("characteristic-warning" /* AccessoryEventTypes.CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
388
- accessory.bridged = true;
389
- accessory.bridge = this;
390
- this.bridgedAccessories.push(accessory);
391
- this.controllerStorage.linkAccessory(accessory); // init controllers of bridged accessory
392
- if (!deferUpdate) {
393
- this.enqueueConfigurationUpdate();
394
- }
395
- return accessory;
396
- }
397
- addBridgedAccessories(accessories) {
398
- for (const accessory of accessories) {
399
- this.addBridgedAccessory(accessory, true);
400
- }
401
- this.enqueueConfigurationUpdate();
402
- }
403
- removeBridgedAccessory(accessory, deferUpdate = false) {
404
- // check for UUID conflict
405
- const accessoryIndex = this.bridgedAccessories.indexOf(accessory);
406
- if (accessoryIndex === -1) {
407
- throw new Error("Cannot find the bridged Accessory to remove.");
408
- }
409
- this.bridgedAccessories.splice(accessoryIndex, 1);
410
- accessory.bridged = false;
411
- accessory.bridge = undefined;
412
- accessory.permsQuarantined = false; // a later bridge starts from a clean slate and re-evaluates the accessory itself
413
- accessory.removeAllListeners();
414
- if (!deferUpdate) {
415
- this.enqueueConfigurationUpdate();
416
- }
417
- }
418
- removeBridgedAccessories(accessories) {
419
- for (const accessory of accessories) {
420
- this.removeBridgedAccessory(accessory, true);
421
- }
422
- this.enqueueConfigurationUpdate();
423
- }
424
- removeAllBridgedAccessories() {
425
- for (let i = this.bridgedAccessories.length - 1; i >= 0; i--) {
426
- this.removeBridgedAccessory(this.bridgedAccessories[i], true);
427
- }
428
- this.enqueueConfigurationUpdate();
429
- }
430
- getCharacteristicByIID(iid) {
431
- for (const service of this.services) {
432
- const characteristic = service.getCharacteristicByIID(iid);
433
- if (characteristic) {
434
- return characteristic;
435
- }
436
- }
437
- }
438
- getAccessoryByAID(aid) {
439
- if (this.aid === aid) {
440
- return this;
441
- }
442
- return this.bridgedAccessories.find(value => value.aid === aid);
443
- }
444
- findCharacteristic(aid, iid) {
445
- const accessory = this.getAccessoryByAID(aid);
446
- return accessory && accessory.getCharacteristicByIID(iid);
447
- }
448
- /**
449
- * This method is used to set up a new Controller for this accessory. See {@link Controller} for a more detailed
450
- * explanation what a Controller is and what it is capable of.
451
- *
452
- * The controller can be passed as an instance of the class or as a constructor (without any necessary parameters)
453
- * for a new Controller.
454
- * Only one Controller of a given {@link ControllerIdentifier} can be configured for a given Accessory.
455
- *
456
- * When called, it will be checked if there are any services and persistent data the Controller (for the given
457
- * {@link ControllerIdentifier}) can be restored from. Otherwise, the Controller will be created with new services.
458
- *
459
- *
460
- * @param controllerConstructor - The Controller instance or constructor to the Controller with no required arguments.
461
- */
462
- configureController(controllerConstructor) {
463
- const controller = typeof controllerConstructor === "function"
464
- ? new controllerConstructor() // any custom constructor arguments should be passed before using .bind(...)
465
- : controllerConstructor;
466
- const id = controller.controllerId();
467
- if (this.controllers[id]) {
468
- throw new Error(`A Controller with the type/id '${id}' was already added to the accessory ${this.displayName}`);
469
- }
470
- const savedServiceMap = this.serializedControllers && this.serializedControllers[id];
471
- let serviceMap;
472
- if (savedServiceMap) { // we found data to restore from
473
- const clonedServiceMap = (0, clone_1.clone)(savedServiceMap);
474
- const updatedServiceMap = controller.initWithServices(savedServiceMap); // init controller with existing services
475
- serviceMap = updatedServiceMap || savedServiceMap; // initWithServices could return an updated serviceMap, otherwise just use the existing one
476
- if (updatedServiceMap) { // controller returned a ServiceMap and thus signaled an updated set of services
477
- // clonedServiceMap is altered by this method, should not be touched again after this call (for the future people)
478
- this.handleUpdatedControllerServiceMap(clonedServiceMap, updatedServiceMap);
479
- }
480
- controller.configureServices(); // let the controller setup all its handlers
481
- // remove serialized data from our dictionary:
482
- delete this.serializedControllers[id];
483
- if (Object.entries(this.serializedControllers).length === 0) {
484
- this.serializedControllers = undefined;
485
- }
486
- }
487
- else {
488
- serviceMap = controller.constructServices(); // let the controller create his services
489
- controller.configureServices(); // let the controller setup all its handlers
490
- Object.values(serviceMap).forEach(service => {
491
- if (service && !this.services.includes(service)) {
492
- this.addService(service);
493
- }
494
- });
495
- }
496
- // --- init handlers and setup context ---
497
- const context = {
498
- controller: controller,
499
- serviceMap: serviceMap,
500
- };
501
- if ((0, controller_1.isSerializableController)(controller)) {
502
- this.controllerStorage.trackController(controller);
503
- }
504
- this.controllers[id] = context;
505
- if ((0, controller_1.isSnapshotController)(controller)) { // save the controller for snapshot handling
506
- this.activeCameraController = controller;
507
- }
508
- }
509
- /**
510
- * This method will remove a given Controller from this accessory.
511
- * The controller object will be restored to its initial state.
512
- * This also means that any event handlers setup for the controller will be removed.
513
- *
514
- * @param controller - The controller which should be removed from the accessory.
515
- */
516
- removeController(controller) {
517
- const id = controller.controllerId();
518
- const storedController = this.controllers[id];
519
- if (storedController) {
520
- if (storedController.controller !== controller) {
521
- throw new Error("[" + this.displayName + "] tried removing a controller with the id/type '" + id +
522
- "' though provided controller isn't the same instance that is registered!");
523
- }
524
- if ((0, controller_1.isSerializableController)(controller)) {
525
- // this will reset the state change delegate before we call handleControllerRemoved()
526
- this.controllerStorage.untrackController(controller);
527
- }
528
- if (controller.handleFactoryReset) {
529
- controller.handleFactoryReset();
530
- }
531
- controller.handleControllerRemoved();
532
- delete this.controllers[id];
533
- if (this.activeCameraController === controller) {
534
- this.activeCameraController = undefined;
535
- }
536
- Object.values(storedController.serviceMap).forEach(service => {
537
- if (service) {
538
- this.removeService(service);
539
- }
540
- });
541
- }
542
- if (this.serializedControllers) {
543
- delete this.serializedControllers[id];
544
- }
545
- }
546
- handleAccessoryUnpairedForControllers() {
547
- for (const context of Object.values(this.controllers)) {
548
- const controller = context.controller;
549
- if (controller.handleFactoryReset) { // if the controller implements handleFactoryReset, setup event handlers for this controller
550
- controller.handleFactoryReset();
551
- }
552
- if ((0, controller_1.isSerializableController)(controller)) {
553
- this.controllerStorage.purgeControllerData(controller);
554
- }
555
- }
556
- }
557
- handleUpdatedControllerServiceMap(originalServiceMap, updatedServiceMap) {
558
- updatedServiceMap = (0, clone_1.clone)(updatedServiceMap); // clone it so we can alter it
559
- Object.keys(originalServiceMap).forEach(name => {
560
- const service = originalServiceMap[name];
561
- const updatedService = updatedServiceMap[name];
562
- if (service && updatedService) { // we check all names contained in both ServiceMaps for changes
563
- delete originalServiceMap[name]; // delete from original ServiceMap, so it will only contain deleted services at the end
564
- delete updatedServiceMap[name]; // delete from updated ServiceMap, so it will only contain added services at the end
565
- if (service !== updatedService) {
566
- this.removeService(service);
567
- this.addService(updatedService);
568
- }
569
- }
570
- });
571
- // now originalServiceMap contains only deleted services and updateServiceMap only added services
572
- Object.values(originalServiceMap).forEach(service => {
573
- if (service) {
574
- this.removeService(service);
575
- }
576
- });
577
- Object.values(updatedServiceMap).forEach(service => {
578
- if (service) {
579
- this.addService(service);
580
- }
581
- });
582
- }
583
- setupURI() {
584
- if (this._setupURI) {
585
- return this._setupURI;
586
- }
587
- (0, assert_1.default)(!!this._accessoryInfo, "Cannot generate setupURI on an accessory that isn't published yet!");
588
- const buffer = Buffer.alloc(8);
589
- let value_low = parseInt(this._accessoryInfo.pincode.replace(/-/g, ""), 10);
590
- const value_high = this._accessoryInfo.category >> 1;
591
- value_low |= 1 << 28; // Supports IP;
592
- buffer.writeUInt32BE(value_low, 4);
593
- if (this._accessoryInfo.category & 1) {
594
- buffer[4] = buffer[4] | 1 << 7;
595
- }
596
- buffer.writeUInt32BE(value_high, 0);
597
- let encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) * 0x100000000)).toString(36).toUpperCase();
598
- if (encodedPayload.length !== 9) {
599
- for (let i = 0; i <= 9 - encodedPayload.length; i++) {
600
- encodedPayload = "0" + encodedPayload;
601
- }
602
- }
603
- this._setupURI = "X-HM://" + encodedPayload + this._setupID;
604
- return this._setupURI;
605
- }
606
- /**
607
- * Searches this accessory for the first characteristic whose permissions HomeKit would reject, ignoring any bridged accessories (each one is asked
608
- * about itself). The permissions are read from the model on every call rather than remembered, because a plugin can assign `props.perms` directly at
609
- * any time, which reaches neither {@link Characteristic.setProps} nor any event.
610
- *
611
- * @returns the offending characteristic and its service, or undefined if every characteristic on this accessory is well-formed.
612
- */
613
- findPermsViolation() {
614
- for (const service of this.services) {
615
- for (const characteristic of service.characteristics) {
616
- if (!(0, Characteristic_1.isValidPerms)(characteristic.props.perms)) {
617
- return { characteristic: characteristic, service: service };
618
- }
619
- }
620
- }
621
- return undefined;
622
- }
623
- /**
624
- * Describes a permissions violation to the plugin author: which accessory, which service, which characteristic, and the array that was rejected. The
625
- * publish failure and the quarantine warning report the same fault at different boundaries, so they share this text and supply only the phrase that
626
- * says what happened as a result.
627
- *
628
- * @param violation - the violation as returned by {@link findPermsViolation}.
629
- * @param disposition - what became of this accessory, phrased to follow its name.
630
- */
631
- permsViolationMessage(violation, disposition) {
632
- const serviceName = violation.service.displayName || violation.service.constructor.name;
633
- return `HAP-NodeJS: accessory '${this.displayName}' ${disposition}. Service '${serviceName}' (${violation.service.UUID}), `
634
- + `characteristic '${violation.characteristic.displayName}' (${violation.characteristic.UUID}) contains invalid permissions: `
635
- + `${(0, Characteristic_1.describePerms)(violation.characteristic.props.perms)}`;
636
- }
637
- /**
638
- * Returns the bridged accessories fit to be served, excluding any whose characteristic permissions HomeKit would reject. Both representation builders
639
- * go through here, so the accessory database we hand out and the configuration we hash agree by construction, whatever put the malformed permissions
640
- * into the model.
641
- *
642
- * The exclusion is presentation-level and reversible. A quarantined accessory keeps its place in {@link bridgedAccessories}, its aid, its cached
643
- * identifiers and its context, so correcting the permissions restores it exactly where it was, under the same identity HomeKit knew it by.
644
- */
645
- servedBridgedAccessories() {
646
- const served = [];
647
- for (const accessory of this.bridgedAccessories) {
648
- const violation = accessory.findPermsViolation();
649
- if (violation) {
650
- if (!accessory.permsQuarantined) {
651
- accessory.permsQuarantined = true;
652
- accessory.sendCharacteristicWarning(violation.characteristic, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, accessory.permsViolationMessage(violation, "is excluded from the accessory database until its permissions are corrected"));
653
- /* The configuration this accessory contributed has just disappeared from what we serve, so the configuration number has to move. Enqueueing
654
- * from inside a representation build is safe and terminates: the build that observes a transition records it before returning, so the
655
- * debounced pass that follows sees a settled state, hashes it, and enqueues nothing further.
656
- */
657
- this.enqueueConfigurationUpdate();
658
- }
659
- continue;
660
- }
661
- if (accessory.permsQuarantined) {
662
- accessory.permsQuarantined = false;
663
- this.enqueueConfigurationUpdate();
664
- }
665
- served.push(accessory);
666
- }
667
- return served;
668
- }
669
- /**
670
- * This method is called right before the accessory is published. It should be used to check for common
671
- * mistakes in Accessory structured, which may lead to HomeKit rejecting the accessory when pairing.
672
- * If it is called on a bridge it will call this method for all bridged accessories.
673
- */
674
- validateAccessory(mainAccessory) {
675
- const service = this.getService(Service_1.Service.AccessoryInformation);
676
- if (!service) {
677
- console.log("HAP-NodeJS WARNING: The accessory '" + this.displayName + "' is getting published without a AccessoryInformation service. " +
678
- "This might prevent the accessory from being added to the Home app or leading to the accessory being unresponsive!");
679
- }
680
- else {
681
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
682
- const checkValue = (name, value) => {
683
- if (!value) {
684
- console.log("HAP-NodeJS WARNING: The accessory '" + this.displayName + "' is getting published with the characteristic '" + name + "'" +
685
- " (of the AccessoryInformation service) not having a value set. " +
686
- "This might prevent the accessory from being added to the Home App or leading to the accessory being unresponsive!");
687
- }
688
- };
689
- (0, checkName_1.checkName)(this.displayName, "Name", service.getCharacteristic(Characteristic_1.Characteristic.Name).value);
690
- checkValue("FirmwareRevision", service.getCharacteristic(Characteristic_1.Characteristic.FirmwareRevision).value);
691
- checkValue("Manufacturer", service.getCharacteristic(Characteristic_1.Characteristic.Manufacturer).value);
692
- checkValue("Model", service.getCharacteristic(Characteristic_1.Characteristic.Model).value);
693
- checkValue("Name", service.getCharacteristic(Characteristic_1.Characteristic.Name).value);
694
- checkValue("SerialNumber", service.getCharacteristic(Characteristic_1.Characteristic.SerialNumber).value);
695
- }
696
- if (mainAccessory) {
697
- // the main accessory which is advertised via bonjour must have a name with length <= 63 (limitation of DNS FQDN names)
698
- (0, assert_1.default)(Buffer.from(this.displayName, "utf8").length <= 63, "Accessory displayName cannot be longer than 63 bytes!");
699
- }
700
- // any accessories we are bridging are validated the same way; the list is empty for anything that is not a bridge
701
- this.bridgedAccessories.forEach(accessory => accessory.validateAccessory());
702
- }
703
- /**
704
- * Assigns aid/iid to ourselves, any Accessories we are bridging, and all associated Services+Characteristics. Uses
705
- * the provided identifierCache to keep IDs stable.
706
- * @private Private API
707
- */
708
- _assignIDs(identifierCache) {
709
- // if we are responsible for our own identifierCache, start the expiration process
710
- // also check weather we want to have an expiration process
711
- if (this._identifierCache && this.shouldPurgeUnusedIDs) {
712
- this._identifierCache.startTrackingUsage();
713
- }
714
- if (this.bridged) {
715
- // This Accessory is bridged, so it must have an aid > 1. Use the provided identifierCache to
716
- // fetch or assign one based on our UUID.
717
- this.aid = identifierCache.getAID(this.UUID);
718
- }
719
- else {
720
- // Since this Accessory is the server (as opposed to any Accessories that may be bridged behind us),
721
- // we must have aid = 1
722
- this.aid = 1;
723
- }
724
- for (const service of this.services) {
725
- if (this._isBridge) {
726
- service._assignIDs(identifierCache, this.UUID, 2000000000);
727
- }
728
- else {
729
- service._assignIDs(identifierCache, this.UUID);
730
- }
731
- }
732
- // now assign IDs for any Accessories we are bridging
733
- for (const accessory of this.bridgedAccessories) {
734
- accessory._assignIDs(identifierCache);
735
- }
736
- // expire any now-unused cache keys (for Accessories, Services, or Characteristics
737
- // that have been removed since the last call to assignIDs())
738
- if (this._identifierCache) {
739
- //Check weather we want to purge the unused ids
740
- if (this.shouldPurgeUnusedIDs) {
741
- this._identifierCache.stopTrackingUsageAndExpireUnused();
742
- }
743
- //Save in case we have new ones
744
- this._identifierCache.save();
745
- }
746
- }
747
- disableUnusedIDPurge() {
748
- this.shouldPurgeUnusedIDs = false;
749
- }
750
- enableUnusedIDPurge() {
751
- this.shouldPurgeUnusedIDs = true;
752
- }
753
- /**
754
- * Manually purge the unused ids if you like, comes handy
755
- * when you have disabled auto purge, so you can do it manually
756
- */
757
- purgeUnusedIDs() {
758
- //Cache the state of the purge mechanism and set it to true
759
- const oldValue = this.shouldPurgeUnusedIDs;
760
- this.shouldPurgeUnusedIDs = true;
761
- //Reassign all ids
762
- this._assignIDs(this._identifierCache);
763
- // Revert the purge mechanism state
764
- this.shouldPurgeUnusedIDs = oldValue;
765
- }
766
- /**
767
- * Returns a JSON representation of this accessory suitable for delivering to HAP clients.
768
- */
769
- async toHAP(connection, contactGetHandlers = true) {
770
- (0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
771
- (0, assert_1.default)(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
772
- const accessory = {
773
- aid: this.aid,
774
- services: await Promise.all(this.services.map(service => service.toHAP(connection, contactGetHandlers))),
775
- };
776
- const accessories = [accessory];
777
- if (!this.bridged) {
778
- accessories.push(...await Promise.all(this.servedBridgedAccessories()
779
- .map(accessory => accessory.toHAP(connection, contactGetHandlers).then(value => value[0]))));
780
- }
781
- return accessories;
782
- }
783
- /**
784
- * Returns a JSON representation of this accessory without characteristic values.
785
- */
786
- internalHAPRepresentation(assignIds = true) {
787
- if (assignIds) {
788
- this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
789
- }
790
- (0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
791
- (0, assert_1.default)(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
792
- const accessory = {
793
- aid: this.aid,
794
- services: this.services.map(service => service.internalHAPRepresentation()),
795
- };
796
- const accessories = [accessory];
797
- if (!this.bridged) {
798
- for (const accessory of this.servedBridgedAccessories()) {
799
- accessories.push(accessory.internalHAPRepresentation(false)[0]);
800
- }
801
- }
802
- return accessories;
803
- }
804
- /**
805
- * Publishes this accessory on the local network for iOS clients to communicate with.
806
- * - `info.username` - formatted as a MAC address, like `CC:22:3D:E3:CE:F6`, of this accessory.
807
- * Must be globally unique from all Accessories on your local network.
808
- * - `info.pincode` - the 8-digit pin code for clients to use when pairing this Accessory.
809
- * Must be formatted as a string like `031-45-154`.
810
- * - `info.category` - one of the values of the `Accessory.Category` enum, like `Accessory.Category.SWITCH`.
811
- * This is a hint to iOS clients about what "type" of Accessory this represents, so
812
- * that for instance an appropriate icon can be drawn for the user while adding a
813
- * new Accessory.
814
- * @param {{
815
- * username: string;
816
- * pincode: string;
817
- * category: Accessory.Categories;
818
- * }} info - Required info for publishing.
819
- * @param {boolean} allowInsecureRequest - Will allow unencrypted and unauthenticated access to the http server
820
- */
821
- async publish(info, allowInsecureRequest) {
822
- if (this.bridged) {
823
- throw new Error("Can't publish in accessory which is bridged by another accessory. Bridged by " + this.bridge?.displayName);
824
- }
825
- /* Bridged accessories with malformed permissions are quarantined at the serving boundary, but the accessory being published is the root of its own
826
- * accessory database and has nowhere to be quarantined to. HomeKit would reject the whole database, so we refuse here instead, in the caller's stack.
827
- */
828
- const violation = this.findPermsViolation();
829
- if (violation) {
830
- throw new Error(this.permsViolationMessage(violation, "cannot be published"));
831
- }
832
- let service = this.getService(Service_1.Service.ProtocolInformation);
833
- if (!service) {
834
- service = this.addService(Service_1.Service.ProtocolInformation); // add the protocol information service to the primary accessory
835
- }
836
- service.setCharacteristic(Characteristic_1.Characteristic.Version, Advertiser_1.CiaoAdvertiser.protocolVersionService);
837
- hksvDebug("[%s] publish: UUID=%s lastKnownUsername=%s newUsername=%s", this.displayName, this.UUID, this.lastKnownUsername, info.username);
838
- if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
839
- hksvDebug("[%s] publish: wiping data for previous username %s", this.displayName, this.lastKnownUsername);
840
- Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
841
- }
842
- if (!this.initialized && (info.addIdentifyingMaterial ?? true)) {
843
- // adding some identifying material to our displayName if it's our first publish() call
844
- this.displayName = this.displayName + " " + crypto_1.default.createHash("sha512")
845
- .update(info.username, "utf8")
846
- .digest("hex").slice(0, 4).toUpperCase();
847
- this.getService(Service_1.Service.AccessoryInformation).updateCharacteristic(Characteristic_1.Characteristic.Name, this.displayName);
848
- }
849
- // attempt to load existing AccessoryInfo from disk
850
- this._accessoryInfo = AccessoryInfo_1.AccessoryInfo.load(info.username);
851
- // if we don't have one, create a new one.
852
- if (!this._accessoryInfo) {
853
- debug("[%s] Creating new AccessoryInfo for our HAP server", this.displayName);
854
- this._accessoryInfo = AccessoryInfo_1.AccessoryInfo.create(info.username);
855
- }
856
- if (info.setupID) {
857
- this._setupID = info.setupID;
858
- }
859
- else if (this._accessoryInfo.setupID === undefined || this._accessoryInfo.setupID === "") {
860
- this._setupID = Accessory._generateSetupID();
861
- }
862
- else {
863
- this._setupID = this._accessoryInfo.setupID;
864
- }
865
- this._accessoryInfo.setupID = this._setupID;
866
- // make sure we have up-to-date values in AccessoryInfo, then save it in case they changed (or if we just created it)
867
- this._accessoryInfo.displayName = this.displayName;
868
- this._accessoryInfo.model = this.getService(Service_1.Service.AccessoryInformation).getCharacteristic(Characteristic_1.Characteristic.Model).value;
869
- this._accessoryInfo.category = info.category || 1 /* Categories.OTHER */;
870
- this._accessoryInfo.pincode = info.pincode;
871
- this._accessoryInfo.save();
872
- // create our IdentifierCache, so we can provide clients with stable aid/iid's
873
- this._identifierCache = IdentifierCache_1.IdentifierCache.load(info.username);
874
- // if we don't have one, create a new one.
875
- if (!this._identifierCache) {
876
- debug("[%s] Creating new IdentifierCache", this.displayName);
877
- this._identifierCache = new IdentifierCache_1.IdentifierCache(info.username);
878
- }
879
- // If it's bridge and there are no accessories already assigned to the bridge
880
- // probably purge is not needed since it's going to delete all the ids
881
- // of accessories that might be added later. Useful when dynamically adding
882
- // accessories.
883
- if (this._isBridge && this.bridgedAccessories.length === 0) {
884
- this.disableUnusedIDPurge();
885
- this.controllerStorage.purgeUnidentifiedAccessoryData = false;
886
- }
887
- if (!this.initialized) { // controller storage is only loaded from disk the first time we publish!
888
- this.controllerStorage.load(info.username); // initializing controller data
889
- }
890
- // assign aid/iid
891
- this._assignIDs(this._identifierCache);
892
- // get our accessory information in HAP format and determine if our configuration (that is, our
893
- // Accessories/Services/Characteristics) has changed since the last time we were published. make
894
- // sure to omit actual values since these are not part of the "configuration".
895
- const config = this.internalHAPRepresentation(false); // TODO ensure this stuff is ordered
896
- // TODO queue this check until about 5 seconds after startup, allowing some last changes after the publish call
897
- // without constantly incrementing the current config number
898
- this._accessoryInfo.checkForCurrentConfigurationNumberIncrement(config, true);
899
- this.validateAccessory(true);
900
- // create our Advertiser which broadcasts our presence over mdns
901
- const parsed = Accessory.parseBindOption(info);
902
- info.advertiser ??= "ciao" /* MDNSAdvertiser.CIAO */;
903
- if ((info.advertiser === "avahi" /* MDNSAdvertiser.AVAHI */ && !await Advertiser_1.AvahiAdvertiser.isAvailable()) ||
904
- (info.advertiser === "resolved" /* MDNSAdvertiser.RESOLVED */ && !await Advertiser_1.ResolvedAdvertiser.isAvailable())) {
905
- console.error(`[${this.displayName}] The selected advertiser, "${info.advertiser}", isn't available on this platform. ` +
906
- `Reverting to "${"ciao" /* MDNSAdvertiser.CIAO */}"`);
907
- info.advertiser = "ciao" /* MDNSAdvertiser.CIAO */;
908
- }
909
- switch (info.advertiser) {
910
- case "ciao" /* MDNSAdvertiser.CIAO */:
911
- this._advertiser = new Advertiser_1.CiaoAdvertiser(this._accessoryInfo, {
912
- interface: parsed.advertiserAddress,
913
- }, {
914
- restrictedAddresses: parsed.serviceRestrictedAddress,
915
- disabledIpv6: parsed.serviceDisableIpv6,
916
- });
917
- break;
918
- case "bonjour-hap" /* MDNSAdvertiser.BONJOUR */:
919
- this._advertiser = new Advertiser_1.BonjourHAPAdvertiser(this._accessoryInfo, {
920
- restrictedAddresses: parsed.serviceRestrictedAddress,
921
- disabledIpv6: parsed.serviceDisableIpv6,
922
- });
923
- break;
924
- case "avahi" /* MDNSAdvertiser.AVAHI */:
925
- this._advertiser = new Advertiser_1.AvahiAdvertiser(this._accessoryInfo);
926
- break;
927
- case "resolved" /* MDNSAdvertiser.RESOLVED */:
928
- this._advertiser = new Advertiser_1.ResolvedAdvertiser(this._accessoryInfo);
929
- break;
930
- default:
931
- throw new Error("Unsupported advertiser setting: '" + info.advertiser + "'");
932
- }
933
- this._advertiser.on("updated-name" /* AdvertiserEvent.UPDATED_NAME */, name => {
934
- this.displayName = name;
935
- if (this._accessoryInfo) {
936
- this._accessoryInfo.displayName = name;
937
- this._accessoryInfo.save();
938
- }
939
- // bonjour service name MUST match the name in the accessory information service
940
- this.getService(Service_1.Service.AccessoryInformation)
941
- .updateCharacteristic(Characteristic_1.Characteristic.Name, name);
942
- });
943
- // create our HAP server which handles all communication between iOS devices and us
944
- this._server = new HAPServer_1.HAPServer(this._accessoryInfo);
945
- this._server.allowInsecureRequest = !!allowInsecureRequest;
946
- this._server.on("listening" /* HAPServerEventTypes.LISTENING */, this.onListening.bind(this));
947
- this._server.on("identify" /* HAPServerEventTypes.IDENTIFY */, this.identificationRequest.bind(this, false));
948
- this._server.on("pair" /* HAPServerEventTypes.PAIR */, this.handleInitialPairSetupFinished.bind(this));
949
- this._server.on("add-pairing" /* HAPServerEventTypes.ADD_PAIRING */, this.handleAddPairing.bind(this));
950
- this._server.on("remove-pairing" /* HAPServerEventTypes.REMOVE_PAIRING */, this.handleRemovePairing.bind(this));
951
- this._server.on("list-pairings" /* HAPServerEventTypes.LIST_PAIRINGS */, this.handleListPairings.bind(this));
952
- this._server.on("accessories" /* HAPServerEventTypes.ACCESSORIES */, this.handleAccessories.bind(this));
953
- this._server.on("get-characteristics" /* HAPServerEventTypes.GET_CHARACTERISTICS */, this.handleGetCharacteristics.bind(this));
954
- this._server.on("set-characteristics" /* HAPServerEventTypes.SET_CHARACTERISTICS */, this.handleSetCharacteristics.bind(this));
955
- this._server.on("connection-closed" /* HAPServerEventTypes.CONNECTION_CLOSED */, this.handleHAPConnectionClosed.bind(this));
956
- this._server.on("request-resource" /* HAPServerEventTypes.REQUEST_RESOURCE */, this.handleResource.bind(this));
957
- this._server.listen(info.port, parsed.serverAddress);
958
- this.initialized = true;
959
- }
960
- /**
961
- * Removes this Accessory from the local network
962
- * Accessory object will no longer valid after invoking this method
963
- * Trying to invoke publish() on the object will result undefined behavior
964
- */
965
- destroy() {
966
- const promise = this.unpublish();
967
- if (this._accessoryInfo) {
968
- Accessory.cleanupAccessoryData(this._accessoryInfo.username);
969
- this._accessoryInfo = undefined;
970
- this._identifierCache = undefined;
971
- this.controllerStorage = new ControllerStorage_1.ControllerStorage(this);
972
- }
973
- this.removeAllListeners();
974
- return promise;
975
- }
976
- async unpublish() {
977
- if (this._server) {
978
- this._server.destroy();
979
- this._server = undefined;
980
- }
981
- if (this._advertiser) {
982
- // noinspection JSIgnoredPromiseFromCall
983
- await this._advertiser.destroy();
984
- this._advertiser = undefined;
985
- }
986
- }
987
- enqueueConfigurationUpdate() {
988
- if (this.configurationChangeDebounceTimeout) {
989
- return; // already enqueued
990
- }
991
- this.configurationChangeDebounceTimeout = setTimeout(() => {
992
- this.configurationChangeDebounceTimeout = undefined;
993
- if (this._advertiser) {
994
- // get our accessory information in HAP format and determine if our configuration (that is, our
995
- // Accessories/Services/Characteristics) has changed since the last time we were published. make
996
- // sure to omit actual values since these are not part of the "configuration".
997
- const config = this.internalHAPRepresentation(); // TODO ensure this stuff is ordered
998
- if (this._accessoryInfo?.checkForCurrentConfigurationNumberIncrement(config)) {
999
- this._advertiser.updateAdvertisement();
1000
- }
1001
- }
1002
- }, 1000);
1003
- this.configurationChangeDebounceTimeout.unref();
1004
- // 1s is fine, HomeKit is built that with configuration updates no iid or aid conflicts occur.
1005
- // Thus, the only thing happening when the txt update arrives late is already removed accessories/services
1006
- // not responding or new accessories/services not yet shown
1007
- }
1008
- onListening(port, hostname) {
1009
- (0, assert_1.default)(this._advertiser, "Advertiser wasn't created at onListening!");
1010
- // the HAP server is listening, so we can now start advertising our presence.
1011
- this._advertiser.initPort(port);
1012
- this._advertiser.startAdvertising()
1013
- .then(() => this.emit("advertised" /* AccessoryEventTypes.ADVERTISED */))
1014
- .catch(reason => {
1015
- console.error("Could not create mDNS advertisement. The HAP-Server won't be discoverable: " + reason);
1016
- if (reason.stack) {
1017
- debug("Detailed error: " + reason.stack);
1018
- }
1019
- });
1020
- this.emit("listening" /* AccessoryEventTypes.LISTENING */, port, hostname);
1021
- }
1022
- handleInitialPairSetupFinished(username, publicKey, callback) {
1023
- debug("[%s] Paired with client %s", this.displayName, username);
1024
- if (this._accessoryInfo) {
1025
- this._accessoryInfo.addPairedClient(username, publicKey, 1 /* PermissionTypes.ADMIN */);
1026
- this._accessoryInfo.save();
1027
- }
1028
- // update our advertisement, so it can pick up on the paired status of AccessoryInfo
1029
- if (this._advertiser) {
1030
- this._advertiser.updateAdvertisement();
1031
- }
1032
- callback();
1033
- this.emit("paired" /* AccessoryEventTypes.PAIRED */);
1034
- }
1035
- handleAddPairing(connection, username, publicKey, permission, callback) {
1036
- if (!this._accessoryInfo) {
1037
- callback(6 /* TLVErrorCode.UNAVAILABLE */);
1038
- return;
1039
- }
1040
- if (!this._accessoryInfo.hasAdminPermissions(connection.username)) {
1041
- callback(2 /* TLVErrorCode.AUTHENTICATION */);
1042
- return;
1043
- }
1044
- const existingKey = this._accessoryInfo.getClientPublicKey(username);
1045
- if (existingKey) {
1046
- if (existingKey.toString() !== publicKey.toString()) {
1047
- callback(1 /* TLVErrorCode.UNKNOWN */);
1048
- return;
1049
- }
1050
- this._accessoryInfo.updatePermission(username, permission);
1051
- }
1052
- else {
1053
- this._accessoryInfo.addPairedClient(username, publicKey, permission);
1054
- }
1055
- this._accessoryInfo.save();
1056
- // there should be no need to update advertisement
1057
- callback(0);
1058
- }
1059
- handleRemovePairing(connection, username, callback) {
1060
- if (!this._accessoryInfo) {
1061
- callback(6 /* TLVErrorCode.UNAVAILABLE */);
1062
- return;
1063
- }
1064
- if (!this._accessoryInfo.hasAdminPermissions(connection.username)) {
1065
- callback(2 /* TLVErrorCode.AUTHENTICATION */);
1066
- return;
1067
- }
1068
- this._accessoryInfo.removePairedClient(connection, username);
1069
- this._accessoryInfo.save();
1070
- callback(0); // first of all ensure the pairing is removed before we advertise availability again
1071
- if (!this._accessoryInfo.paired()) {
1072
- if (this._advertiser) {
1073
- this._advertiser.updateAdvertisement();
1074
- }
1075
- this.emit("unpaired" /* AccessoryEventTypes.UNPAIRED */);
1076
- this.handleAccessoryUnpairedForControllers();
1077
- for (const accessory of this.bridgedAccessories) {
1078
- accessory.handleAccessoryUnpairedForControllers();
1079
- }
1080
- }
1081
- }
1082
- handleListPairings(connection, callback) {
1083
- if (!this._accessoryInfo) {
1084
- callback(6 /* TLVErrorCode.UNAVAILABLE */);
1085
- return;
1086
- }
1087
- if (!this._accessoryInfo.hasAdminPermissions(connection.username)) {
1088
- callback(2 /* TLVErrorCode.AUTHENTICATION */);
1089
- return;
1090
- }
1091
- callback(0, this._accessoryInfo.listPairings());
1092
- }
1093
- handleAccessories(connection, callback) {
1094
- this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
1095
- const now = Date.now();
1096
- const contactGetHandlers = now - this.lastAccessoriesRequest > 5_000; // we query the latest value if last /accessories was more than 5s ago
1097
- this.lastAccessoriesRequest = now;
1098
- this.toHAP(connection, contactGetHandlers).then(value => {
1099
- callback(undefined, {
1100
- accessories: value,
1101
- });
1102
- }, reason => {
1103
- console.error("[" + this.displayName + "] /accessories request error with: " + reason.stack);
1104
- callback({ httpCode: 500 /* HAPHTTPCode.INTERNAL_SERVER_ERROR */, status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */ });
1105
- });
1106
- }
1107
- handleGetCharacteristics(connection, request, callback) {
1108
- const characteristics = [];
1109
- const response = { characteristics: characteristics };
1110
- const missingCharacteristics = new Set(request.ids.map(id => id.aid + "." + id.iid));
1111
- if (missingCharacteristics.size !== request.ids.length) {
1112
- // if those sizes differ, we have duplicates and can't properly handle that
1113
- callback({ httpCode: 422 /* HAPHTTPCode.UNPROCESSABLE_ENTITY */, status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ });
1114
- return;
1115
- }
1116
- let timeout = setTimeout(() => {
1117
- for (const id of missingCharacteristics) {
1118
- const split = id.split(".");
1119
- const aid = parseInt(split[0], 10);
1120
- const iid = parseInt(split[1], 10);
1121
- const accessory = this.getAccessoryByAID(aid);
1122
- const characteristic = accessory?.getCharacteristicByIID(iid);
1123
- if (!accessory || !characteristic) {
1124
- continue;
1125
- }
1126
- this.sendCharacteristicWarning(characteristic, "slow-read" /* CharacteristicWarningType.SLOW_READ */, "The read handler for the characteristic '" +
1127
- characteristic.displayName + "' on the accessory '" + accessory.displayName + "' was slow to respond!");
1128
- }
1129
- // after a total of 10s we do no longer wait for a request to appear and just return status code timeout
1130
- timeout = setTimeout(() => {
1131
- timeout = undefined;
1132
- for (const id of missingCharacteristics) {
1133
- const split = id.split(".");
1134
- const aid = parseInt(split[0], 10);
1135
- const iid = parseInt(split[1], 10);
1136
- const accessory = this.getAccessoryByAID(aid);
1137
- const characteristic = accessory?.getCharacteristicByIID(iid);
1138
- if (!accessory || !characteristic) {
1139
- continue;
1140
- }
1141
- this.sendCharacteristicWarning(characteristic, "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */, "The read handler for the characteristic '" +
1142
- characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!. " +
1143
- "Please check that you properly call the callback!");
1144
- characteristics.push({
1145
- aid: aid,
1146
- iid: iid,
1147
- status: -70408 /* HAPStatus.OPERATION_TIMED_OUT */,
1148
- });
1149
- }
1150
- missingCharacteristics.clear();
1151
- callback(undefined, response);
1152
- }, Accessory.TIMEOUT_AFTER_WARNING);
1153
- timeout.unref();
1154
- }, Accessory.TIMEOUT_WARNING);
1155
- timeout.unref();
1156
- for (const id of request.ids) {
1157
- const name = id.aid + "." + id.iid;
1158
- this.handleCharacteristicRead(connection, id, request).then(value => {
1159
- return {
1160
- aid: id.aid,
1161
- iid: id.iid,
1162
- ...value,
1163
- };
1164
- }, reason => {
1165
- console.error(`[${this.displayName}] Read request for characteristic ${name} encountered an error: ${reason.stack}`);
1166
- return {
1167
- aid: id.aid,
1168
- iid: id.iid,
1169
- status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */,
1170
- };
1171
- }).then(value => {
1172
- if (!timeout) {
1173
- return; // if timeout is undefined, response was already sent out
1174
- }
1175
- missingCharacteristics.delete(name);
1176
- characteristics.push(value);
1177
- if (missingCharacteristics.size === 0) {
1178
- if (timeout) {
1179
- clearTimeout(timeout);
1180
- timeout = undefined;
1181
- }
1182
- callback(undefined, response);
1183
- }
1184
- });
1185
- }
1186
- }
1187
- async handleCharacteristicRead(connection, id, request) {
1188
- const characteristic = this.findCharacteristic(id.aid, id.iid);
1189
- if (!characteristic) {
1190
- debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, id.aid, id.iid);
1191
- return { status: 0 /* HAPStatus.SUCCESS */, value: "" };
1192
- }
1193
- if (!characteristic.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if read is allowed for this characteristic
1194
- debug("[%s] Tried reading from characteristic which does not allow reading (aid of %s and iid of %s)", this.displayName, id.aid, id.iid);
1195
- return { status: -70405 /* HAPStatus.WRITE_ONLY_CHARACTERISTIC */ };
1196
- }
1197
- if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(0 /* Access.READ */)) {
1198
- const verifiable = this._accessoryInfo && connection.username;
1199
- if (!verifiable) {
1200
- 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);
1201
- }
1202
- if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1203
- return { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ };
1204
- }
1205
- }
1206
- return characteristic.handleGetRequest(connection).then(value => {
1207
- value = (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props);
1208
- debug("[%s] Got Characteristic \"%s\" value: \"%s\"", this.displayName, characteristic.displayName, value);
1209
- const data = {
1210
- value: value == null ? null : value,
1211
- };
1212
- if (request.includeMeta) {
1213
- data.format = characteristic.props.format;
1214
- data.unit = characteristic.props.unit;
1215
- data.minValue = characteristic.props.minValue;
1216
- data.maxValue = characteristic.props.maxValue;
1217
- data.minStep = characteristic.props.minStep;
1218
- data.maxLen = characteristic.props.maxLen || characteristic.props.maxDataLen;
1219
- }
1220
- if (request.includePerms) {
1221
- data.perms = characteristic.props.perms;
1222
- }
1223
- if (request.includeType) {
1224
- data.type = (0, uuid_1.toShortForm)(characteristic.UUID);
1225
- }
1226
- if (request.includeEvent) {
1227
- data.ev = connection.hasEventNotifications(id.aid, id.iid);
1228
- }
1229
- return data;
1230
- }, (reason) => {
1231
- // @ts-expect-error: preserveConstEnums compiler option
1232
- debug("[%s] Error getting value for characteristic \"%s\": %s", this.displayName, characteristic.displayName, HAPServer_1.HAPStatus[reason]);
1233
- return { status: reason };
1234
- });
1235
- }
1236
- handleSetCharacteristics(connection, writeRequest, callback) {
1237
- debug("[%s] Processing characteristic set: %s", this.displayName, JSON.stringify(writeRequest));
1238
- console.info("[HK4K-HAP-DIAG] characteristic-write", JSON.stringify({
1239
- remote: connection.remoteAddress,
1240
- camera: this.displayName,
1241
- characteristics: writeRequest.characteristics.map(data => {
1242
- const characteristic = this.findCharacteristic(data.aid, data.iid);
1243
- return {
1244
- aid: data.aid,
1245
- iid: data.iid,
1246
- name: characteristic?.displayName ?? "unknown",
1247
- uuid: characteristic?.UUID,
1248
- write: data.value !== undefined,
1249
- event: data.ev === undefined ? undefined : data.ev,
1250
- valueType: data.value === undefined ? undefined : Array.isArray(data.value) ? "array" : typeof data.value,
1251
- };
1252
- }),
1253
- }));
1254
- let writeState = 0 /* WriteRequestState.REGULAR_REQUEST */;
1255
- if (writeRequest.pid !== undefined) { // check for timed writes
1256
- if (connection.timedWritePid === writeRequest.pid) {
1257
- writeState = 1 /* WriteRequestState.TIMED_WRITE_AUTHENTICATED */;
1258
- clearTimeout(connection.timedWriteTimeout);
1259
- connection.timedWritePid = undefined;
1260
- connection.timedWriteTimeout = undefined;
1261
- debug("[%s] Timed write request got acknowledged for pid %d", this.displayName, writeRequest.pid);
1262
- }
1263
- else {
1264
- writeState = 2 /* WriteRequestState.TIMED_WRITE_REJECTED */;
1265
- debug("[%s] TTL for timed write request has probably expired for pid %d", this.displayName, writeRequest.pid);
1266
- }
1267
- }
1268
- const characteristics = [];
1269
- const response = { characteristics: characteristics };
1270
- const missingCharacteristics = new Set(writeRequest.characteristics
1271
- .map(characteristic => characteristic.aid + "." + characteristic.iid));
1272
- if (missingCharacteristics.size !== writeRequest.characteristics.length) {
1273
- // if those sizes differ, we have duplicates and can't properly handle that
1274
- callback({ httpCode: 422 /* HAPHTTPCode.UNPROCESSABLE_ENTITY */, status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ });
1275
- return;
1276
- }
1277
- let timeout = setTimeout(() => {
1278
- for (const id of missingCharacteristics) {
1279
- const split = id.split(".");
1280
- const aid = parseInt(split[0], 10);
1281
- const iid = parseInt(split[1], 10);
1282
- const accessory = this.getAccessoryByAID(aid);
1283
- const characteristic = accessory?.getCharacteristicByIID(iid);
1284
- if (!accessory || !characteristic) {
1285
- continue;
1286
- }
1287
- this.sendCharacteristicWarning(characteristic, "slow-write" /* CharacteristicWarningType.SLOW_WRITE */, "The write handler for the characteristic '" +
1288
- characteristic.displayName + "' on the accessory '" + accessory.displayName + "' was slow to respond!");
1289
- }
1290
- // after a total of 10s we do no longer wait for a request to appear and just return status code timeout
1291
- timeout = setTimeout(() => {
1292
- timeout = undefined;
1293
- for (const id of missingCharacteristics) {
1294
- const split = id.split(".");
1295
- const aid = parseInt(split[0], 10);
1296
- const iid = parseInt(split[1], 10);
1297
- const accessory = this.getAccessoryByAID(aid);
1298
- const characteristic = accessory?.getCharacteristicByIID(iid);
1299
- if (!accessory || !characteristic) {
1300
- continue;
1301
- }
1302
- this.sendCharacteristicWarning(characteristic, "timeout-write" /* CharacteristicWarningType.TIMEOUT_WRITE */, "The write handler for the characteristic '" +
1303
- characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!. " +
1304
- "Please check that you properly call the callback!");
1305
- characteristics.push({
1306
- aid: aid,
1307
- iid: iid,
1308
- status: -70408 /* HAPStatus.OPERATION_TIMED_OUT */,
1309
- });
1310
- }
1311
- missingCharacteristics.clear();
1312
- callback(undefined, response);
1313
- }, Accessory.TIMEOUT_AFTER_WARNING);
1314
- timeout.unref();
1315
- }, Accessory.TIMEOUT_WARNING);
1316
- timeout.unref();
1317
- for (const data of writeRequest.characteristics) {
1318
- const name = data.aid + "." + data.iid;
1319
- this.handleCharacteristicWrite(connection, data, writeState).then(value => {
1320
- return {
1321
- aid: data.aid,
1322
- iid: data.iid,
1323
- ...value,
1324
- };
1325
- }, reason => {
1326
- console.error(`[${this.displayName}] Write request for characteristic ${name} encountered an error: ${reason.stack}`);
1327
- return {
1328
- aid: data.aid,
1329
- iid: data.iid,
1330
- status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */,
1331
- };
1332
- }).then(value => {
1333
- if (!timeout) {
1334
- return; // if timeout is undefined, response was already sent out
1335
- }
1336
- const writtenCharacteristic = this.findCharacteristic(data.aid, data.iid);
1337
- console.info("[HK4K-HAP-DIAG] characteristic-result", JSON.stringify({
1338
- remote: connection.remoteAddress,
1339
- aid: data.aid,
1340
- iid: data.iid,
1341
- name: writtenCharacteristic?.displayName ?? "unknown",
1342
- uuid: writtenCharacteristic?.UUID,
1343
- status: value.status ?? 0,
1344
- }));
1345
- missingCharacteristics.delete(name);
1346
- characteristics.push(value);
1347
- if (missingCharacteristics.size === 0) { // if everything returned send the response
1348
- if (timeout) {
1349
- clearTimeout(timeout);
1350
- timeout = undefined;
1351
- }
1352
- callback(undefined, response);
1353
- }
1354
- });
1355
- }
1356
- }
1357
- async handleCharacteristicWrite(connection, data, writeState) {
1358
- const characteristic = this.findCharacteristic(data.aid, data.iid);
1359
- if (!characteristic) {
1360
- debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, data.aid, data.iid);
1361
- return { status: 0 /* HAPStatus.SUCCESS */ };
1362
- }
1363
- if (writeState === 2 /* WriteRequestState.TIMED_WRITE_REJECTED */) {
1364
- return { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ };
1365
- }
1366
- if (data.ev == null && data.value == null) {
1367
- return { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ };
1368
- }
1369
- if (data.ev != null) { // register/unregister event notifications
1370
- if (!characteristic.props.perms.includes("ev" /* Perms.NOTIFY */)) { // check if notify is allowed for this characteristic
1371
- 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);
1372
- return { status: -70406 /* HAPStatus.NOTIFICATION_NOT_SUPPORTED */ };
1373
- }
1374
- if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* Access.NOTIFY */)) {
1375
- const verifiable = connection.username && this._accessoryInfo;
1376
- if (!verifiable) {
1377
- 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);
1378
- }
1379
- if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1380
- return { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ };
1381
- }
1382
- }
1383
- const notificationsEnabled = connection.hasEventNotifications(data.aid, data.iid);
1384
- if (data.ev && !notificationsEnabled) {
1385
- connection.enableEventNotifications(data.aid, data.iid);
1386
- characteristic.subscribe();
1387
- debug("[%s] Registered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
1388
- }
1389
- else if (!data.ev && notificationsEnabled) {
1390
- characteristic.unsubscribe();
1391
- connection.disableEventNotifications(data.aid, data.iid);
1392
- debug("[%s] Unregistered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
1393
- }
1394
- // response is returned below in the else block
1395
- }
1396
- if (data.value != null) {
1397
- if (!characteristic.props.perms.includes("pw" /* Perms.PAIRED_WRITE */)) { // check if write is allowed for this characteristic
1398
- debug("[%s] Tried writing to Characteristic which does not allow writing (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
1399
- return { status: -70404 /* HAPStatus.READ_ONLY_CHARACTERISTIC */ };
1400
- }
1401
- if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(1 /* Access.WRITE */)) {
1402
- const verifiable = connection.username && this._accessoryInfo;
1403
- if (!verifiable) {
1404
- 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);
1405
- }
1406
- if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
1407
- return { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ };
1408
- }
1409
- }
1410
- if (characteristic.props.perms.includes("aa" /* Perms.ADDITIONAL_AUTHORIZATION */) && characteristic.additionalAuthorizationHandler) {
1411
- // if the characteristic "supports additional authorization" but doesn't define a handler for the check
1412
- // we conclude that the characteristic doesn't want to check the authData (currently) and just allows access for everybody
1413
- let allowWrite;
1414
- try {
1415
- allowWrite = characteristic.additionalAuthorizationHandler(data.authData);
1416
- }
1417
- catch (error) {
1418
- console.warn("[" + this.displayName + "] Additional authorization handler has thrown an error when checking authData: " + error.stack);
1419
- allowWrite = false;
1420
- }
1421
- if (!allowWrite) {
1422
- return { status: -70411 /* HAPStatus.INSUFFICIENT_AUTHORIZATION */ };
1423
- }
1424
- }
1425
- if (characteristic.props.perms.includes("tw" /* Perms.TIMED_WRITE */) && writeState !== 1 /* WriteRequestState.TIMED_WRITE_AUTHENTICATED */) {
1426
- 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);
1427
- return { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ };
1428
- }
1429
- return characteristic.handleSetRequest(data.value, connection).then(value => {
1430
- debug("[%s] Setting Characteristic \"%s\" to value %s", this.displayName, characteristic.displayName, data.value);
1431
- return {
1432
- // if write response is requests and value is provided, return that
1433
- value: data.r && value ? (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props) : undefined,
1434
- status: 0 /* HAPStatus.SUCCESS */,
1435
- };
1436
- }, (status) => {
1437
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1438
- debug("[%s] Error setting Characteristic \"%s\" to value %s: ", this.displayName, characteristic.displayName, data.value, HAPServer_1.HAPStatus[status]);
1439
- return { status: status };
1440
- });
1441
- }
1442
- return { status: 0 /* HAPStatus.SUCCESS */ };
1443
- }
1444
- handleResource(data, callback) {
1445
- if (data["resource-type"] === "image" /* ResourceRequestType.IMAGE */) {
1446
- const aid = data.aid; // aid is optionally supplied by HomeKit (for example when camera is bridged, multiple cams, etc)
1447
- let accessory = undefined;
1448
- let controller = undefined;
1449
- if (aid) {
1450
- accessory = this.getAccessoryByAID(aid);
1451
- if (accessory && accessory.activeCameraController) {
1452
- controller = accessory.activeCameraController;
1453
- }
1454
- }
1455
- else if (this.activeCameraController) { // aid was not supplied, check if this accessory is a camera
1456
- // eslint-disable-next-line @typescript-eslint/no-this-alias
1457
- accessory = this;
1458
- controller = this.activeCameraController;
1459
- }
1460
- if (!controller) {
1461
- debug("[%s] received snapshot request though no camera controller was associated!");
1462
- callback({ httpCode: 404 /* HAPHTTPCode.NOT_FOUND */, status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ });
1463
- return;
1464
- }
1465
- controller.handleSnapshotRequest(data["image-height"], data["image-width"], accessory?.displayName, data.reason)
1466
- .then(buffer => {
1467
- callback(undefined, buffer);
1468
- }, (status) => {
1469
- callback({ httpCode: 207 /* HAPHTTPCode.MULTI_STATUS */, status: status });
1470
- });
1471
- return;
1472
- }
1473
- debug("[%s] received request for unsupported image type: " + data["resource-type"], this._accessoryInfo?.username);
1474
- callback({ httpCode: 404 /* HAPHTTPCode.NOT_FOUND */, status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ });
1475
- }
1476
- handleHAPConnectionClosed(connection) {
1477
- for (const event of connection.getRegisteredEvents()) {
1478
- const ids = event.split(".");
1479
- if (ids.length < 2) {
1480
- continue;
1481
- }
1482
- const aid = parseInt(ids[0], 10);
1483
- const iid = parseInt(ids[1], 10);
1484
- const characteristic = this.findCharacteristic(aid, iid);
1485
- if (characteristic) {
1486
- characteristic.unsubscribe();
1487
- }
1488
- }
1489
- connection.clearRegisteredEvents();
1490
- }
1491
- handleServiceConfigurationChangeEvent(service) {
1492
- if (!service.isPrimaryService && service === this.primaryService) {
1493
- // service changed form primary to non-primary service
1494
- this.primaryService = undefined;
1495
- }
1496
- else if (service.isPrimaryService && service !== this.primaryService) {
1497
- // service changed from non-primary to primary service
1498
- if (this.primaryService !== undefined) {
1499
- this.primaryService.isPrimaryService = false;
1500
- }
1501
- this.primaryService = service;
1502
- }
1503
- if (this.bridged) {
1504
- this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service: service });
1505
- }
1506
- else {
1507
- this.enqueueConfigurationUpdate();
1508
- }
1509
- }
1510
- handleCharacteristicChangeEvent(accessory, service, change) {
1511
- if (this.bridged) { // forward this to our main accessory
1512
- this.emit("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, { ...change, service: service });
1513
- }
1514
- else {
1515
- if (!this._server) {
1516
- return; // we're not running a HAPServer, so there's no one to notify about this event
1517
- }
1518
- if (accessory.aid == null || change.characteristic.iid == null) {
1519
- debug("[%s] Muting event notification for %s as ids aren't yet assigned!", accessory.displayName, change.characteristic.displayName);
1520
- return;
1521
- }
1522
- if (change.context != null && typeof change.context === "object" && change.context.omitEventUpdate) {
1523
- debug("[%s] Omitting event updates for %s as specified in the context object!", accessory.displayName, change.characteristic.displayName);
1524
- return;
1525
- }
1526
- if (!(change.reason === "event" /* ChangeReason.EVENT */ || change.oldValue !== change.newValue
1527
- || change.characteristic.UUID === Characteristic_1.Characteristic.ProgrammableSwitchEvent.UUID // those specific checks are out of backwards compatibility
1528
- || change.characteristic.UUID === Characteristic_1.Characteristic.ButtonEvent.UUID // new characteristics should use sendEventNotification call
1529
- )) {
1530
- // we only emit a change event if the reason was a call to sendEventNotification, if the value changed
1531
- // as of a write request or a read request or if the change happened on dedicated event characteristics
1532
- // otherwise we ignore this change event (with the return below)
1533
- return;
1534
- }
1535
- const uuid = change.characteristic.UUID;
1536
- const immediateDelivery = uuid === Characteristic_1.Characteristic.ButtonEvent.UUID || uuid === Characteristic_1.Characteristic.ProgrammableSwitchEvent.UUID
1537
- || uuid === Characteristic_1.Characteristic.MotionDetected.UUID || uuid === Characteristic_1.Characteristic.ContactSensorState.UUID;
1538
- const value = (0, request_util_1.formatOutgoingCharacteristicValue)(change.newValue, change.characteristic.props);
1539
- this._server.sendEventNotifications(accessory.aid, change.characteristic.iid, value, change.originator, immediateDelivery);
1540
- }
1541
- }
1542
- sendCharacteristicWarning(characteristic, type, message) {
1543
- this.handleCharacteristicWarning({
1544
- characteristic: characteristic,
1545
- type: type,
1546
- message: message,
1547
- originatorChain: [characteristic.displayName], // we are missing the service displayName, but that's okay
1548
- stack: new Error().stack,
1549
- });
1550
- }
1551
- handleCharacteristicWarning(warning) {
1552
- warning.originatorChain = [this.displayName, ...warning.originatorChain];
1553
- const emitted = this.emit("characteristic-warning" /* AccessoryEventTypes.CHARACTERISTIC_WARNING */, warning);
1554
- if (!emitted) {
1555
- const message = `[${warning.originatorChain.join("@")}] ${warning.message}`;
1556
- if (warning.type === "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */
1557
- || warning.type === "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */ || warning.type === "timeout-write" /* CharacteristicWarningType.TIMEOUT_WRITE */) {
1558
- console.error(message);
1559
- }
1560
- else {
1561
- console.warn(message);
1562
- }
1563
- debug("[%s] Above characteristic warning was thrown at: %s", this.displayName, warning.stack ?? "unknown");
1564
- }
1565
- }
1566
- setupServiceEventHandlers(service) {
1567
- service.on("service-configurationChange" /* ServiceEventTypes.SERVICE_CONFIGURATION_CHANGE */, this.handleServiceConfigurationChangeEvent.bind(this, service));
1568
- service.on("characteristic-change" /* ServiceEventTypes.CHARACTERISTIC_CHANGE */, this.handleCharacteristicChangeEvent.bind(this, this, service));
1569
- service.on("characteristic-warning" /* ServiceEventTypes.CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
1570
- }
1571
- _sideloadServices(targetServices) {
1572
- for (const service of targetServices) {
1573
- this.setupServiceEventHandlers(service);
1574
- }
1575
- this.services = targetServices.slice();
1576
- // Fix Identify
1577
- this
1578
- .getService(Service_1.Service.AccessoryInformation)
1579
- .getCharacteristic(Characteristic_1.Characteristic.Identify)
1580
- .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
1581
- if (value) {
1582
- const paired = true;
1583
- this.identificationRequest(paired, callback);
1584
- }
1585
- });
1586
- }
1587
- static _generateSetupID() {
1588
- const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1589
- const max = chars.length;
1590
- let setupID = "";
1591
- for (let i = 0; i < 4; i++) {
1592
- const index = Math.floor(Math.random() * max);
1593
- setupID += chars.charAt(index);
1594
- }
1595
- return setupID;
1596
- }
1597
- // serialization and deserialization functions, mainly designed for homebridge to create a json copy to store on disk
1598
- static serialize(accessory) {
1599
- const json = {
1600
- displayName: accessory.displayName,
1601
- UUID: accessory.UUID,
1602
- lastKnownUsername: accessory._accessoryInfo ? accessory._accessoryInfo.username : undefined,
1603
- category: accessory.category,
1604
- services: [],
1605
- };
1606
- const linkedServices = {};
1607
- let hasLinkedServices = false;
1608
- accessory.services.forEach(service => {
1609
- json.services.push(Service_1.Service.serialize(service));
1610
- const linkedServicesPresentation = [];
1611
- service.linkedServices.forEach(linkedService => {
1612
- linkedServicesPresentation.push(linkedService.getServiceId());
1613
- });
1614
- if (linkedServicesPresentation.length > 0) {
1615
- linkedServices[service.getServiceId()] = linkedServicesPresentation;
1616
- hasLinkedServices = true;
1617
- }
1618
- });
1619
- if (hasLinkedServices) {
1620
- json.linkedServices = linkedServices;
1621
- }
1622
- const controllers = [];
1623
- // save controllers
1624
- Object.values(accessory.controllers).forEach((context) => {
1625
- controllers.push({
1626
- type: context.controller.controllerId(),
1627
- services: Accessory.serializeServiceMap(context.serviceMap),
1628
- });
1629
- });
1630
- // also save controller which didn't get initialized (could lead to service duplication if we throw that data away)
1631
- if (accessory.serializedControllers) {
1632
- Object.entries(accessory.serializedControllers).forEach(([id, serviceMap]) => {
1633
- controllers.push({
1634
- type: id,
1635
- services: Accessory.serializeServiceMap(serviceMap),
1636
- });
1637
- });
1638
- }
1639
- if (controllers.length > 0) {
1640
- json.controllers = controllers;
1641
- }
1642
- return json;
1643
- }
1644
- static deserialize(json) {
1645
- const accessory = new Accessory(json.displayName, json.UUID);
1646
- accessory.lastKnownUsername = json.lastKnownUsername;
1647
- accessory.category = json.category;
1648
- const services = [];
1649
- const servicesMap = {};
1650
- json.services.forEach(serialized => {
1651
- const service = Service_1.Service.deserialize(serialized);
1652
- services.push(service);
1653
- servicesMap[service.getServiceId()] = service;
1654
- });
1655
- if (json.linkedServices) {
1656
- for (const [serviceId, linkedServicesKeys] of Object.entries(json.linkedServices)) {
1657
- const primaryService = servicesMap[serviceId];
1658
- if (!primaryService) {
1659
- continue;
1660
- }
1661
- linkedServicesKeys.forEach(linkedServiceKey => {
1662
- const linkedService = servicesMap[linkedServiceKey];
1663
- if (linkedService) {
1664
- primaryService.addLinkedService(linkedService);
1665
- }
1666
- });
1667
- }
1668
- }
1669
- if (json.controllers) { // just save it for later if it exists {@see configureController}
1670
- accessory.serializedControllers = {};
1671
- json.controllers.forEach(serializedController => {
1672
- accessory.serializedControllers[serializedController.type] = Accessory.deserializeServiceMap(serializedController.services, servicesMap);
1673
- });
1674
- }
1675
- accessory._sideloadServices(services);
1676
- return accessory;
1677
- }
1678
- static cleanupAccessoryData(username) {
1679
- IdentifierCache_1.IdentifierCache.remove(username);
1680
- AccessoryInfo_1.AccessoryInfo.remove(username);
1681
- ControllerStorage_1.ControllerStorage.remove(username);
1682
- }
1683
- static serializeServiceMap(serviceMap) {
1684
- const serialized = {};
1685
- Object.entries(serviceMap).forEach(([name, service]) => {
1686
- if (!service) {
1687
- return;
1688
- }
1689
- serialized[name] = service.getServiceId();
1690
- });
1691
- return serialized;
1692
- }
1693
- static deserializeServiceMap(serializedServiceMap, servicesMap) {
1694
- const controllerServiceMap = {};
1695
- Object.entries(serializedServiceMap).forEach(([name, serviceId]) => {
1696
- const service = servicesMap[serviceId];
1697
- if (service) {
1698
- controllerServiceMap[name] = service;
1699
- }
1700
- });
1701
- return controllerServiceMap;
1702
- }
1703
- static parseBindOption(info) {
1704
- let advertiserAddress = undefined;
1705
- let disableIpv6 = undefined;
1706
- let serverAddress = undefined;
1707
- if (info.bind) {
1708
- const entries = new Set(Array.isArray(info.bind) ? info.bind : [info.bind]);
1709
- if (entries.has("::")) {
1710
- serverAddress = "::";
1711
- entries.delete("::");
1712
- if (entries.size) {
1713
- advertiserAddress = Array.from(entries);
1714
- }
1715
- }
1716
- else if (entries.has("0.0.0.0")) {
1717
- disableIpv6 = true;
1718
- serverAddress = "0.0.0.0";
1719
- entries.delete("0.0.0.0");
1720
- if (entries.size) {
1721
- advertiserAddress = Array.from(entries);
1722
- }
1723
- }
1724
- else if (entries.size === 1) {
1725
- advertiserAddress = Array.from(entries);
1726
- const entry = entries.values().next().value; // grab the first one
1727
- const version = net_1.default.isIP(entry); // check if ip address was specified or an interface name
1728
- if (version) {
1729
- serverAddress = version === 4 ? "0.0.0.0" : "::"; // we currently bind to unspecified addresses so config-ui always has a connection via loopback
1730
- }
1731
- else {
1732
- serverAddress = "::"; // the interface could have both ipv4 and ipv6 addresses
1733
- }
1734
- }
1735
- else if (entries.size > 1) {
1736
- advertiserAddress = Array.from(entries);
1737
- let bindUnspecifiedIpv6 = false; // we bind on "::" if there are interface names, or we detect ipv6 addresses
1738
- for (const entry of entries) {
1739
- const version = net_1.default.isIP(entry);
1740
- if (version === 0 || version === 6) {
1741
- bindUnspecifiedIpv6 = true;
1742
- break;
1743
- }
1744
- }
1745
- if (bindUnspecifiedIpv6) {
1746
- serverAddress = "::";
1747
- }
1748
- else {
1749
- serverAddress = "0.0.0.0";
1750
- }
1751
- }
1752
- }
1753
- return {
1754
- advertiserAddress: advertiserAddress,
1755
- serviceRestrictedAddress: advertiserAddress,
1756
- serviceDisableIpv6: disableIpv6,
1757
- serverAddress: serverAddress,
1758
- };
1759
- }
1760
- }
1761
- exports.Accessory = Accessory;
1762
- //# sourceMappingURL=Accessory.js.map