matter-all-in-one-addon 2.3.12 → 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 (104) hide show
  1. package/README.md +16 -8
  2. package/dist/camera/ai/camera-ai-detector.js +2 -1
  3. package/dist/camera/ai/camera-ai-detector.js.map +1 -1
  4. package/dist/camera/camera-source-resolver.js +5 -3
  5. package/dist/camera/camera-source-resolver.js.map +1 -1
  6. package/dist/camera/cameraui/cameraui-client.js +91 -30
  7. package/dist/camera/cameraui/cameraui-client.js.map +1 -1
  8. package/dist/camera/cameraui/cameraui-homekit-bridge.js +11 -4
  9. package/dist/camera/cameraui/cameraui-homekit-bridge.js.map +1 -1
  10. package/dist/camera/cameraui/cameraui-storage.js.map +1 -1
  11. package/dist/camera/cameraui/ha-camera-entity.js +5 -2
  12. package/dist/camera/cameraui/ha-camera-entity.js.map +1 -1
  13. package/dist/camera/homekit/ffmpeg-helper.js.map +1 -1
  14. package/dist/camera/homekit/hevc/fmp4-hevc.js +3 -1
  15. package/dist/camera/homekit/hevc/fmp4-hevc.js.map +1 -1
  16. package/dist/camera/homekit/hevc/hevc-recording.js +10 -8
  17. package/dist/camera/homekit/hevc/hevc-recording.js.map +1 -1
  18. package/dist/camera/homekit/hevc/multi-tier-rtp.js +15 -8
  19. package/dist/camera/homekit/hevc/multi-tier-rtp.js.map +1 -1
  20. package/dist/camera/homekit/hevc/sframe-rtp.js +13 -4
  21. package/dist/camera/homekit/hevc/sframe-rtp.js.map +1 -1
  22. package/dist/camera/homekit/hevc/sframe.js +67 -10
  23. package/dist/camera/homekit/hevc/sframe.js.map +1 -1
  24. package/dist/camera/homekit/hevc/types.js +81 -9
  25. package/dist/camera/homekit/hevc/types.js.map +1 -1
  26. package/dist/camera/homekit/hevc/webrtc-session.js +41 -16
  27. package/dist/camera/homekit/hevc/webrtc-session.js.map +1 -1
  28. package/dist/camera/homekit/homekit-camera-recording.delegate.js +10 -4
  29. package/dist/camera/homekit/homekit-camera-recording.delegate.js.map +1 -1
  30. package/dist/camera/homekit/homekit-camera-stream.delegate.js.map +1 -1
  31. package/dist/camera/homekit/tuya-hap-talkback.js +1 -3
  32. package/dist/camera/homekit/tuya-hap-talkback.js.map +1 -1
  33. package/dist/camera/motion/ffmpeg-motion-detector.js +27 -13
  34. package/dist/camera/motion/ffmpeg-motion-detector.js.map +1 -1
  35. package/dist/camera/nest/nest-camera-adapter.js +9 -5
  36. package/dist/camera/nest/nest-camera-adapter.js.map +1 -1
  37. package/dist/camera/ptz/ptz-capabilities.js +3 -1
  38. package/dist/camera/ptz/ptz-capabilities.js.map +1 -1
  39. package/dist/camera/ptz/ptz-legacy-discovery.js.map +1 -1
  40. package/dist/camera/ptz/ptz-mqtt-publisher.js +50 -12
  41. package/dist/camera/ptz/ptz-mqtt-publisher.js.map +1 -1
  42. package/dist/camera/ptz/ptz-zones-manager.js +6 -1
  43. package/dist/camera/ptz/ptz-zones-manager.js.map +1 -1
  44. package/dist/camera/scrypted/scrypted-camera-card.js +3 -1
  45. package/dist/camera/scrypted/scrypted-camera-card.js.map +1 -1
  46. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js +7 -5
  47. package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js.map +1 -1
  48. package/dist/camera/scrypted/scrypted-client-discovery-adapter.js.map +1 -1
  49. package/dist/camera/scrypted/scrypted-client.js +6 -5
  50. package/dist/camera/scrypted/scrypted-client.js.map +1 -1
  51. package/dist/camera/scrypted/scrypted-discovery-provider.js.map +1 -1
  52. package/dist/camera/scrypted/scrypted-homekit-bridge.js +6 -4
  53. package/dist/camera/scrypted/scrypted-homekit-bridge.js.map +1 -1
  54. package/dist/camera/scrypted/scrypted-reconnect-manager.js.map +1 -1
  55. package/dist/camera/scrypted/scrypted-runtime-facade.js +2 -2
  56. package/dist/camera/scrypted/scrypted-runtime-facade.js.map +1 -1
  57. package/dist/camera/scrypted/scrypted-runtime-ingest.js +3 -1
  58. package/dist/camera/scrypted/scrypted-runtime-ingest.js.map +1 -1
  59. package/dist/camera/scrypted/scrypted-storage.js +12 -6
  60. package/dist/camera/scrypted/scrypted-storage.js.map +1 -1
  61. package/dist/camera/scrypted/scrypted-stream-validator.js +25 -7
  62. package/dist/camera/scrypted/scrypted-stream-validator.js.map +1 -1
  63. package/dist/camera/tuya-webrtc-session.js +6 -2
  64. package/dist/camera/tuya-webrtc-session.js.map +1 -1
  65. package/dist/converters/sensor.converter.js +4 -1
  66. package/dist/converters/sensor.converter.js.map +1 -1
  67. package/dist/device-profiles.js +3 -1
  68. package/dist/device-profiles.js.map +1 -1
  69. package/dist/entities/air_quality.entity.js +3 -1
  70. package/dist/entities/air_quality.entity.js.map +1 -1
  71. package/dist/entities/base.entity.js +45 -17
  72. package/dist/entities/base.entity.js.map +1 -1
  73. package/dist/entities/camera.entity.js +6 -2
  74. package/dist/entities/camera.entity.js.map +1 -1
  75. package/dist/entities/composite-device.entity.js +37 -13
  76. package/dist/entities/composite-device.entity.js.map +1 -1
  77. package/dist/entities/energy_tariff.entity.js.map +1 -1
  78. package/dist/entities/vacuum.entity.js +16 -5
  79. package/dist/entities/vacuum.entity.js.map +1 -1
  80. package/dist/hap/hap-generic-accessory.js +308 -138
  81. package/dist/hap/hap-generic-accessory.js.map +1 -1
  82. package/dist/homeAssistant.js +14 -5
  83. package/dist/homeAssistant.js.map +1 -1
  84. package/dist/index.js +3 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/mqtt/mqtt-client.js.map +1 -1
  87. package/dist/mqtt/mqtt.entity.js +41 -17
  88. package/dist/mqtt/mqtt.entity.js.map +1 -1
  89. package/dist/platform.d.ts +4 -4
  90. package/dist/platform.js +237 -96
  91. package/dist/platform.js.map +1 -1
  92. package/dist/utils/atomic-json-store.js +5 -1
  93. package/dist/utils/atomic-json-store.js.map +1 -1
  94. package/dist/utils/ha-state.js +3 -1
  95. package/dist/utils/ha-state.js.map +1 -1
  96. package/dist/utils/light-color.js +3 -5
  97. package/dist/utils/light-color.js.map +1 -1
  98. package/dist/utils/matter-command-response.js.map +1 -1
  99. package/dist/utils/matter-firmware.js +1 -2
  100. package/dist/utils/matter-firmware.js.map +1 -1
  101. package/dist/utils/matter-protocol.d.ts +1 -0
  102. package/dist/utils/matter-protocol.js +30 -0
  103. package/dist/utils/matter-protocol.js.map +1 -0
  104. package/package.json +26 -17
package/dist/platform.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { loadBridgeProtocol } from "./utils/matter-protocol.js";
1
2
  import { BrowserPreview } from "./camera/browser-preview.js";
2
3
  /**
3
4
  * Core platform class for matter-all-in-one-chrisalvir.
@@ -265,10 +266,12 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
265
266
  }
266
267
  }
267
268
  async saveHapAccessoryRecords() {
268
- this.hapAccessorySaveQueue = this.hapAccessorySaveQueue.then(async () => {
269
+ this.hapAccessorySaveQueue = this.hapAccessorySaveQueue
270
+ .then(async () => {
269
271
  const list = Array.from(this.hapAccessoryRecords.values());
270
272
  await writeHapAccessoryRecords("/data/homekit-accessories.json", list);
271
- }).catch((err) => {
273
+ })
274
+ .catch((err) => {
272
275
  this.log.debug(`Failed to save homekit-accessories.json: ${err instanceof Error ? err.name : "unknown error"}`);
273
276
  });
274
277
  await this.hapAccessorySaveQueue;
@@ -346,7 +349,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
346
349
  record.model !== identity.model ||
347
350
  record.serialNumber !== identity.serialNumber;
348
351
  if (changed) {
349
- Object.assign(record, identity, { lastUpdated: new Date().toISOString() });
352
+ Object.assign(record, identity, {
353
+ lastUpdated: new Date().toISOString(),
354
+ });
350
355
  }
351
356
  return changed;
352
357
  }
@@ -466,14 +471,23 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
466
471
  async setHapAlarmCode(entityId, alarmCode) {
467
472
  const record = this.hapAccessoryRecords.get(entityId);
468
473
  if (!record || record.hapProfile !== "security_system") {
469
- return { success: false, error: "This HAP accessory is not an alarm panel." };
474
+ return {
475
+ success: false,
476
+ error: "This HAP accessory is not an alarm panel.",
477
+ };
470
478
  }
471
479
  if (typeof alarmCode !== "string" || alarmCode.length > 64) {
472
- return { success: false, error: "Alarm PIN must be a text value of at most 64 characters." };
480
+ return {
481
+ success: false,
482
+ error: "Alarm PIN must be a text value of at most 64 characters.",
483
+ };
473
484
  }
474
485
  const normalized = alarmCode.trim();
475
486
  if (normalized && /[\u0000-\u001f\u007f]/.test(normalized)) {
476
- return { success: false, error: "Alarm PIN cannot contain control characters." };
487
+ return {
488
+ success: false,
489
+ error: "Alarm PIN cannot contain control characters.",
490
+ };
477
491
  }
478
492
  if (normalized)
479
493
  record.alarmCode = normalized;
@@ -599,7 +613,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
599
613
  continue;
600
614
  const previousSource = previousSources.get(camera.id);
601
615
  const accessory = await CameraUiHomeKitBridge.mountCamera(this, camera, {
602
- forceRemount: previousSources.has(camera.id) && previousSource !== camera.rtspUrl,
616
+ forceRemount: previousSources.has(camera.id) &&
617
+ previousSource !== camera.rtspUrl,
603
618
  });
604
619
  if (accessory)
605
620
  mountedCount++;
@@ -873,13 +888,25 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
873
888
  : undefined);
874
889
  // Keep genuine controls on the camera's HA device distinct from lights.
875
890
  // A feeder's dispense switch must never be classified as a spotlight.
876
- if (isSameDevice && ["button", "number", "switch"].includes(domain) &&
891
+ if (isSameDevice &&
892
+ ["button", "number", "switch"].includes(domain) &&
877
893
  !/spotlight|floodlight|reflector|status_light|indicador|luz|light|siren|alarm/i.test(`${entityId} ${fn}`)) {
878
- entities.push({ id: entityId, domain: domain, type: domain,
879
- name: state.attributes?.friendly_name || entityId, state: isStateOn,
880
- value: domain === "number" && Number.isFinite(Number(state.state)) ? Number(state.state) : undefined,
881
- min: state.attributes?.min, max: state.attributes?.max, step: state.attributes?.step,
882
- matterExported: isExported, matterPairingCode: matterCode, matterManualCode: manualCode });
894
+ entities.push({
895
+ id: entityId,
896
+ domain: domain,
897
+ type: domain,
898
+ name: state.attributes?.friendly_name || entityId,
899
+ state: isStateOn,
900
+ value: domain === "number" && Number.isFinite(Number(state.state))
901
+ ? Number(state.state)
902
+ : undefined,
903
+ min: state.attributes?.min,
904
+ max: state.attributes?.max,
905
+ step: state.attributes?.step,
906
+ matterExported: isExported,
907
+ matterPairingCode: matterCode,
908
+ matterManualCode: manualCode,
909
+ });
883
910
  continue;
884
911
  }
885
912
  if (!explicitMotionId &&
@@ -1059,7 +1086,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
1059
1086
  this.log.info(`[MatterCommandTrace][${entityId}] start command=${command}`);
1060
1087
  },
1061
1088
  onCommandOutcome: (command, durationMs, outcome, late) => {
1062
- const stage = late ? "ha_operation_finished_after_handler_return" : "handler_returned";
1089
+ const stage = late
1090
+ ? "ha_operation_finished_after_handler_return"
1091
+ : "handler_returned";
1063
1092
  this.log.info(`[MatterCommandTrace][${entityId}] ${stage} command=${command} elapsed_ms=${durationMs} outcome=${outcome}`);
1064
1093
  },
1065
1094
  onFailure: async (command, error, late) => {
@@ -1456,7 +1485,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
1456
1485
  }
1457
1486
  }
1458
1487
  async runMatterAccessoryOperation(entityId, operation) {
1459
- const key = this.compositeMembership.get(entityId) ?? this.ha?.hassEntities?.get(entityId)?.device_id ?? entityId;
1488
+ const key = this.compositeMembership.get(entityId) ??
1489
+ this.ha?.hassEntities?.get(entityId)?.device_id ??
1490
+ entityId;
1460
1491
  const previous = this.matterAccessoryOperations.get(key) ?? Promise.resolve();
1461
1492
  const current = previous.catch(() => undefined).then(operation);
1462
1493
  this.matterAccessoryOperations.set(key, current);
@@ -1528,7 +1559,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
1528
1559
  }
1529
1560
  catch { }
1530
1561
  };
1531
- this.cameraUiHealthStartupTimer = setTimeout(() => { this.cameraUiHealthStartupTimer = undefined; void checkLiveness(); }, 4000);
1562
+ this.cameraUiHealthStartupTimer = setTimeout(() => {
1563
+ this.cameraUiHealthStartupTimer = undefined;
1564
+ void checkLiveness();
1565
+ }, 4000);
1532
1566
  this.cameraUiHealthMonitor = setInterval(() => void checkLiveness(), 30_000);
1533
1567
  }
1534
1568
  cameraUiMotionPoller = null;
@@ -1930,10 +1964,11 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
1930
1964
  isMultiSwitchDevice(deviceId) {
1931
1965
  if (!deviceId)
1932
1966
  return false;
1933
- const allMembers = this.inventoryMembers?.get(deviceId) ?? Array.from(this.entities.values()).filter((entity) => {
1934
- const hassEntry = this.ha.hassEntities?.get(entity.entityId);
1935
- return hassEntry?.device_id === deviceId;
1936
- });
1967
+ const allMembers = this.inventoryMembers?.get(deviceId) ??
1968
+ Array.from(this.entities.values()).filter((entity) => {
1969
+ const hassEntry = this.ha.hassEntities?.get(entity.entityId);
1970
+ return hassEntry?.device_id === deviceId;
1971
+ });
1937
1972
  const isNonGeneric = (e) => !this.isDpsGenericEntity(e.entityId) &&
1938
1973
  !this.isAuxiliaryEntity(e.entityId);
1939
1974
  const switches = allMembers.filter((e) => e.entityId.startsWith("switch.") && isNonGeneric(e));
@@ -1967,8 +2002,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
1967
2002
  // If device has 2+ real switches, 2+ real lights, 2+ switch/light buttons, or matches controller/switch keywords with 2+ channels:
1968
2003
  if (switches.length >= 2 ||
1969
2004
  lights.length >= 2 ||
1970
- (switches.length + lights.length >= 2 && (!isLightingDevice || isSwitchOrPlugDevice)) ||
1971
- (isSwitchOrPlugDevice && switches.length + lights.length + fans.length >= 2)) {
2005
+ (switches.length + lights.length >= 2 &&
2006
+ (!isLightingDevice || isSwitchOrPlugDevice)) ||
2007
+ (isSwitchOrPlugDevice &&
2008
+ switches.length + lights.length + fans.length >= 2)) {
1972
2009
  return true;
1973
2010
  }
1974
2011
  // 1. Any device with 2 or more fan entities (e.g. 2-gang fan controller)
@@ -2000,7 +2037,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
2000
2037
  return undefined;
2001
2038
  }
2002
2039
  const config = this.getCompositeConfigForEntity(entityId, deviceId);
2003
- const existingComposite = this.exportedDevices.has(this.compositeStorageKey(deviceId)) || this.compositeDevices.has(deviceId);
2040
+ const existingComposite = this.exportedDevices.has(this.compositeStorageKey(deviceId)) ||
2041
+ this.compositeDevices.has(deviceId);
2004
2042
  if (config?.group_by_device_id === false && !existingComposite) {
2005
2043
  this.log.debug(`[Composite] ${entityId}: grouping explicitly disabled for device ${deviceId}`);
2006
2044
  return undefined;
@@ -2013,11 +2051,13 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
2013
2051
  // sibling entities are loaded) and pinned. Recomputing it at every boot
2014
2052
  // flips identities when a slow integration only exposes part of a device.
2015
2053
  const pinnedMode = this.nodeIdentities.get(`mode:${deviceId}`);
2016
- const multi = existingComposite ? false : pinnedMode === "multi"
2017
- ? true
2018
- : pinnedMode === "composite"
2019
- ? false
2020
- : this.isMultiSwitchDevice(deviceId);
2054
+ const multi = existingComposite
2055
+ ? false
2056
+ : pinnedMode === "multi"
2057
+ ? true
2058
+ : pinnedMode === "composite"
2059
+ ? false
2060
+ : this.isMultiSwitchDevice(deviceId);
2021
2061
  if (multi) {
2022
2062
  this.log.debug(`[Composite] ${entityId}: multi-switch device ${deviceId} — composite grouping bypassed, each entity gets its own QR`);
2023
2063
  return undefined;
@@ -2037,7 +2077,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
2037
2077
  ]);
2038
2078
  const sourceMembers = explicitlyIncluded?.length
2039
2079
  ? Array.from(this.entities.values())
2040
- : (this.inventoryMembers?.get(compositeDeviceId) ?? Array.from(this.entities.values()));
2080
+ : (this.inventoryMembers?.get(compositeDeviceId) ??
2081
+ Array.from(this.entities.values()));
2041
2082
  let members = sourceMembers.filter((entity) => {
2042
2083
  const [domain] = entity.entityId.split(".");
2043
2084
  if (!supported.has(domain))
@@ -2280,9 +2321,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
2280
2321
  "switch",
2281
2322
  "fan",
2282
2323
  ];
2283
- const candidates = (this.inventoryMembers?.get(deviceId) ?? Array.from(this.entities.values())
2284
- .filter((entity) => this.ha?.hassEntities?.get(entity.entityId)?.device_id === deviceId))
2285
- .slice().sort((left, right) => priority.indexOf(left.entityId.split(".")[0]) -
2324
+ const candidates = (this.inventoryMembers?.get(deviceId) ??
2325
+ Array.from(this.entities.values()).filter((entity) => this.ha?.hassEntities?.get(entity.entityId)?.device_id === deviceId))
2326
+ .slice()
2327
+ .sort((left, right) => priority.indexOf(left.entityId.split(".")[0]) -
2286
2328
  priority.indexOf(right.entityId.split(".")[0]));
2287
2329
  const foundInEntities = candidates.find((entity) => priority.includes(entity.entityId.split(".")[0]))?.entityId;
2288
2330
  if (foundInEntities)
@@ -2290,7 +2332,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
2290
2332
  // Fallback to hassEntities if primary entity hasn't been registered yet during initial pass
2291
2333
  for (const domain of priority) {
2292
2334
  if (this.inventoryRegistry) {
2293
- const id = this.inventoryRegistry.get(deviceId)?.find((id) => id.startsWith(`${domain}.`));
2335
+ const id = this.inventoryRegistry
2336
+ .get(deviceId)
2337
+ ?.find((id) => id.startsWith(`${domain}.`));
2294
2338
  if (id)
2295
2339
  return id;
2296
2340
  }
@@ -2311,7 +2355,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
2311
2355
  if (!deviceId)
2312
2356
  return false;
2313
2357
  if (this.inventoryRegistry)
2314
- return this.inventoryRegistry.get(deviceId)?.some((id) => id.startsWith("vacuum.")) ?? false;
2358
+ return (this.inventoryRegistry
2359
+ .get(deviceId)
2360
+ ?.some((id) => id.startsWith("vacuum.")) ?? false);
2315
2361
  for (const [id, reg] of this.ha?.hassEntities?.entries() ?? []) {
2316
2362
  if (reg.device_id === deviceId && id.startsWith("vacuum.")) {
2317
2363
  return true;
@@ -3327,7 +3373,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3327
3373
  entityInstance = new SoilSensorEntity(this, state, deviceType);
3328
3374
  }
3329
3375
  else if (domain === "sensor" &&
3330
- (deviceClass === "monetary" || deviceClass === "power" || deviceClass === "energy")) {
3376
+ (deviceClass === "monetary" ||
3377
+ deviceClass === "power" ||
3378
+ deviceClass === "energy")) {
3331
3379
  entityInstance = new EnergyTariffEntity(this, state, deviceType);
3332
3380
  }
3333
3381
  else if (domain === "valve" || deviceType.name === "WaterValve") {
@@ -3451,10 +3499,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3451
3499
  }
3452
3500
  }
3453
3501
  /**
3454
- * An exported accessory whose HA entity is not loaded yet (slow integration
3455
- * after a power outage). Its identity stays reserved; it is activated as soon
3456
- * as the entity shows up (see handleEntityStateChange).
3457
- */
3502
+ * An exported accessory whose HA entity is not loaded yet (slow integration
3503
+ * after a power outage). Its identity stays reserved; it is activated as soon
3504
+ * as the entity shows up (see handleEntityStateChange).
3505
+ */
3458
3506
  deferRestore(exportedId) {
3459
3507
  if (!this.pendingRestore.has(exportedId)) {
3460
3508
  this.log.warn(`[Restore] ${exportedId} aún no está disponible en Home Assistant; se reactivará automáticamente cuando aparezca (su vinculación Matter se conserva).`);
@@ -3490,8 +3538,12 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3490
3538
  const pinnedName = this.nodeIdentities.get(identifier);
3491
3539
  if (pinnedName)
3492
3540
  endpoint.deviceName = pinnedName;
3493
- const registered = typeof this.getDevices === "function" ? this.getDevices() : [];
3494
- const duplicate = registered.find((item) => item !== endpoint && item.uniqueId && item.uniqueId === endpoint.uniqueId);
3541
+ const registered = typeof this.getDevices === "function"
3542
+ ? this.getDevices()
3543
+ : [];
3544
+ const duplicate = registered.find((item) => item !== endpoint &&
3545
+ item.uniqueId &&
3546
+ item.uniqueId === endpoint.uniqueId);
3495
3547
  if (duplicate)
3496
3548
  await this.unregisterDeviceBounded(duplicate, `duplicate identity for ${identifier}`);
3497
3549
  const ownOld = this.matterbridgeDevices.get(identifier);
@@ -3532,7 +3584,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3532
3584
  // UNLESS this is an explicit factory reset (forceRecreate = true).
3533
3585
  if (!forceRecreate) {
3534
3586
  const existingEndpoint = this.getDeviceByName(nodeName);
3535
- if (existingEndpoint?.serverNode && existingEndpoint.uniqueId === `device_${candidate.deviceId}`.substring(0, 32)) {
3587
+ if (existingEndpoint?.serverNode &&
3588
+ existingEndpoint.uniqueId ===
3589
+ `device_${candidate.deviceId}`.substring(0, 32)) {
3536
3590
  const composite = new CompositeDeviceEntity(this, candidate.deviceId, nodeName, candidate.members, candidate.config?.primary_entity);
3537
3591
  composite.adoptEndpoint(existingEndpoint);
3538
3592
  for (const member of candidate.members) {
@@ -3648,7 +3702,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3648
3702
  : endpoint.deviceName
3649
3703
  ? this.getDeviceByName(endpoint.deviceName)
3650
3704
  : undefined;
3651
- if (!forceRecreate && existingEndpoint?.serverNode && !existingEndpoint.lifecycle?.isGone && !existingEndpoint.serverNode.lifecycle?.isGone) {
3705
+ if (!forceRecreate &&
3706
+ existingEndpoint?.serverNode &&
3707
+ !existingEndpoint.lifecycle?.isGone &&
3708
+ !existingEndpoint.serverNode.lifecycle?.isGone) {
3652
3709
  entity.adoptEndpoint(existingEndpoint);
3653
3710
  this.installMatterCommandResponsePolicy(existingEndpoint, entityId);
3654
3711
  this.matterbridgeDevices.set(entityId, existingEndpoint);
@@ -3674,7 +3731,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3674
3731
  }
3675
3732
  await this.prepareEndpointForRegistration(endpoint, entityId);
3676
3733
  await this.registerDevice(endpoint);
3677
- if (endpoint.lifecycle?.isGone || endpoint.lifecycle?.isReady === false) {
3734
+ if (endpoint.lifecycle?.isGone ||
3735
+ endpoint.lifecycle?.isReady === false) {
3678
3736
  throw new Error(`Matter endpoint initialization failed for ${entityId}; refusing to publish a destroyed or unready endpoint.`);
3679
3737
  }
3680
3738
  // Matterbridge creates the ServerNode during registerDevice(), but nodes
@@ -3683,8 +3741,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3683
3741
  // mDNS record (_matterc._udp) is present before showing its QR code.
3684
3742
  let serverNode = endpoint.serverNode;
3685
3743
  if (!serverNode) {
3686
- const registered = (endpoint.uniqueId && this.getDeviceByUniqueId?.(endpoint.uniqueId)) ||
3687
- (endpoint.deviceName && this.getDeviceByName?.(endpoint.deviceName));
3744
+ const registered = (endpoint.uniqueId &&
3745
+ this.getDeviceByUniqueId?.(endpoint.uniqueId)) ||
3746
+ (endpoint.deviceName &&
3747
+ this.getDeviceByName?.(endpoint.deviceName));
3688
3748
  if (registered?.serverNode) {
3689
3749
  serverNode = registered.serverNode;
3690
3750
  endpoint.serverNode = serverNode;
@@ -3836,8 +3896,12 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3836
3896
  this.nodeIdentities.pin(`mode:${deviceId}`, isMultiSwitch ? "multi" : "composite");
3837
3897
  if (isMultiSwitch && deviceId) {
3838
3898
  const compKey = this.compositeStorageKey(deviceId);
3839
- if (this.exportedDevices.has(compKey) || this.compositeDevices.has(deviceId)) {
3840
- return { success: false, error: "El dispositivo ya tiene un accesorio compuesto. Se conserva su vinculación existente." };
3899
+ if (this.exportedDevices.has(compKey) ||
3900
+ this.compositeDevices.has(deviceId)) {
3901
+ return {
3902
+ success: false,
3903
+ error: "El dispositivo ya tiene un accesorio compuesto. Se conserva su vinculación existente.",
3904
+ };
3841
3905
  }
3842
3906
  }
3843
3907
  try {
@@ -3893,7 +3957,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3893
3957
  async manualUnregister(entityId) {
3894
3958
  const previousSelection = new Set(this.exportedDevices);
3895
3959
  const affectedSelections = new Set([entityId]);
3896
- const candidateDeviceId = this.compositeMembership.get(entityId) ?? this.getCompositeCandidate(entityId)?.deviceId;
3960
+ const candidateDeviceId = this.compositeMembership.get(entityId) ??
3961
+ this.getCompositeCandidate(entityId)?.deviceId;
3897
3962
  if (candidateDeviceId) {
3898
3963
  affectedSelections.add(this.compositeStorageKey(candidateDeviceId));
3899
3964
  for (const member of this.getCompositeCandidate(entityId)?.members ?? [])
@@ -3911,7 +3976,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3911
3976
  }
3912
3977
  }
3913
3978
  else if (!entityId.startsWith("mqtt.")) {
3914
- const deviceId = this.compositeMembership.get(entityId) ?? this.getCompositeCandidate(entityId)?.deviceId;
3979
+ const deviceId = this.compositeMembership.get(entityId) ??
3980
+ this.getCompositeCandidate(entityId)?.deviceId;
3915
3981
  if (deviceId) {
3916
3982
  const candidate = this.getCompositeCandidate(entityId);
3917
3983
  await this.disposeCompositeNode(deviceId);
@@ -3942,7 +4008,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
3942
4008
  else
3943
4009
  this.exportedDevices.delete(entry);
3944
4010
  }
3945
- if (!this.matterbridgeDevices.has(entityId) && previousSelection.has(entityId)) {
4011
+ if (!this.matterbridgeDevices.has(entityId) &&
4012
+ previousSelection.has(entityId)) {
3946
4013
  this.deferRestore(entityId);
3947
4014
  this.schedulePendingRestore(entityId);
3948
4015
  }
@@ -4050,27 +4117,38 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4050
4117
  * light that was first published as on/off-only.
4051
4118
  */
4052
4119
  async resetMatterAccessory(entityId) {
4053
- const compositeDeviceId = this.compositeMembership.get(entityId) ?? this.getCompositeCandidate(entityId)?.deviceId;
4120
+ const compositeDeviceId = this.compositeMembership.get(entityId) ??
4121
+ this.getCompositeCandidate(entityId)?.deviceId;
4054
4122
  const endpoint = this.getMatterEndpointForEntity(entityId, compositeDeviceId);
4055
4123
  const node = endpoint?.serverNode;
4056
4124
  if (!node || typeof node.erase !== "function") {
4057
- return { success: false, error: "El nodo Matter no está disponible para restablecerse de forma segura. Reconéctalo y vuelve a intentarlo." };
4125
+ return {
4126
+ success: false,
4127
+ error: "El nodo Matter no está disponible para restablecerse de forma segura. Reconéctalo y vuelve a intentarlo.",
4128
+ };
4058
4129
  }
4059
4130
  try {
4060
4131
  await node.erase();
4061
4132
  if (!node.lifecycle?.isOnline)
4062
4133
  await node.start();
4063
4134
  let connection = this.getMatterConnectionInfo(endpoint);
4064
- for (let attempt = 0; attempt < 30 && (connection.fabricCount !== 0 || (!connection.pairingCode && !connection.manualPairingCode)); attempt++) {
4135
+ for (let attempt = 0; attempt < 30 &&
4136
+ (connection.fabricCount !== 0 ||
4137
+ (!connection.pairingCode && !connection.manualPairingCode)); attempt++) {
4065
4138
  await new Promise((resolve) => setTimeout(resolve, 200));
4066
4139
  connection = this.getMatterConnectionInfo(endpoint);
4067
4140
  }
4068
- if (connection.fabricCount !== 0 || (!connection.pairingCode && !connection.manualPairingCode)) {
4141
+ if (connection.fabricCount !== 0 ||
4142
+ (!connection.pairingCode && !connection.manualPairingCode)) {
4069
4143
  throw new Error("El nodo todavía no confirma la eliminación de fabrics y un código de vinculación disponible.");
4070
4144
  }
4071
4145
  this.clearMatterAccessoryProblems(entityId, compositeDeviceId);
4072
4146
  this.pushEntityUpdate(entityId);
4073
- return { success: true, pairingCode: connection.pairingCode, manualPairingCode: connection.manualPairingCode };
4147
+ return {
4148
+ success: true,
4149
+ pairingCode: connection.pairingCode,
4150
+ manualPairingCode: connection.manualPairingCode,
4151
+ };
4074
4152
  }
4075
4153
  catch (error) {
4076
4154
  this.log.error(`Failed to reset Matter accessory ${entityId}: ${error}`);
@@ -4306,7 +4384,7 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4306
4384
  // 2. Direct DeviceCommissioner call if agent didn't handle it
4307
4385
  if (!opened) {
4308
4386
  try {
4309
- const { DeviceCommissioner } = (await import("@matter/protocol"));
4387
+ const { DeviceCommissioner } = await loadBridgeProtocol();
4310
4388
  const commissioner = serverNode.env?.get?.(DeviceCommissioner);
4311
4389
  if (commissioner &&
4312
4390
  typeof commissioner.allowBasicCommissioning === "function") {
@@ -4374,12 +4452,15 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4374
4452
  String(f?.fabricId) === targetStr ||
4375
4453
  Number(f?.fabricIndex) === targetNum);
4376
4454
  if (!matchedFabric || matchedFabric.fabricIndex === undefined) {
4377
- return { success: false, error: "No se encontró la fabric solicitada; no se modificaron otras vinculaciones." };
4455
+ return {
4456
+ success: false,
4457
+ error: "No se encontró la fabric solicitada; no se modificaron otras vinculaciones.",
4458
+ };
4378
4459
  }
4379
4460
  const fabricIndex = Number(matchedFabric.fabricIndex);
4380
4461
  // 1. Try deleting fabric directly via dynamic import of FabricManager if available
4381
4462
  try {
4382
- const { FabricManager } = (await import("@matter/protocol"));
4463
+ const { FabricManager } = await loadBridgeProtocol();
4383
4464
  const fabricManager = serverNode.env?.get?.(FabricManager);
4384
4465
  if (fabricManager) {
4385
4466
  let fabric = fabricManager.maybeFor(fabricIndex);
@@ -4420,8 +4501,12 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4420
4501
  }
4421
4502
  }
4422
4503
  const connection = this.getMatterConnectionInfo(endpoint);
4423
- if (!removed || connection.fabrics.some((fabric) => Number(fabric.fabricIndex) === fabricIndex)) {
4424
- return { success: false, error: "No se pudo confirmar la eliminación de la fabric solicitada." };
4504
+ if (!removed ||
4505
+ connection.fabrics.some((fabric) => Number(fabric.fabricIndex) === fabricIndex)) {
4506
+ return {
4507
+ success: false,
4508
+ error: "No se pudo confirmar la eliminación de la fabric solicitada.",
4509
+ };
4425
4510
  }
4426
4511
  const controllerName = matchedFabric
4427
4512
  ? (MATTER_CONTROLLER_VENDORS[matchedFabric.rootNodeId?.vendorId ??
@@ -4631,7 +4716,7 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4631
4716
  if (!entityId.startsWith("binary_sensor."))
4632
4717
  return;
4633
4718
  const isActive = state.state === "on";
4634
- for (const [cameraId, accessory] of CameraUiHomeKitBridge.getAllAccessories()) {
4719
+ for (const [cameraId, accessory,] of CameraUiHomeKitBridge.getAllAccessories()) {
4635
4720
  if (accessory?.linkedMotionEntityId !== entityId)
4636
4721
  continue;
4637
4722
  this.log.notice(`[Camera.UI][HAP] Movimiento (${isActive ? "DETECTADO" : "REPOSO"}) desde ${entityId} para ${accessory.record?.name || cameraId}`);
@@ -4686,7 +4771,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4686
4771
  continue;
4687
4772
  if (/_segment_\d+$/i.test(id) || /_segment_/i.test(id))
4688
4773
  continue;
4689
- const matchesPrefix = entityId.startsWith(id + "_segment_") || entityId.startsWith(id + "_");
4774
+ const matchesPrefix = entityId.startsWith(id + "_segment_") ||
4775
+ entityId.startsWith(id + "_");
4690
4776
  const sameDevice = deviceId &&
4691
4777
  this.ha?.hassEntities?.get(id)?.device_id === deviceId;
4692
4778
  if ((matchesPrefix || sameDevice) && this.isEntityExported(id)) {
@@ -4698,7 +4784,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4698
4784
  entityId.startsWith("event.")) {
4699
4785
  const isEvent = entityId.startsWith("event.");
4700
4786
  const isMotionState = isEvent
4701
- ? !["unavailable", "unknown", ""].includes(String(newState.state || "").trim().toLowerCase())
4787
+ ? !["unavailable", "unknown", ""].includes(String(newState.state || "")
4788
+ .trim()
4789
+ .toLowerCase())
4702
4790
  : newState.state === "on";
4703
4791
  const devState = this.ha?.hassStates?.get(entityId);
4704
4792
  const entityFriendlyName = getHaEntitySearchText(this.ha, entityId);
@@ -4804,7 +4892,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4804
4892
  (sameDevice && isMotionClass) ||
4805
4893
  isC402Match ||
4806
4894
  isC120Match ||
4807
- (isTapoC120Cam && (isTapoC120Entity || sameDevice || linkedId === entityId) && isMotionClass) ||
4895
+ (isTapoC120Cam &&
4896
+ (isTapoC120Entity || sameDevice || linkedId === entityId) &&
4897
+ isMotionClass) ||
4808
4898
  isWyzeMatch ||
4809
4899
  isEzvizMatch ||
4810
4900
  isVimtagMatch ||
@@ -4990,7 +5080,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4990
5080
  const entity = this.entities.get(entityId);
4991
5081
  if (entity && this.isEntityExported(entityId)) {
4992
5082
  await entity.updateState(state);
4993
- if (!isUnavailable(state) && !entity.hasCommandCommunicationFailure) {
5083
+ if (!isUnavailable(state) &&
5084
+ !entity.hasCommandCommunicationFailure) {
4994
5085
  this.clearEntityProblem(entityId);
4995
5086
  }
4996
5087
  }
@@ -4998,7 +5089,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
4998
5089
  // only its primary entity. Forward changes from every discovered
4999
5090
  // member so its real sensors stay current in Apple Home.
5000
5091
  for (const hapAcc of this.hapAccessories.values()) {
5001
- if (hapAcc.entityId !== entityId && hapAcc.handlesEntityId(entityId)) {
5092
+ if (hapAcc.entityId !== entityId &&
5093
+ hapAcc.handlesEntityId(entityId)) {
5002
5094
  hapAcc.updateFromHassState(state, entityId);
5003
5095
  }
5004
5096
  }
@@ -5113,11 +5205,17 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5113
5205
  return;
5114
5206
  }
5115
5207
  if (!isCameraDiagnosticsAuthorized(secret, req.headers.authorization)) {
5116
- res.writeHead(401, { "Content-Type": "application/json", "Cache-Control": "no-store" });
5208
+ res.writeHead(401, {
5209
+ "Content-Type": "application/json",
5210
+ "Cache-Control": "no-store",
5211
+ });
5117
5212
  res.end(JSON.stringify({ error: "Unauthorized" }));
5118
5213
  return;
5119
5214
  }
5120
- res.writeHead(200, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" });
5215
+ res.writeHead(200, {
5216
+ "Content-Type": "application/json; charset=utf-8",
5217
+ "Cache-Control": "no-store",
5218
+ });
5121
5219
  res.end(JSON.stringify(this.getReadOnlyCameraDiagnostics()));
5122
5220
  return;
5123
5221
  }
@@ -5343,7 +5441,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5343
5441
  const state = this.ha.hassStates?.get(entityId);
5344
5442
  this.ptzManager.registerCamera(entityId, state, cam.rtspUrl);
5345
5443
  }
5346
- const cameras = this.ptzManager.getAllPtzCameras().filter((c) => c.hasPtz);
5444
+ const cameras = this.ptzManager
5445
+ .getAllPtzCameras()
5446
+ .filter((c) => c.hasPtz);
5347
5447
  res.writeHead(200, {
5348
5448
  "Content-Type": "application/json; charset=utf-8",
5349
5449
  });
@@ -5361,7 +5461,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5361
5461
  const cmd = JSON.parse(bodyStr || "{}");
5362
5462
  this.log.info(`[HTTP] PTZ command for ${entityId}: ${JSON.stringify(cmd)}`);
5363
5463
  let result = { success: true };
5364
- if (cmd.command === "move_to_preset" || cmd.command === "set_zone_active") {
5464
+ if (cmd.command === "move_to_preset" ||
5465
+ cmd.command === "set_zone_active") {
5365
5466
  const zoneId = Number(cmd.preset_id || cmd.zone_id || cmd.preset || 1);
5366
5467
  result = await this.ptzManager.setActiveZone(entityId, zoneId);
5367
5468
  }
@@ -5380,10 +5481,15 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5380
5481
  speed: 5,
5381
5482
  });
5382
5483
  }
5383
- else if (lowerId.includes("vimtag") || lowerId.includes("onvif")) {
5484
+ else if (lowerId.includes("vimtag") ||
5485
+ lowerId.includes("onvif")) {
5384
5486
  await this.ha.callService("onvif", "ptz", entityId, {
5385
5487
  tilt: dir === "up" ? "UP" : dir === "down" ? "DOWN" : "HOME",
5386
- pan: dir === "left" ? "LEFT" : dir === "right" ? "RIGHT" : "HOME",
5488
+ pan: dir === "left"
5489
+ ? "LEFT"
5490
+ : dir === "right"
5491
+ ? "RIGHT"
5492
+ : "HOME",
5387
5493
  distance: cmd.step || 0.1,
5388
5494
  speed: 0.5,
5389
5495
  });
@@ -5418,10 +5524,15 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5418
5524
  speed: 5,
5419
5525
  });
5420
5526
  }
5421
- else if (lowerId.includes("vimtag") || lowerId.includes("onvif")) {
5527
+ else if (lowerId.includes("vimtag") ||
5528
+ lowerId.includes("onvif")) {
5422
5529
  await this.ha.callService("onvif", "ptz", entityId, {
5423
5530
  tilt: dir === "up" ? "UP" : dir === "down" ? "DOWN" : "HOME",
5424
- pan: dir === "left" ? "LEFT" : dir === "right" ? "RIGHT" : "HOME",
5531
+ pan: dir === "left"
5532
+ ? "LEFT"
5533
+ : dir === "right"
5534
+ ? "RIGHT"
5535
+ : "HOME",
5425
5536
  distance: step,
5426
5537
  speed: 0.5,
5427
5538
  });
@@ -5590,7 +5701,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5590
5701
  name: friendlyName,
5591
5702
  domain: domain,
5592
5703
  state: e.state.state,
5593
- attributes: { friendly_name: friendlyName, ...e.state.attributes },
5704
+ attributes: {
5705
+ friendly_name: friendlyName,
5706
+ ...e.state.attributes,
5707
+ },
5594
5708
  deviceTypeLabel: typeLabel,
5595
5709
  matterType: domain === "fan"
5596
5710
  ? "fan"
@@ -5621,7 +5735,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5621
5735
  matterFabrics: connection.fabrics,
5622
5736
  // Detect issues strictly on exported accessories (connection drops, unavailable state, active problems)
5623
5737
  hasIssue: this.isEntityExported(e.entityId) &&
5624
- (this.entityProblems.has(e.entityId) || isUnavailable(e.state)),
5738
+ (this.entityProblems.has(e.entityId) ||
5739
+ isUnavailable(e.state)),
5625
5740
  diagnostics: this.entityDiagnostics.get(e.entityId) ?? [],
5626
5741
  nodeDiagnostics: {
5627
5742
  pinnedName: this.nodeIdentities.get(compositeDeviceId
@@ -5653,8 +5768,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5653
5768
  ? "waiting_hub"
5654
5769
  : "configurable"
5655
5770
  : "not_capable");
5656
- const linkedMotion = e.homekitAccessory
5657
- ?.linkedMotionEntityId;
5771
+ const linkedMotion = e
5772
+ .homekitAccessory?.linkedMotionEntityId;
5658
5773
  let recordingStatus = "🔴 HKSV bloqueado (Sin fuente STREAM)";
5659
5774
  if (!cap?.hasLiveStream) {
5660
5775
  recordingStatus =
@@ -5679,7 +5794,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5679
5794
  "⚠️ HKSV con error (Live View activo)";
5680
5795
  }
5681
5796
  return {
5682
- published: e.homekitAccessory?.isPublished ?? false,
5797
+ published: e.homekitAccessory?.isPublished ??
5798
+ false,
5683
5799
  setupId: rec?.setupId,
5684
5800
  liveViewCapabilities: e.homekitAccessory?.getLiveViewCapabilitiesDiagnostic(),
5685
5801
  liveViewTelemetry: e.homekitAccessory?.delegate?.getLiveViewTelemetry(),
@@ -5693,7 +5809,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5693
5809
  port: rec?.port ?? 51830,
5694
5810
  pincode: rec?.pincode,
5695
5811
  username: rec?.username,
5696
- setupUri: e.homekitAccessory?.setupUri || "",
5812
+ setupUri: e.homekitAccessory?.setupUri ||
5813
+ "",
5697
5814
  strategy: rec?.strategy || cap?.strategy || "unsupported",
5698
5815
  hasAudio: cap?.hasAudio ?? false,
5699
5816
  audioCodec: cap?.audioCodec ?? "none",
@@ -5736,7 +5853,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5736
5853
  isPaired: hapAcc?.isPaired() ?? hapRec.isPaired ?? false,
5737
5854
  hapProfile: hapRec.hapProfile,
5738
5855
  alarmCodeConfigured: Boolean(hapRec.alarmCode),
5739
- profileLabel: HAP_PROFILE_LABELS[hapRec.hapProfile] || hapRec.hapProfile,
5856
+ profileLabel: HAP_PROFILE_LABELS[hapRec.hapProfile] ||
5857
+ hapRec.hapProfile,
5740
5858
  pincode: hapRec.pincode,
5741
5859
  port: hapRec.port,
5742
5860
  username: hapRec.username,
@@ -5759,7 +5877,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5759
5877
  domain: m.domain,
5760
5878
  state: m.getStateString(),
5761
5879
  origin: "mqtt",
5762
- attributes: { friendly_name: m.friendlyName, ...m.attributes },
5880
+ attributes: {
5881
+ friendly_name: m.friendlyName,
5882
+ ...m.attributes,
5883
+ },
5763
5884
  deviceTypeLabel: "MQTT " +
5764
5885
  (m.domain.charAt(0).toUpperCase() + m.domain.slice(1)),
5765
5886
  matterType: m.deviceType.name,
@@ -5782,7 +5903,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5782
5903
  profiles: [],
5783
5904
  pairingCode: connection.pairingCode,
5784
5905
  manualPairingCode: connection.manualPairingCode,
5785
- commissioned: this.isEntityExported(m.entityId) && connection.commissioned,
5906
+ commissioned: this.isEntityExported(m.entityId) &&
5907
+ connection.commissioned,
5786
5908
  homeName: connection.homeName,
5787
5909
  controllerNames: connection.controllerNames,
5788
5910
  fabricCount: connection.fabricCount,
@@ -5906,9 +6028,12 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
5906
6028
  return;
5907
6029
  }
5908
6030
  // DELETE /api/custom/diagnostics/:entityId OR POST /api/custom/clear-diagnostics/:entityId
5909
- if ((req.method === "DELETE" && pathname.startsWith("/api/custom/diagnostics/")) ||
5910
- (req.method === "POST" && pathname.startsWith("/api/custom/clear-diagnostics/")) ||
5911
- ((req.method === "DELETE" || req.method === "POST") && /^\/api\/custom\/devices\/[^/]+\/diagnostics$/.test(pathname))) {
6031
+ if ((req.method === "DELETE" &&
6032
+ pathname.startsWith("/api/custom/diagnostics/")) ||
6033
+ (req.method === "POST" &&
6034
+ pathname.startsWith("/api/custom/clear-diagnostics/")) ||
6035
+ ((req.method === "DELETE" || req.method === "POST") &&
6036
+ /^\/api\/custom\/devices\/[^/]+\/diagnostics$/.test(pathname))) {
5912
6037
  let entityId = "";
5913
6038
  if (pathname.startsWith("/api/custom/diagnostics/")) {
5914
6039
  entityId = decodeURIComponent(pathname.substring("/api/custom/diagnostics/".length));
@@ -6965,7 +7090,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
6965
7090
  if (isVimtag && targetUrl.startsWith("rtsp://")) {
6966
7091
  try {
6967
7092
  const u = new URL(targetUrl);
6968
- if (!u.pathname || u.pathname === "/" || u.pathname === "/stream1" || u.pathname === "/stream2") {
7093
+ if (!u.pathname ||
7094
+ u.pathname === "/" ||
7095
+ u.pathname === "/stream1" ||
7096
+ u.pathname === "/stream2") {
6969
7097
  u.pathname = "/live/ch0";
6970
7098
  targetUrl = u.toString();
6971
7099
  }
@@ -7199,7 +7327,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
7199
7327
  if (isVimtag && targetUrl.startsWith("rtsp://")) {
7200
7328
  try {
7201
7329
  const u = new URL(targetUrl);
7202
- if (!u.pathname || u.pathname === "/" || u.pathname === "/stream1" || u.pathname === "/stream2") {
7330
+ if (!u.pathname ||
7331
+ u.pathname === "/" ||
7332
+ u.pathname === "/stream1" ||
7333
+ u.pathname === "/stream2") {
7203
7334
  u.pathname = "/live/ch0";
7204
7335
  targetUrl = u.toString();
7205
7336
  }
@@ -7232,8 +7363,7 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
7232
7363
  // protected endpoints. The diagnostic must use the same HA token as
7233
7364
  // the HAP and HKSV FFmpeg pipelines, otherwise it produces a false
7234
7365
  // 401 even when the freshly-created HLS stream is usable.
7235
- const httpBearerToken = /^https?:\/\//i.test(targetUrl) &&
7236
- /\/api\/hls\//i.test(targetUrl)
7366
+ const httpBearerToken = /^https?:\/\//i.test(targetUrl) && /\/api\/hls\//i.test(targetUrl)
7237
7367
  ? this.ha?.getAccessToken?.() || this.ha?.wsAccessToken
7238
7368
  : undefined;
7239
7369
  ScryptedStreamValidator.clearCache();
@@ -7286,7 +7416,10 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
7286
7416
  if (req.method === "GET" && previewMatch) {
7287
7417
  const id = urlObj.searchParams.get("session") || "";
7288
7418
  if (previewMatch[2]) {
7289
- res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
7419
+ res.writeHead(200, {
7420
+ "Content-Type": "application/json",
7421
+ "Cache-Control": "no-store",
7422
+ });
7290
7423
  res.end(JSON.stringify(this.browserPreview.sessions.get(id) || { frames: 0 }));
7291
7424
  }
7292
7425
  else {
@@ -8147,7 +8280,9 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
8147
8280
  else {
8148
8281
  const result = await this.manualRegister(cameraId);
8149
8282
  if (!result.success) {
8150
- res.writeHead(409, { "Content-Type": "application/json; charset=utf-8" });
8283
+ res.writeHead(409, {
8284
+ "Content-Type": "application/json; charset=utf-8",
8285
+ });
8151
8286
  res.end(JSON.stringify(result));
8152
8287
  return;
8153
8288
  }
@@ -8202,11 +8337,17 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
8202
8337
  }
8203
8338
  else if (domain === "number" && action === "set_value") {
8204
8339
  const n = Number(value);
8205
- if (typeof value !== "number" || !Number.isFinite(n) || n < Number(state.attributes?.min ?? -Infinity) || n > Number(state.attributes?.max ?? Infinity))
8340
+ if (typeof value !== "number" ||
8341
+ !Number.isFinite(n) ||
8342
+ n < Number(state.attributes?.min ?? -Infinity) ||
8343
+ n > Number(state.attributes?.max ?? Infinity))
8206
8344
  throw new Error("Valor fuera del rango de la entidad");
8207
- await this.ha.callService("number", "set_value", entityId, { value: n });
8345
+ await this.ha.callService("number", "set_value", entityId, {
8346
+ value: n,
8347
+ });
8208
8348
  }
8209
- else if (["switch", "light", "siren"].includes(domain) && ["turn_on", "turn_off", "toggle"].includes(action)) {
8349
+ else if (["switch", "light", "siren"].includes(domain) &&
8350
+ ["turn_on", "turn_off", "toggle"].includes(action)) {
8210
8351
  await this.ha.callService(domain, action, entityId);
8211
8352
  }
8212
8353
  else