matter-all-in-one-addon 1.8.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +183 -0
  2. package/dist/camera/ai/camera-ai-detector.d.ts +44 -0
  3. package/dist/camera/ai/camera-ai-detector.js +329 -0
  4. package/dist/camera/ai/camera-ai-detector.js.map +1 -0
  5. package/dist/camera/camera-capabilities.d.ts +13 -0
  6. package/dist/camera/camera-capabilities.js +186 -0
  7. package/dist/camera/camera-capabilities.js.map +1 -0
  8. package/dist/camera/camera-source-resolver.d.ts +18 -0
  9. package/dist/camera/camera-source-resolver.js +187 -0
  10. package/dist/camera/camera-source-resolver.js.map +1 -0
  11. package/dist/camera/camera-types.d.ts +124 -0
  12. package/dist/camera/camera-types.js +8 -0
  13. package/dist/camera/camera-types.js.map +1 -0
  14. package/dist/camera/cameraui/cameraui-client.d.ts +54 -0
  15. package/dist/camera/cameraui/cameraui-client.js +698 -0
  16. package/dist/camera/cameraui/cameraui-client.js.map +1 -0
  17. package/dist/camera/cameraui/cameraui-homekit-bridge.d.ts +21 -0
  18. package/dist/camera/cameraui/cameraui-homekit-bridge.js +343 -0
  19. package/dist/camera/cameraui/cameraui-homekit-bridge.js.map +1 -0
  20. package/dist/camera/cameraui/cameraui-storage.d.ts +17 -0
  21. package/dist/camera/cameraui/cameraui-storage.js +916 -0
  22. package/dist/camera/cameraui/cameraui-storage.js.map +1 -0
  23. package/dist/camera/cameraui/cameraui-types.d.ts +89 -0
  24. package/dist/camera/cameraui/cameraui-types.js +5 -0
  25. package/dist/camera/cameraui/cameraui-types.js.map +1 -0
  26. package/dist/camera/homekit/ffmpeg-helper.d.ts +88 -0
  27. package/dist/camera/homekit/ffmpeg-helper.js +673 -0
  28. package/dist/camera/homekit/ffmpeg-helper.js.map +1 -0
  29. package/dist/camera/homekit/fmp4-parser.d.ts +48 -0
  30. package/dist/camera/homekit/fmp4-parser.js +156 -0
  31. package/dist/camera/homekit/fmp4-parser.js.map +1 -0
  32. package/dist/camera/homekit/hevc-eligibility.d.ts +16 -0
  33. package/dist/camera/homekit/hevc-eligibility.js +153 -0
  34. package/dist/camera/homekit/hevc-eligibility.js.map +1 -0
  35. package/dist/camera/homekit/homekit-camera-recording.delegate.d.ts +73 -0
  36. package/dist/camera/homekit/homekit-camera-recording.delegate.js +445 -0
  37. package/dist/camera/homekit/homekit-camera-recording.delegate.js.map +1 -0
  38. package/dist/camera/homekit/homekit-camera-stream.delegate.d.ts +47 -0
  39. package/dist/camera/homekit/homekit-camera-stream.delegate.js +833 -0
  40. package/dist/camera/homekit/homekit-camera-stream.delegate.js.map +1 -0
  41. package/dist/camera/homekit/homekit-camera.accessory.d.ts +53 -0
  42. package/dist/camera/homekit/homekit-camera.accessory.js +697 -0
  43. package/dist/camera/homekit/homekit-camera.accessory.js.map +1 -0
  44. package/dist/camera/matter/camera-endpoint.builder.d.ts +7 -0
  45. package/dist/camera/matter/camera-endpoint.builder.js +127 -0
  46. package/dist/camera/matter/camera-endpoint.builder.js.map +1 -0
  47. package/dist/camera/matter/camera-session-manager.d.ts +46 -0
  48. package/dist/camera/matter/camera-session-manager.js +120 -0
  49. package/dist/camera/matter/camera-session-manager.js.map +1 -0
  50. package/dist/camera/matter/camera-webrtc-adapter.d.ts +62 -0
  51. package/dist/camera/matter/camera-webrtc-adapter.js +298 -0
  52. package/dist/camera/matter/camera-webrtc-adapter.js.map +1 -0
  53. package/dist/camera/motion/ffmpeg-motion-detector.d.ts +46 -0
  54. package/dist/camera/motion/ffmpeg-motion-detector.js +200 -0
  55. package/dist/camera/motion/ffmpeg-motion-detector.js.map +1 -0
  56. package/dist/camera/nest/nest-camera-adapter.d.ts +38 -0
  57. package/dist/camera/nest/nest-camera-adapter.js +109 -0
  58. package/dist/camera/nest/nest-camera-adapter.js.map +1 -0
  59. package/dist/camera/scrypted/scrypted-camera-card.d.ts +39 -0
  60. package/dist/camera/scrypted/scrypted-camera-card.js +38 -0
  61. package/dist/camera/scrypted/scrypted-camera-card.js.map +1 -0
  62. package/dist/camera/scrypted/scrypted-camera-detail.d.ts +33 -0
  63. package/dist/camera/scrypted/scrypted-camera-detail.js +34 -0
  64. package/dist/camera/scrypted/scrypted-camera-detail.js.map +1 -0
  65. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.d.ts +17 -0
  66. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js +24 -0
  67. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js.map +1 -0
  68. package/dist/camera/scrypted/scrypted-camera-normalizer.d.ts +44 -0
  69. package/dist/camera/scrypted/scrypted-camera-normalizer.js +44 -0
  70. package/dist/camera/scrypted/scrypted-camera-normalizer.js.map +1 -0
  71. package/dist/camera/scrypted/scrypted-camera-policy.d.ts +11 -0
  72. package/dist/camera/scrypted/scrypted-camera-policy.js +13 -0
  73. package/dist/camera/scrypted/scrypted-camera-policy.js.map +1 -0
  74. package/dist/camera/scrypted/scrypted-camera-presentation.d.ts +13 -0
  75. package/dist/camera/scrypted/scrypted-camera-presentation.js +23 -0
  76. package/dist/camera/scrypted/scrypted-camera-presentation.js.map +1 -0
  77. package/dist/camera/scrypted/scrypted-client-discovery-adapter.d.ts +6 -0
  78. package/dist/camera/scrypted/scrypted-client-discovery-adapter.js +12 -0
  79. package/dist/camera/scrypted/scrypted-client-discovery-adapter.js.map +1 -0
  80. package/dist/camera/scrypted/scrypted-client.d.ts +152 -0
  81. package/dist/camera/scrypted/scrypted-client.js +1170 -0
  82. package/dist/camera/scrypted/scrypted-client.js.map +1 -0
  83. package/dist/camera/scrypted/scrypted-crypto.d.ts +21 -0
  84. package/dist/camera/scrypted/scrypted-crypto.js +90 -0
  85. package/dist/camera/scrypted/scrypted-crypto.js.map +1 -0
  86. package/dist/camera/scrypted/scrypted-discovery-provider.d.ts +9 -0
  87. package/dist/camera/scrypted/scrypted-discovery-provider.js +25 -0
  88. package/dist/camera/scrypted/scrypted-discovery-provider.js.map +1 -0
  89. package/dist/camera/scrypted/scrypted-homekit-bridge.d.ts +12 -0
  90. package/dist/camera/scrypted/scrypted-homekit-bridge.js +214 -0
  91. package/dist/camera/scrypted/scrypted-homekit-bridge.js.map +1 -0
  92. package/dist/camera/scrypted/scrypted-matter-bridge.d.ts +36 -0
  93. package/dist/camera/scrypted/scrypted-matter-bridge.js +226 -0
  94. package/dist/camera/scrypted/scrypted-matter-bridge.js.map +1 -0
  95. package/dist/camera/scrypted/scrypted-reconnect-manager.d.ts +40 -0
  96. package/dist/camera/scrypted/scrypted-reconnect-manager.js +353 -0
  97. package/dist/camera/scrypted/scrypted-reconnect-manager.js.map +1 -0
  98. package/dist/camera/scrypted/scrypted-runtime-connector.d.ts +7 -0
  99. package/dist/camera/scrypted/scrypted-runtime-connector.js +17 -0
  100. package/dist/camera/scrypted/scrypted-runtime-connector.js.map +1 -0
  101. package/dist/camera/scrypted/scrypted-runtime-facade.d.ts +13 -0
  102. package/dist/camera/scrypted/scrypted-runtime-facade.js +29 -0
  103. package/dist/camera/scrypted/scrypted-runtime-facade.js.map +1 -0
  104. package/dist/camera/scrypted/scrypted-runtime-ingest.d.ts +5 -0
  105. package/dist/camera/scrypted/scrypted-runtime-ingest.js +54 -0
  106. package/dist/camera/scrypted/scrypted-runtime-ingest.js.map +1 -0
  107. package/dist/camera/scrypted/scrypted-storage.d.ts +95 -0
  108. package/dist/camera/scrypted/scrypted-storage.js +698 -0
  109. package/dist/camera/scrypted/scrypted-storage.js.map +1 -0
  110. package/dist/camera/scrypted/scrypted-stream-validator.d.ts +46 -0
  111. package/dist/camera/scrypted/scrypted-stream-validator.js +412 -0
  112. package/dist/camera/scrypted/scrypted-stream-validator.js.map +1 -0
  113. package/dist/camera/scrypted/scrypted-types.d.ts +354 -0
  114. package/dist/camera/scrypted/scrypted-types.js +6 -0
  115. package/dist/camera/scrypted/scrypted-types.js.map +1 -0
  116. package/dist/converters/binary_sensor.converter.d.ts +18 -0
  117. package/dist/converters/binary_sensor.converter.js +21 -0
  118. package/dist/converters/binary_sensor.converter.js.map +1 -0
  119. package/dist/converters/camera.converter.d.ts +18 -0
  120. package/dist/converters/camera.converter.js +24 -0
  121. package/dist/converters/camera.converter.js.map +1 -0
  122. package/dist/converters/climate.converter.d.ts +21 -0
  123. package/dist/converters/climate.converter.js +55 -0
  124. package/dist/converters/climate.converter.js.map +1 -0
  125. package/dist/converters/cover.converter.d.ts +14 -0
  126. package/dist/converters/cover.converter.js +22 -0
  127. package/dist/converters/cover.converter.js.map +1 -0
  128. package/dist/converters/energy_tariff.converter.d.ts +10 -0
  129. package/dist/converters/energy_tariff.converter.js +12 -0
  130. package/dist/converters/energy_tariff.converter.js.map +1 -0
  131. package/dist/converters/fan.converter.d.ts +233 -0
  132. package/dist/converters/fan.converter.js +353 -0
  133. package/dist/converters/fan.converter.js.map +1 -0
  134. package/dist/converters/index.d.ts +14 -0
  135. package/dist/converters/index.js +15 -0
  136. package/dist/converters/index.js.map +1 -0
  137. package/dist/converters/light.converter.d.ts +26 -0
  138. package/dist/converters/light.converter.js +36 -0
  139. package/dist/converters/light.converter.js.map +1 -0
  140. package/dist/converters/lock.converter.d.ts +20 -0
  141. package/dist/converters/lock.converter.js +29 -0
  142. package/dist/converters/lock.converter.js.map +1 -0
  143. package/dist/converters/sensor.converter.d.ts +18 -0
  144. package/dist/converters/sensor.converter.js +33 -0
  145. package/dist/converters/sensor.converter.js.map +1 -0
  146. package/dist/converters/soil_sensor.converter.d.ts +14 -0
  147. package/dist/converters/soil_sensor.converter.js +21 -0
  148. package/dist/converters/soil_sensor.converter.js.map +1 -0
  149. package/dist/converters/vacuum.converter.d.ts +168 -0
  150. package/dist/converters/vacuum.converter.js +288 -0
  151. package/dist/converters/vacuum.converter.js.map +1 -0
  152. package/dist/device-profiles.d.ts +14 -0
  153. package/dist/device-profiles.js +245 -0
  154. package/dist/device-profiles.js.map +1 -0
  155. package/dist/device-registry.d.ts +58 -0
  156. package/dist/device-registry.js +288 -0
  157. package/dist/device-registry.js.map +1 -0
  158. package/dist/entities/base.entity.d.ts +40 -0
  159. package/dist/entities/base.entity.js +826 -0
  160. package/dist/entities/base.entity.js.map +1 -0
  161. package/dist/entities/camera.entity.d.ts +48 -0
  162. package/dist/entities/camera.entity.js +127 -0
  163. package/dist/entities/camera.entity.js.map +1 -0
  164. package/dist/entities/closure.entity.d.ts +9 -0
  165. package/dist/entities/closure.entity.js +52 -0
  166. package/dist/entities/closure.entity.js.map +1 -0
  167. package/dist/entities/composite-device.entity.d.ts +61 -0
  168. package/dist/entities/composite-device.entity.js +986 -0
  169. package/dist/entities/composite-device.entity.js.map +1 -0
  170. package/dist/entities/cooktop.entity.d.ts +20 -0
  171. package/dist/entities/cooktop.entity.js +59 -0
  172. package/dist/entities/cooktop.entity.js.map +1 -0
  173. package/dist/entities/energy_tariff.entity.d.ts +7 -0
  174. package/dist/entities/energy_tariff.entity.js +32 -0
  175. package/dist/entities/energy_tariff.entity.js.map +1 -0
  176. package/dist/entities/humidifier.entity.d.ts +27 -0
  177. package/dist/entities/humidifier.entity.js +187 -0
  178. package/dist/entities/humidifier.entity.js.map +1 -0
  179. package/dist/entities/lock.entity.d.ts +12 -0
  180. package/dist/entities/lock.entity.js +58 -0
  181. package/dist/entities/lock.entity.js.map +1 -0
  182. package/dist/entities/media-player.entity.d.ts +13 -0
  183. package/dist/entities/media-player.entity.js +52 -0
  184. package/dist/entities/media-player.entity.js.map +1 -0
  185. package/dist/entities/oven.entity.d.ts +20 -0
  186. package/dist/entities/oven.entity.js +112 -0
  187. package/dist/entities/oven.entity.js.map +1 -0
  188. package/dist/entities/pet_feeder.entity.d.ts +28 -0
  189. package/dist/entities/pet_feeder.entity.js +67 -0
  190. package/dist/entities/pet_feeder.entity.js.map +1 -0
  191. package/dist/entities/soil_sensor.entity.d.ts +7 -0
  192. package/dist/entities/soil_sensor.entity.js +40 -0
  193. package/dist/entities/soil_sensor.entity.js.map +1 -0
  194. package/dist/entities/vacuum.entity.d.ts +37 -0
  195. package/dist/entities/vacuum.entity.js +352 -0
  196. package/dist/entities/vacuum.entity.js.map +1 -0
  197. package/dist/frontend/assets/index-DPXu3al2.js +26 -0
  198. package/dist/frontend/assets/index-DalMl4eS.css +1 -0
  199. package/dist/frontend/assets/logo-B_gEBugV.png +0 -0
  200. package/dist/frontend/index.html +14 -0
  201. package/dist/frontend/logo.png +0 -0
  202. package/dist/homeAssistant.d.ts +1268 -0
  203. package/dist/homeAssistant.js +1623 -0
  204. package/dist/homeAssistant.js.map +1 -0
  205. package/dist/homekit.compat.d.ts +40 -0
  206. package/dist/homekit.compat.js +43 -0
  207. package/dist/homekit.compat.js.map +1 -0
  208. package/dist/index.d.ts +7 -0
  209. package/dist/index.js +31 -0
  210. package/dist/index.js.map +1 -0
  211. package/dist/mqtt/mqtt-client.d.ts +33 -0
  212. package/dist/mqtt/mqtt-client.js +138 -0
  213. package/dist/mqtt/mqtt-client.js.map +1 -0
  214. package/dist/mqtt/mqtt.entity.d.ts +30 -0
  215. package/dist/mqtt/mqtt.entity.js +286 -0
  216. package/dist/mqtt/mqtt.entity.js.map +1 -0
  217. package/dist/platform.d.ts +318 -0
  218. package/dist/platform.js +6144 -0
  219. package/dist/platform.js.map +1 -0
  220. package/dist/proxy.d.ts +1 -0
  221. package/dist/proxy.js +226 -0
  222. package/dist/proxy.js.map +1 -0
  223. package/dist/utils/ha-discovery.d.ts +30 -0
  224. package/dist/utils/ha-discovery.js +175 -0
  225. package/dist/utils/ha-discovery.js.map +1 -0
  226. package/dist/utils/ha-state.d.ts +48 -0
  227. package/dist/utils/ha-state.js +21 -0
  228. package/dist/utils/ha-state.js.map +1 -0
  229. package/dist/utils/light-color.d.ts +63 -0
  230. package/dist/utils/light-color.js +213 -0
  231. package/dist/utils/light-color.js.map +1 -0
  232. package/dist/utils/log-buffer.d.ts +13 -0
  233. package/dist/utils/log-buffer.js +50 -0
  234. package/dist/utils/log-buffer.js.map +1 -0
  235. package/dist/utils/matter-attributes.d.ts +13 -0
  236. package/dist/utils/matter-attributes.js +35 -0
  237. package/dist/utils/matter-attributes.js.map +1 -0
  238. package/dist/utils/matter-device-identity.d.ts +22 -0
  239. package/dist/utils/matter-device-identity.js +70 -0
  240. package/dist/utils/matter-device-identity.js.map +1 -0
  241. package/dist/utils/thread-credentials.d.ts +22 -0
  242. package/dist/utils/thread-credentials.js +29 -0
  243. package/dist/utils/thread-credentials.js.map +1 -0
  244. package/package.json +80 -0
@@ -0,0 +1,697 @@
1
+ import { Accessory, AccessoryInfo, CameraController, Characteristic, Service, uuid, } from "hap-nodejs";
2
+ import { HomeKitCameraStreamingDelegate } from "./homekit-camera-stream.delegate.js";
3
+ import { HomeKitCameraRecordingDelegate } from "./homekit-camera-recording.delegate.js";
4
+ import crypto from "node:crypto";
5
+ import os from "node:os";
6
+ import { ScryptedStorage } from "../scrypted/scrypted-storage.js";
7
+ import { CameraUiStorage } from "../cameraui/cameraui-storage.js";
8
+ import { probeCameraSource, supportsFdkAac } from "./ffmpeg-helper.js";
9
+ import { NestCameraAdapter } from "../nest/nest-camera-adapter.js";
10
+ export class HomeKitCameraAccessory {
11
+ platform;
12
+ entityId;
13
+ record;
14
+ capabilities;
15
+ streamSource;
16
+ accessory;
17
+ controller;
18
+ delegate;
19
+ recordingDelegate;
20
+ motionService;
21
+ lightService;
22
+ sirenService;
23
+ linkedMotionEntityId;
24
+ linkedLightEntityId;
25
+ linkedSirenEntityId;
26
+ linkedDoorbellEntityId;
27
+ isPublished = false;
28
+ constructor(platform, entityId, record, capabilities, streamSource) {
29
+ this.platform = platform;
30
+ this.entityId = entityId;
31
+ this.record = record;
32
+ this.capabilities = capabilities;
33
+ this.streamSource = streamSource;
34
+ const accessoryUuid = record.uuid || uuid.generate(`homekit:camera:${entityId}`);
35
+ this.record.uuid = accessoryUuid;
36
+ this.accessory = new Accessory(record.name || entityId, accessoryUuid);
37
+ const linked = this.findLinkedEntities();
38
+ this.linkedMotionEntityId =
39
+ this.record.motionEntityId && this.record.motionEntityId !== "auto"
40
+ ? (this.record.motionEntityId === "none" ? undefined : this.record.motionEntityId)
41
+ : (linked.motion || this.findLinkedMotionEntity());
42
+ this.linkedLightEntityId =
43
+ this.record.lightEntityId && this.record.lightEntityId !== "auto"
44
+ ? (this.record.lightEntityId === "none" ? undefined : this.record.lightEntityId)
45
+ : linked.light;
46
+ this.linkedSirenEntityId =
47
+ this.record.sirenEntityId && this.record.sirenEntityId !== "auto"
48
+ ? (this.record.sirenEntityId === "none" ? undefined : this.record.sirenEntityId)
49
+ : linked.siren;
50
+ this.linkedDoorbellEntityId = linked.doorbell;
51
+ this.rebuildServiceGraph();
52
+ }
53
+ rebuildServiceGraph() {
54
+ this.configureAccessoryInformation();
55
+ this.delegate = new HomeKitCameraStreamingDelegate(this.platform, this.entityId, this.capabilities, this.streamSource);
56
+ this.recordingDelegate = new HomeKitCameraRecordingDelegate(this.platform, this.entityId, this.record, this.capabilities, this.streamSource);
57
+ // Coordinate Live Stream and HKSV Recording to prevent camera RTSP socket contention
58
+ this.delegate.on("session-start", () => {
59
+ this.recordingDelegate?.pausePrebuffer();
60
+ });
61
+ this.delegate.on("session-end", () => {
62
+ this.recordingDelegate?.resumePrebuffer();
63
+ });
64
+ this.motionService = undefined;
65
+ const isScrypted = this.entityId.startsWith("scrypted.") ||
66
+ Boolean(this.streamSource.metadata?.isScrypted);
67
+ const isCameraUi = this.entityId.startsWith("camera.cameraui_") ||
68
+ this.entityId.startsWith("cameraui.") ||
69
+ Boolean(this.streamSource.metadata?.isCameraUi);
70
+ if (this.linkedMotionEntityId || isScrypted || isCameraUi) {
71
+ this.motionService = this.accessory.addService(Service.MotionSensor, `${this.record.name || this.entityId} Movimiento`);
72
+ const motionOn = this.linkedMotionEntityId
73
+ ? this.platform?.ha?.hassStates?.get(this.linkedMotionEntityId)?.state === "on"
74
+ : false;
75
+ this.motionService.setCharacteristic(Characteristic.MotionDetected, motionOn);
76
+ this.motionService.setCharacteristic(Characteristic.StatusActive, true);
77
+ }
78
+ if (this.linkedDoorbellEntityId || Boolean(this.streamSource.metadata?.hasDoorbell)) {
79
+ try {
80
+ const doorbell = this.accessory.addService(Service.Doorbell, `${this.record.name || this.entityId} Timbre`);
81
+ doorbell.setCharacteristic(Characteristic.ProgrammableSwitchEvent, 0);
82
+ }
83
+ catch { }
84
+ }
85
+ this.lightService = undefined;
86
+ if (this.linkedLightEntityId || Boolean(this.streamSource.metadata?.hasLight)) {
87
+ try {
88
+ this.lightService = this.accessory.addService(Service.Lightbulb, `${this.record.name || this.entityId} Luz`);
89
+ this.lightService
90
+ .getCharacteristic(Characteristic.On)
91
+ .onGet(() => {
92
+ if (this.linkedLightEntityId) {
93
+ const state = this.platform?.ha?.hassStates?.get(this.linkedLightEntityId)?.state;
94
+ return state === "on";
95
+ }
96
+ return false;
97
+ })
98
+ .onSet(async (value) => {
99
+ if (this.linkedLightEntityId) {
100
+ const service = value ? "turn_on" : "turn_off";
101
+ try {
102
+ await this.platform?.ha?.callService("light", service, this.linkedLightEntityId);
103
+ }
104
+ catch { }
105
+ }
106
+ });
107
+ }
108
+ catch { }
109
+ }
110
+ this.sirenService = undefined;
111
+ if (this.linkedSirenEntityId || Boolean(this.streamSource.metadata?.hasSiren)) {
112
+ try {
113
+ this.sirenService = this.accessory.addService(Service.Switch, `${this.record.name || this.entityId} Sirena`);
114
+ this.sirenService
115
+ .getCharacteristic(Characteristic.On)
116
+ .onGet(() => {
117
+ if (this.linkedSirenEntityId) {
118
+ const state = this.platform?.ha?.hassStates?.get(this.linkedSirenEntityId)?.state;
119
+ return state === "on";
120
+ }
121
+ return false;
122
+ })
123
+ .onSet(async (value) => {
124
+ if (this.linkedSirenEntityId) {
125
+ const domain = this.linkedSirenEntityId.split(".")[0] || "siren";
126
+ const service = value ? "turn_on" : "turn_off";
127
+ try {
128
+ await this.platform?.ha?.callService(domain, service, this.linkedSirenEntityId);
129
+ }
130
+ catch { }
131
+ }
132
+ });
133
+ }
134
+ catch { }
135
+ }
136
+ const isStreamingUsable = Boolean(this.streamSource.url);
137
+ this.record.hksvEnabled = isStreamingUsable;
138
+ this.record.hksvCapable = isStreamingUsable;
139
+ this.record.hksvState = isStreamingUsable ? "waiting_hub" : "not_capable";
140
+ this.controller = new CameraController(this.buildControllerOptions());
141
+ this.accessory.configureController(this.controller);
142
+ }
143
+ configureAccessoryInformation() {
144
+ this.accessory
145
+ .getService(Service.AccessoryInformation)
146
+ ?.setCharacteristic(Characteristic.Manufacturer, this.record.manufacturer || "Matter all in one Chrisalvir")
147
+ ?.setCharacteristic(Characteristic.Model, this.record.model || "Modelo no identificado")
148
+ ?.setCharacteristic(Characteristic.SerialNumber, this.record.serialNumber || this.entityId.toUpperCase())
149
+ ?.setCharacteristic(Characteristic.FirmwareRevision, this.platform?.matterbridge?.matterbridgeVersion || "unknown");
150
+ }
151
+ buildControllerOptions() {
152
+ const isStreamingUsable = Boolean(this.streamSource.url);
153
+ const hasFdk = supportsFdkAac();
154
+ const audioCodecs = [
155
+ {
156
+ type: "OPUS" /* AudioStreamingCodecType.OPUS */,
157
+ samplerate: 16 /* AudioStreamingSamplerate.KHZ_16 */,
158
+ },
159
+ {
160
+ type: "OPUS" /* AudioStreamingCodecType.OPUS */,
161
+ samplerate: 24 /* AudioStreamingSamplerate.KHZ_24 */,
162
+ },
163
+ ...(hasFdk
164
+ ? [
165
+ {
166
+ type: "AAC-eld" /* AudioStreamingCodecType.AAC_ELD */,
167
+ samplerate: 16 /* AudioStreamingSamplerate.KHZ_16 */,
168
+ },
169
+ {
170
+ type: "AAC-eld" /* AudioStreamingCodecType.AAC_ELD */,
171
+ samplerate: 24 /* AudioStreamingSamplerate.KHZ_24 */,
172
+ },
173
+ ]
174
+ : []),
175
+ ];
176
+ const options = {
177
+ cameraStreamCount: 2,
178
+ delegate: this.delegate,
179
+ streamingOptions: {
180
+ supportedCryptoSuites: [0 /* SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80 */],
181
+ video: {
182
+ codec: {
183
+ profiles: [0 /* H264Profile.BASELINE */, 1 /* H264Profile.MAIN */, 2 /* H264Profile.HIGH */],
184
+ levels: [0 /* H264Level.LEVEL3_1 */, 1 /* H264Level.LEVEL3_2 */, 2 /* H264Level.LEVEL4_0 */],
185
+ },
186
+ resolutions: this.buildDeclaredResolutions(),
187
+ },
188
+ audio: {
189
+ codecs: audioCodecs,
190
+ },
191
+ },
192
+ sensors: this.motionService ? { motion: this.motionService } : undefined,
193
+ };
194
+ if (isStreamingUsable && this.recordingDelegate) {
195
+ options.recording = {
196
+ options: {
197
+ prebufferLength: 4000,
198
+ overrideEventTriggerOptions: [1 /* EventTriggerOption.MOTION */],
199
+ mediaContainerConfiguration: {
200
+ type: 0 /* MediaContainerType.FRAGMENTED_MP4 */,
201
+ fragmentLength: 4000,
202
+ },
203
+ video: {
204
+ type: 0 /* VideoCodecType.H264 */,
205
+ parameters: {
206
+ profiles: [0 /* H264Profile.BASELINE */, 1 /* H264Profile.MAIN */, 2 /* H264Profile.HIGH */],
207
+ levels: [0 /* H264Level.LEVEL3_1 */, 1 /* H264Level.LEVEL3_2 */, 2 /* H264Level.LEVEL4_0 */],
208
+ },
209
+ resolutions: this.buildRecordingResolutions(),
210
+ },
211
+ audio: {
212
+ codecs: {
213
+ type: 0 /* AudioRecordingCodecType.AAC_LC */,
214
+ audioChannels: 1,
215
+ samplerate: [
216
+ 1 /* AudioRecordingSamplerate.KHZ_16 */,
217
+ 3 /* AudioRecordingSamplerate.KHZ_32 */,
218
+ ],
219
+ },
220
+ },
221
+ },
222
+ delegate: this.recordingDelegate,
223
+ };
224
+ }
225
+ return options;
226
+ }
227
+ buildRecordingResolutions() {
228
+ return [
229
+ [3840, 2160, 30],
230
+ [2560, 1440, 30],
231
+ [1920, 1080, 30],
232
+ [1280, 720, 30],
233
+ ];
234
+ }
235
+ buildDeclaredResolutions() {
236
+ const source = this.capabilities.resolution || { width: 1920, height: 1080 };
237
+ const sourceFps = Math.max(15, Math.min(this.capabilities.maxFps || 30, 60));
238
+ const ladder = [
239
+ // 1. Native source resolution first so HomeKit prioritizes maximum native sensor quality
240
+ [source.width, source.height, sourceFps],
241
+ // 2. 4K UHD (3840x2160)
242
+ [3840, 2160, sourceFps],
243
+ // 3. 2K QHD (2560x1440)
244
+ [2560, 1440, sourceFps],
245
+ // 4. 2K 3MP (2304x1296 for Tapo, Wyze, etc.)
246
+ [2304, 1296, sourceFps],
247
+ // 5. 1080p Full HD (1920x1080)
248
+ [1920, 1080, sourceFps],
249
+ // 6. 720p HD (1280x720)
250
+ [1280, 720, sourceFps],
251
+ [1280, 960, sourceFps],
252
+ [1024, 768, sourceFps],
253
+ [640, 480, 30],
254
+ [640, 360, 30],
255
+ [480, 360, 30],
256
+ [480, 270, 30],
257
+ [320, 240, 30],
258
+ [320, 240, 15],
259
+ [320, 180, 30],
260
+ ];
261
+ // Deduplicate resolutions while preserving maximum quality order
262
+ const seen = new Set();
263
+ const supported = [];
264
+ for (const [w, h, fps] of ladder) {
265
+ const key = `${w}x${h}`;
266
+ if (!seen.has(key)) {
267
+ seen.add(key);
268
+ supported.push([w, h, fps]);
269
+ }
270
+ }
271
+ return supported.length ? supported : [[1920, 1080, 30]];
272
+ }
273
+ findLinkedEntities() {
274
+ const result = {};
275
+ // 1. Leverage platform multi-strategy matcher if available
276
+ if (typeof this.platform?.findLinkedCameraEntities === "function") {
277
+ try {
278
+ const realEntities = this.platform.findLinkedCameraEntities(this.record.name || "", this.entityId);
279
+ for (const ent of realEntities) {
280
+ if (ent.type === "motion" && !result.motion)
281
+ result.motion = ent.id;
282
+ if (ent.type === "light" && !result.light)
283
+ result.light = ent.id;
284
+ if (ent.type === "siren" && !result.siren)
285
+ result.siren = ent.id;
286
+ if (ent.type === "doorbell" && !result.doorbell)
287
+ result.doorbell = ent.id;
288
+ }
289
+ }
290
+ catch { }
291
+ }
292
+ const registry = this.platform?.ha?.hassEntities;
293
+ const states = this.platform?.ha?.hassStates;
294
+ if (!states)
295
+ return result;
296
+ const cameraBase = (this.record.name || this.entityId)
297
+ .toLowerCase()
298
+ .replace(/[^a-z0-9]/g, "_")
299
+ .replace(/_+/g, "_")
300
+ .replace(/^_|_$/g, "");
301
+ const words = cameraBase.split("_").filter((w) => w.length >= 3);
302
+ const matchesName = (entityId, friendlyName) => {
303
+ const idLower = entityId.toLowerCase();
304
+ const fnLower = (friendlyName || "").toLowerCase();
305
+ if (idLower.includes(cameraBase) || fnLower.includes(cameraBase))
306
+ return true;
307
+ const modelKeywords = words.filter((w) => /^[a-z]+\d+|\d+[a-z]+|vimtag|tapo|wyze|reolink|nest/i.test(w));
308
+ if (modelKeywords.length > 0 && modelKeywords.some((k) => idLower.includes(k) || fnLower.includes(k))) {
309
+ return true;
310
+ }
311
+ const matchingWords = words.filter((w) => idLower.includes(w) || fnLower.includes(w));
312
+ return matchingWords.length >= Math.min(2, words.length);
313
+ };
314
+ const deviceId = registry?.get(this.entityId)?.device_id;
315
+ for (const [entityId, state] of states.entries()) {
316
+ const entry = registry?.get(entityId);
317
+ const isSameDevice = Boolean(deviceId && entry?.device_id === deviceId);
318
+ const fn = state?.attributes?.friendly_name;
319
+ // CRITICAL: If the camera is a registered HA device (has deviceId), ONLY accept
320
+ // entities physically belonging to that exact same hardware (entry.device_id === deviceId).
321
+ // Never link room fixtures or ambient household bulbs to the camera!
322
+ if (deviceId) {
323
+ if (!isSameDevice)
324
+ continue;
325
+ }
326
+ else {
327
+ // Cameras without a HA device: strictly exclude room fixtures
328
+ const isRoomFixture = /ventilador|fan|techo|ceiling|plafon|plafón|arbotante|aplique|lampara|lámpara|tira|strip|hexágono|hexagon|neon|neón|tv|pantalla|mesa|escritorio|buró|buro|noche|velador|veladora|piso|floor|doble_spot|chandelier|segment/i.test(`${entityId} ${fn || ""}`);
329
+ if (isRoomFixture)
330
+ continue;
331
+ if (!matchesName(entityId, fn))
332
+ continue;
333
+ }
334
+ const domain = entityId.split(".")[0];
335
+ const deviceClass = state?.attributes?.device_class;
336
+ if (!result.motion &&
337
+ domain === "binary_sensor" &&
338
+ (["motion", "occupancy", "presence"].includes(deviceClass) ||
339
+ entityId.includes("motion") ||
340
+ entityId.includes("movimiento"))) {
341
+ result.motion = entityId;
342
+ }
343
+ if (!result.light &&
344
+ (domain === "light" || domain === "switch") &&
345
+ (isSameDevice ||
346
+ /spotlight|floodlight|reflector|flash|status_light|indicador|luz_estado|foco_camara|luz_camara/i.test(`${entityId} ${fn || ""}`))) {
347
+ result.light = entityId;
348
+ }
349
+ if (!result.siren &&
350
+ (domain === "siren" ||
351
+ (domain === "switch" &&
352
+ (entityId.includes("siren") ||
353
+ entityId.includes("alarm") ||
354
+ entityId.includes("alarma") ||
355
+ (fn || "").toLowerCase().includes("sirena") ||
356
+ (fn || "").toLowerCase().includes("alarma"))))) {
357
+ result.siren = entityId;
358
+ }
359
+ if (!result.doorbell &&
360
+ (domain === "binary_sensor" || domain === "event") &&
361
+ (deviceClass === "doorbell" ||
362
+ entityId.includes("doorbell") ||
363
+ entityId.includes("timbre"))) {
364
+ result.doorbell = entityId;
365
+ }
366
+ }
367
+ // Correlate Google Nest companion sensors (Person, Doorbell, Sound)
368
+ if (NestCameraAdapter.isNestCamera(this.entityId, states.get(this.entityId))) {
369
+ const nestEntities = NestCameraAdapter.findLinkedNestEntities(this.platform, this.entityId);
370
+ if (nestEntities.motion && !result.motion)
371
+ result.motion = nestEntities.motion;
372
+ if (nestEntities.person && !result.motion)
373
+ result.motion = nestEntities.person;
374
+ if (nestEntities.doorbell && !result.doorbell)
375
+ result.doorbell = nestEntities.doorbell;
376
+ }
377
+ return result;
378
+ }
379
+ findLinkedMotionEntity() {
380
+ if (this.record.motionEntityId &&
381
+ this.platform?.ha?.hassStates?.has(this.record.motionEntityId)) {
382
+ return this.record.motionEntityId;
383
+ }
384
+ const registry = this.platform?.ha?.hassEntities;
385
+ const states = this.platform?.ha?.hassStates;
386
+ const deviceId = registry?.get(this.entityId)?.device_id;
387
+ const cameraBase = this.entityId.split(".")[1] || this.entityId;
388
+ if (deviceId && registry) {
389
+ for (const [entityId, entry] of registry.entries()) {
390
+ if (entry.device_id !== deviceId || !entityId.startsWith("binary_sensor."))
391
+ continue;
392
+ const state = states?.get(entityId);
393
+ const deviceClass = state?.attributes?.device_class;
394
+ if (["motion", "occupancy", "presence"].includes(deviceClass) ||
395
+ entityId.includes("motion") ||
396
+ entityId.includes("movimiento")) {
397
+ return entityId;
398
+ }
399
+ }
400
+ }
401
+ if (states) {
402
+ const clean = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
403
+ const cleanCam = clean(this.record?.name || "");
404
+ const cleanBase = clean(cameraBase.replace(/^cameraui_/, ""));
405
+ for (const [entityId, state] of states.entries()) {
406
+ if (!entityId.startsWith("binary_sensor."))
407
+ continue;
408
+ const deviceClass = state?.attributes?.device_class;
409
+ const isMotionClass = ["motion", "occupancy", "presence"].includes(deviceClass || "") ||
410
+ entityId.includes("motion") ||
411
+ entityId.includes("movimiento") ||
412
+ entityId.includes("person") ||
413
+ entityId.includes("persona") ||
414
+ entityId.includes("detection") ||
415
+ entityId.includes("animal") ||
416
+ entityId.includes("pet") ||
417
+ entityId.includes("vehicle") ||
418
+ entityId.includes("vehiculo") ||
419
+ entityId.includes("car");
420
+ if (!isMotionClass)
421
+ continue;
422
+ const cleanEntity = clean(entityId);
423
+ const fn = (state?.attributes?.friendly_name || "").toLowerCase();
424
+ const cleanFn = clean(fn);
425
+ const camWords = (this.record?.name || "").toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length >= 3);
426
+ const wordsMatch = camWords.length > 0 && camWords.every((w) => cleanEntity.includes(w) || cleanFn.includes(w));
427
+ const aliasMatch = typeof this.platform?.matchCameraIdentifier === "function" &&
428
+ (this.platform.matchCameraIdentifier({ id: this.entityId, name: this.record?.name }, entityId) ||
429
+ this.platform.matchCameraIdentifier({ id: this.entityId, name: this.record?.name }, fn));
430
+ if ((cleanCam.length >= 3 && cleanEntity.includes(cleanCam)) ||
431
+ (cleanBase.length >= 4 && cleanEntity.includes(cleanBase)) ||
432
+ wordsMatch ||
433
+ aliasMatch) {
434
+ return entityId;
435
+ }
436
+ }
437
+ }
438
+ return undefined;
439
+ }
440
+ static detectPrimaryNetworkInterface() {
441
+ try {
442
+ const ifaces = os.networkInterfaces();
443
+ const ignoredPatterns = /^(lo|docker|hassio|veth|br-|dummy|tun|tap|tailscale|wg|utun|llw|awdl)/i;
444
+ for (const [name, addrs] of Object.entries(ifaces)) {
445
+ if (ignoredPatterns.test(name))
446
+ continue;
447
+ for (const addr of addrs || []) {
448
+ if (addr.internal)
449
+ continue;
450
+ if (addr.family === "IPv4" || addr.family === 4) {
451
+ if (addr.address.startsWith("172.17.") || addr.address.startsWith("172.30."))
452
+ continue;
453
+ return { name, ip: addr.address };
454
+ }
455
+ }
456
+ }
457
+ }
458
+ catch { }
459
+ return undefined;
460
+ }
461
+ updateMotionState(motionDetected) {
462
+ if (!this.motionService)
463
+ return;
464
+ this.motionService.updateCharacteristic(Characteristic.MotionDetected, motionDetected);
465
+ this.recordingDelegate?.handleMotionDetected(motionDetected);
466
+ }
467
+ updateLightState(isOn) {
468
+ if (!this.lightService)
469
+ return;
470
+ try {
471
+ this.lightService.updateCharacteristic(Characteristic.On, isOn);
472
+ }
473
+ catch { }
474
+ }
475
+ updateSirenState(isOn) {
476
+ if (!this.sirenService)
477
+ return;
478
+ try {
479
+ this.sirenService.updateCharacteristic(Characteristic.On, isOn);
480
+ }
481
+ catch { }
482
+ }
483
+ async publish() {
484
+ if (this.isPublished)
485
+ return;
486
+ this.accessory.on("paired", () => {
487
+ this.record.isPaired = true;
488
+ this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Camera paired to Apple Home`);
489
+ void this.platform?.saveHomeKitCameraRecords?.();
490
+ this.notifyPairingStateChanged(true);
491
+ });
492
+ this.accessory.on("unpaired", () => {
493
+ this.record.isPaired = false;
494
+ this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Camera un-paired from Apple Home`);
495
+ void this.platform?.saveHomeKitCameraRecords?.();
496
+ this.notifyPairingStateChanged(false);
497
+ });
498
+ const primaryIface = HomeKitCameraAccessory.detectPrimaryNetworkInterface();
499
+ await this.accessory.publish({
500
+ username: this.record.username,
501
+ pincode: this.record.pincode,
502
+ port: this.record.port,
503
+ category: 17 /* Categories.IP_CAMERA */,
504
+ setupID: this.record.setupId,
505
+ advertiser: "ciao" /* MDNSAdvertiser.CIAO */,
506
+ bind: primaryIface?.name ? [primaryIface.name] : undefined,
507
+ });
508
+ this.isPublished = true;
509
+ this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Published production HAP camera port=${this.record.port} (advertiser=ciao, iface=all) HKSV=${this.record.hksvEnabled ? "enabled" : "disabled"}`);
510
+ // Asynchronously probe stream capabilities (HEVC vs H264, audio tracks) to adapt strategy dynamically
511
+ void this.probeAndAdaptCapabilities();
512
+ setTimeout(() => {
513
+ void this.delegate.handleSnapshotRequest({ width: 1280, height: 720 }, () => { });
514
+ }, 1500);
515
+ }
516
+ async probeAndAdaptCapabilities() {
517
+ if (!this.streamSource.url)
518
+ return;
519
+ try {
520
+ const probe = await probeCameraSource(this.streamSource.url, { timeoutMs: 4000 });
521
+ if (probe.valid && probe.videoCodec) {
522
+ const codec = probe.videoCodec.toLowerCase();
523
+ const isHevc = codec.includes("hevc") || codec.includes("265");
524
+ this.capabilities.videoCodec = isHevc ? "hevc" : "h264";
525
+ this.capabilities.requiresTranscoding = false;
526
+ this.capabilities.strategy = isHevc ? "passthrough_hevc" : "passthrough_h264";
527
+ if (probe.hasAudio !== undefined) {
528
+ this.capabilities.hasAudio = probe.hasAudio;
529
+ }
530
+ if (probe.width && probe.height) {
531
+ this.capabilities.resolution = { width: probe.width, height: probe.height };
532
+ }
533
+ if (probe.fps) {
534
+ this.capabilities.maxFps = probe.fps;
535
+ }
536
+ this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Probed capabilities: codec=${probe.videoCodec} ${probe.width}x${probe.height}@${probe.fps}fps hasAudio=${probe.hasAudio} -> strategy=${this.capabilities.strategy}`);
537
+ if (this.entityId.includes("cameraui")) {
538
+ const cuiId = this.entityId.replace(/^camera\.cameraui_/, "").replace(/^camera\./, "");
539
+ void CameraUiStorage.updateCamera(cuiId, (cam) => {
540
+ cam.videoCodec = this.capabilities.videoCodec;
541
+ cam.strategy = this.capabilities.strategy;
542
+ if (probe.hasAudio !== undefined)
543
+ cam.hasAudio = probe.hasAudio;
544
+ if (probe.width && probe.height) {
545
+ cam.width = probe.width;
546
+ cam.height = probe.height;
547
+ }
548
+ if (probe.fps)
549
+ cam.fps = probe.fps;
550
+ return cam;
551
+ });
552
+ }
553
+ }
554
+ }
555
+ catch { }
556
+ }
557
+ notifyPairingStateChanged(paired) {
558
+ try {
559
+ const homeName = this.getPairedHomeName();
560
+ if (this.entityId.startsWith("scrypted.")) {
561
+ const scryptedId = this.entityId.replace(/^scrypted\./, "");
562
+ void ScryptedStorage.updateCamera(scryptedId, (cam) => {
563
+ cam.identity = {
564
+ ...cam.identity,
565
+ homeKitPairingState: paired ? "paired" : "not_paired",
566
+ homeKitPairedHome: homeName,
567
+ };
568
+ return cam;
569
+ });
570
+ }
571
+ // Update Camera.UI storage if applicable
572
+ const cuiId = this.entityId.replace(/^camera\.cameraui_/, "").replace(/^camera\./, "");
573
+ void CameraUiStorage.updateCamera(cuiId, (cam) => {
574
+ cam.isPaired = paired;
575
+ return cam;
576
+ });
577
+ this.platform?.broadcastSseMessage?.("camera_pairing_updated", {
578
+ entityId: this.entityId,
579
+ isPaired: paired,
580
+ homeName,
581
+ });
582
+ this.platform?.broadcastSseMessage?.("cameraui_updated", {
583
+ entityId: this.entityId,
584
+ isPaired: paired,
585
+ });
586
+ this.platform?.broadcastSseMessage?.("state_change", {
587
+ entityId: this.entityId,
588
+ isPaired: paired,
589
+ });
590
+ this.platform?.pushEntityUpdate?.(this.entityId);
591
+ }
592
+ catch { }
593
+ }
594
+ getPairedHomeName() {
595
+ const haLocation = this.platform?.ha?.hassConfig?.location_name;
596
+ return haLocation || "Casa (Apple Home)";
597
+ }
598
+ getPairingState() {
599
+ try {
600
+ const serverInfo = this.accessory?._server?.accessoryInfo;
601
+ if (serverInfo && typeof serverInfo.paired === "function") {
602
+ const isHapPaired = serverInfo.paired();
603
+ if (this.record.isPaired !== isHapPaired) {
604
+ this.record.isPaired = isHapPaired;
605
+ void this.platform?.saveHomeKitCameraRecords?.();
606
+ this.notifyPairingStateChanged(isHapPaired);
607
+ }
608
+ return isHapPaired ? "paired" : "not_paired";
609
+ }
610
+ if (!this.record.username)
611
+ return "unverifiable";
612
+ const info = AccessoryInfo.load(this.record.username);
613
+ if (info && typeof info.paired === "function") {
614
+ const isHapPaired = info.paired();
615
+ if (this.record.isPaired !== isHapPaired) {
616
+ this.record.isPaired = isHapPaired;
617
+ void this.platform?.saveHomeKitCameraRecords?.();
618
+ this.notifyPairingStateChanged(isHapPaired);
619
+ }
620
+ return isHapPaired ? "paired" : "not_paired";
621
+ }
622
+ }
623
+ catch { }
624
+ if (typeof this.record.isPaired === "boolean") {
625
+ return this.record.isPaired ? "paired" : "not_paired";
626
+ }
627
+ return "unverifiable";
628
+ }
629
+ isPaired() {
630
+ return this.getPairingState() === "paired";
631
+ }
632
+ get isStreaming() {
633
+ return this.delegate?.isStreaming ?? false;
634
+ }
635
+ async unpublish() {
636
+ this.delegate?.cleanupAllSessions();
637
+ this.recordingDelegate?.updateRecordingActive(false);
638
+ if (!this.isPublished)
639
+ return;
640
+ try {
641
+ await this.accessory.unpublish();
642
+ }
643
+ finally {
644
+ this.isPublished = false;
645
+ }
646
+ }
647
+ async resetPairing() {
648
+ await this.unpublish();
649
+ try {
650
+ if (this.record.username)
651
+ AccessoryInfo.remove(this.record.username);
652
+ }
653
+ catch (error) {
654
+ this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] Unable to remove old pairing: ${String(error)}`);
655
+ }
656
+ // Generate fresh MAC address (username) and setupId so iOS sees a brand-new device
657
+ const randomHex = crypto.randomBytes(5).toString("hex").toUpperCase();
658
+ this.record.username = `0E:${randomHex.match(/.{2}/g).join(":")}`;
659
+ this.record.setupId = crypto.randomBytes(2).toString("hex").toUpperCase().slice(0, 4);
660
+ // Pick next free port across both HomeKit records and Camera.UI store
661
+ const usedPorts = new Set();
662
+ if (this.platform?.homekitCameraRecords) {
663
+ for (const r of this.platform.homekitCameraRecords.values()) {
664
+ if (r.port && r.port !== this.record.port)
665
+ usedPorts.add(r.port);
666
+ }
667
+ }
668
+ try {
669
+ const cuiStore = CameraUiStorage.getCachedStore();
670
+ if (cuiStore) {
671
+ for (const c of cuiStore.cameras) {
672
+ if (c.port && c.port !== this.record.port)
673
+ usedPorts.add(c.port);
674
+ }
675
+ }
676
+ }
677
+ catch { }
678
+ let nextPort = 51830;
679
+ while (usedPorts.has(nextPort))
680
+ nextPort++;
681
+ this.record.port = nextPort;
682
+ this.record.published = false;
683
+ this.record.isPaired = false;
684
+ this.record.hksvEnabled = false;
685
+ this.record.hksvCapable = false;
686
+ this.record.uuid = uuid.generate(`homekit:camera:${this.entityId}:${Date.now()}`);
687
+ this.accessory = new Accessory(this.record.name || this.entityId, this.record.uuid);
688
+ this.rebuildServiceGraph();
689
+ await this.publish();
690
+ this.record.published = true;
691
+ return this.record;
692
+ }
693
+ get setupUri() {
694
+ return this.accessory.setupURI();
695
+ }
696
+ }
697
+ //# sourceMappingURL=homekit-camera.accessory.js.map