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
@@ -153,7 +153,9 @@ export class HapGenericAccessory {
153
153
  if (!info)
154
154
  return;
155
155
  const mfr = "Matter All-In-One Chrisalvir";
156
- const model = (this.record.model || HAP_PROFILE_LABELS[this.record.hapProfile] || "HAP Device")
156
+ const model = (this.record.model ||
157
+ HAP_PROFILE_LABELS[this.record.hapProfile] ||
158
+ "HAP Device")
157
159
  .replace(/\s*\(HAP-NodeJS[^)]*\)/gi, "")
158
160
  .trim();
159
161
  info
@@ -168,8 +170,8 @@ export class HapGenericAccessory {
168
170
  // Sensores reales del mismo dispositivo de Home Assistant
169
171
  // ──────────────────────────────────────────────
170
172
  getHomeAssistantState(entityId) {
171
- return this.platform.ha?.hassStates?.get(entityId) ??
172
- this.platform.entities.get(entityId)?.state;
173
+ return (this.platform.ha?.hassStates?.get(entityId) ??
174
+ this.platform.entities.get(entityId)?.state);
173
175
  }
174
176
  getDeviceMembers() {
175
177
  const own = { entityId: this.entityId };
@@ -191,14 +193,21 @@ export class HapGenericAccessory {
191
193
  }
192
194
  bindDiscoveredSensor(entityId, serviceType, characteristic, suffix, read) {
193
195
  const service = this.accessory.addService(serviceType, `${this.record.name} ${suffix}`, `sensor:${entityId}`);
194
- service.getCharacteristic(characteristic).onGet(() => read(this.getHomeAssistantState(entityId)));
195
- this.discoveredSensorBindings.set(entityId, { service, characteristic, read });
196
+ service
197
+ .getCharacteristic(characteristic)
198
+ .onGet(() => read(this.getHomeAssistantState(entityId)));
199
+ this.discoveredSensorBindings.set(entityId, {
200
+ service,
201
+ characteristic,
202
+ read,
203
+ });
196
204
  }
197
205
  addDiscoveredSensorServices() {
198
206
  const members = this.getDeviceMembers();
199
207
  const find = (domain, deviceClass) => members.find((item) => {
200
208
  const state = this.getHomeAssistantState(item.entityId);
201
- return item.entityId.startsWith(`${domain}.`) && state?.attributes?.device_class === deviceClass;
209
+ return (item.entityId.startsWith(`${domain}.`) &&
210
+ state?.attributes?.device_class === deviceClass);
202
211
  });
203
212
  const numeric = (deviceClass, serviceType, characteristic, suffix, minimum = 0) => {
204
213
  const member = find("sensor", deviceClass);
@@ -212,19 +221,58 @@ export class HapGenericAccessory {
212
221
  // Only device members reported by HA are exported. No guessed sensor names,
213
222
  // values, or entities are created for HAP.
214
223
  numeric("temperature", Service.TemperatureSensor, Characteristic.CurrentTemperature, "Temperatura");
215
- if (this.record.hapProfile !== "humidifier" && this.record.hapProfile !== "dehumidifier") {
224
+ if (this.record.hapProfile !== "humidifier" &&
225
+ this.record.hapProfile !== "dehumidifier") {
216
226
  numeric("humidity", Service.HumiditySensor, Characteristic.CurrentRelativeHumidity, "Humedad");
217
227
  }
218
228
  numeric("illuminance", Service.LightSensor, Characteristic.CurrentAmbientLightLevel, "Iluminación", 0.0001);
219
229
  numeric("battery", Service.Battery, Characteristic.BatteryLevel, "Batería");
220
230
  const binaryMappings = [
221
- ["motion", Service.MotionSensor, Characteristic.MotionDetected, "Movimiento", (state) => state?.state === "on"],
222
- ["door", Service.ContactSensor, Characteristic.ContactSensorState, "Puerta", (state) => state?.state === "on" ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED],
223
- ["window", Service.ContactSensor, Characteristic.ContactSensorState, "Ventana", (state) => state?.state === "on" ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED],
224
- ["moisture", Service.LeakSensor, Characteristic.LeakDetected, "Fuga", (state) => state?.state === "on" ? Characteristic.LeakDetected.LEAK_DETECTED : Characteristic.LeakDetected.LEAK_NOT_DETECTED],
225
- ["smoke", Service.SmokeSensor, Characteristic.SmokeDetected, "Humo", (state) => state?.state === "on" ? Characteristic.SmokeDetected.SMOKE_DETECTED : Characteristic.SmokeDetected.SMOKE_NOT_DETECTED],
231
+ [
232
+ "motion",
233
+ Service.MotionSensor,
234
+ Characteristic.MotionDetected,
235
+ "Movimiento",
236
+ (state) => state?.state === "on",
237
+ ],
238
+ [
239
+ "door",
240
+ Service.ContactSensor,
241
+ Characteristic.ContactSensorState,
242
+ "Puerta",
243
+ (state) => state?.state === "on"
244
+ ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
245
+ : Characteristic.ContactSensorState.CONTACT_DETECTED,
246
+ ],
247
+ [
248
+ "window",
249
+ Service.ContactSensor,
250
+ Characteristic.ContactSensorState,
251
+ "Ventana",
252
+ (state) => state?.state === "on"
253
+ ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
254
+ : Characteristic.ContactSensorState.CONTACT_DETECTED,
255
+ ],
256
+ [
257
+ "moisture",
258
+ Service.LeakSensor,
259
+ Characteristic.LeakDetected,
260
+ "Fuga",
261
+ (state) => state?.state === "on"
262
+ ? Characteristic.LeakDetected.LEAK_DETECTED
263
+ : Characteristic.LeakDetected.LEAK_NOT_DETECTED,
264
+ ],
265
+ [
266
+ "smoke",
267
+ Service.SmokeSensor,
268
+ Characteristic.SmokeDetected,
269
+ "Humo",
270
+ (state) => state?.state === "on"
271
+ ? Characteristic.SmokeDetected.SMOKE_DETECTED
272
+ : Characteristic.SmokeDetected.SMOKE_NOT_DETECTED,
273
+ ],
226
274
  ];
227
- for (const [deviceClass, serviceType, characteristic, suffix, read] of binaryMappings) {
275
+ for (const [deviceClass, serviceType, characteristic, suffix, read,] of binaryMappings) {
228
276
  const member = find("binary_sensor", deviceClass);
229
277
  if (member)
230
278
  this.bindDiscoveredSensor(member.entityId, serviceType, characteristic, suffix, read);
@@ -236,18 +284,23 @@ export class HapGenericAccessory {
236
284
  return primary;
237
285
  const sensor = this.getDeviceMembers().find((member) => {
238
286
  const state = this.getHomeAssistantState(member.entityId);
239
- return member.entityId.startsWith("sensor.") && state?.attributes?.device_class === "humidity";
287
+ return (member.entityId.startsWith("sensor.") &&
288
+ state?.attributes?.device_class === "humidity");
240
289
  });
241
290
  const value = Number(sensor && this.getHomeAssistantState(sensor.entityId)?.state);
242
- return Number.isFinite(value) && value >= 0 && value <= 100 ? value : undefined;
291
+ return Number.isFinite(value) && value >= 0 && value <= 100
292
+ ? value
293
+ : undefined;
243
294
  }
244
295
  getMediaEntityId() {
245
296
  if (this.entityId.startsWith("media_player."))
246
297
  return this.entityId;
247
- const devId = this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
298
+ const devId = this.platform.entities.get(this.entityId)
299
+ ?.haDeviceInfo?.id;
248
300
  if (devId) {
249
301
  for (const [id, ent] of this.platform.entities.entries()) {
250
- if (id.startsWith("media_player.") && ent?.haDeviceInfo?.id === devId) {
302
+ if (id.startsWith("media_player.") &&
303
+ ent?.haDeviceInfo?.id === devId) {
251
304
  return id;
252
305
  }
253
306
  }
@@ -260,11 +313,12 @@ export class HapGenericAccessory {
260
313
  return this.entityId;
261
314
  }
262
315
  getRemoteEntityId() {
263
- const deviceId = this.platform.ha?.hassEntities?.get(this.entityId)?.device_id
264
- ?? this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
316
+ const deviceId = this.platform.ha?.hassEntities?.get(this.entityId)?.device_id ??
317
+ this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
265
318
  if (deviceId && this.platform.ha?.hassEntities) {
266
319
  for (const entity of this.platform.ha.hassEntities.values()) {
267
- if (entity.device_id === deviceId && entity.entity_id.startsWith("remote.")) {
320
+ if (entity.device_id === deviceId &&
321
+ entity.entity_id.startsWith("remote.")) {
268
322
  return entity.entity_id;
269
323
  }
270
324
  }
@@ -274,39 +328,47 @@ export class HapGenericAccessory {
274
328
  if (remote)
275
329
  return remote.entityId;
276
330
  const base = this.entityId.replace(/^[^.]+\./, "").split("_")[0];
277
- for (const id of (this.platform.ha?.hassStates?.keys() ?? this.platform.entities.keys())) {
331
+ for (const id of this.platform.ha?.hassStates?.keys() ??
332
+ this.platform.entities.keys()) {
278
333
  if (id.startsWith("remote.") && id.includes(base))
279
334
  return id;
280
335
  }
281
336
  return undefined;
282
337
  }
283
338
  getMuteSwitchEntityId() {
284
- const deviceId = this.platform.ha?.hassEntities?.get(this.entityId)?.device_id
285
- ?? this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
339
+ const deviceId = this.platform.ha?.hassEntities?.get(this.entityId)?.device_id ??
340
+ this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
286
341
  if (deviceId && this.platform.ha?.hassEntities) {
287
342
  for (const entity of this.platform.ha.hassEntities.values()) {
288
- if (entity.device_id === deviceId && entity.entity_id.startsWith("switch.") && entity.entity_id.toLowerCase().includes("mute")) {
343
+ if (entity.device_id === deviceId &&
344
+ entity.entity_id.startsWith("switch.") &&
345
+ entity.entity_id.toLowerCase().includes("mute")) {
289
346
  return entity.entity_id;
290
347
  }
291
348
  }
292
349
  }
293
350
  const members = this.getDeviceMembers();
294
- const sw = members.find((m) => m.entityId.startsWith("switch.") && m.entityId.toLowerCase().includes("mute"));
351
+ const sw = members.find((m) => m.entityId.startsWith("switch.") &&
352
+ m.entityId.toLowerCase().includes("mute"));
295
353
  if (sw)
296
354
  return sw.entityId;
297
355
  const base = this.entityId.replace(/^[^.]+\./, "").split("_")[0];
298
- for (const id of (this.platform.ha?.hassStates?.keys() ?? this.platform.entities.keys())) {
299
- if (id.startsWith("switch.") && id.toLowerCase().includes("mute") && id.includes(base))
356
+ for (const id of this.platform.ha?.hassStates?.keys() ??
357
+ this.platform.entities.keys()) {
358
+ if (id.startsWith("switch.") &&
359
+ id.toLowerCase().includes("mute") &&
360
+ id.includes(base))
300
361
  return id;
301
362
  }
302
363
  return undefined;
303
364
  }
304
365
  getDeviceButton(action) {
305
- const deviceId = this.platform.ha?.hassEntities?.get(this.entityId)?.device_id
306
- ?? this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
366
+ const deviceId = this.platform.ha?.hassEntities?.get(this.entityId)?.device_id ??
367
+ this.platform.entities.get(this.entityId)?.haDeviceInfo?.id;
307
368
  if (deviceId && this.platform.ha?.hassEntities) {
308
369
  for (const entity of this.platform.ha.hassEntities.values()) {
309
- if (entity.device_id === deviceId && entity.entity_id.startsWith("button.")) {
370
+ if (entity.device_id === deviceId &&
371
+ entity.entity_id.startsWith("button.")) {
310
372
  const lower = entity.entity_id.toLowerCase();
311
373
  if (lower.endsWith(`_${action}`) || lower.endsWith(`.${action}`)) {
312
374
  return entity.entity_id;
@@ -321,7 +383,8 @@ export class HapGenericAccessory {
321
383
  const startedAt = Date.now();
322
384
  const command = `${domain}.${service}`;
323
385
  this.platform.log?.info?.(`[HAPCommandTrace][${target}] start service=${command}`);
324
- if (!this.platform.ha?.callService || this.platform.ha.connected === false) {
386
+ if (!this.platform.ha?.callService ||
387
+ this.platform.ha.connected === false) {
325
388
  throw -70402; // HAP SERVICE_COMMUNICATION_FAILURE
326
389
  }
327
390
  const operation = Promise.resolve()
@@ -345,7 +408,9 @@ export class HapGenericAccessory {
345
408
  };
346
409
  if (outcome === undefined) {
347
410
  this.platform.log?.info?.(`[HAPCommandTrace][${target}] handler_returned_pending service=${command} elapsed_ms=${Date.now() - startedAt}`);
348
- void operation.then((result) => report(result.failed, true)).catch(() => undefined);
411
+ void operation
412
+ .then((result) => report(result.failed, true))
413
+ .catch(() => undefined);
349
414
  return;
350
415
  }
351
416
  report(outcome.failed, false);
@@ -356,8 +421,9 @@ export class HapGenericAccessory {
356
421
  const [domain] = this.entityId.split(".");
357
422
  const state = () => this.platform.entities.get(this.entityId)?.state;
358
423
  const bindPower = (service, characteristic) => {
359
- service.getCharacteristic(characteristic)
360
- .onGet(() => state()?.state === "on" ? 1 : 0)
424
+ service
425
+ .getCharacteristic(characteristic)
426
+ .onGet(() => (state()?.state === "on" ? 1 : 0))
361
427
  .onSet(async (value) => {
362
428
  await this.callHaWithResponseBudget(domain, value ? "turn_on" : "turn_off");
363
429
  });
@@ -373,18 +439,31 @@ export class HapGenericAccessory {
373
439
  const service = this.accessory.getService(Service.Lightbulb);
374
440
  if (service) {
375
441
  bindPower(service, Characteristic.On);
376
- service.getCharacteristic(Characteristic.Brightness)
377
- .onGet(() => Math.round((Number(state()?.attributes?.brightness) || 0) * 100 / 255))
378
- .onSet(async (value) => this.callHaWithResponseBudget("light", "turn_on", { brightness_pct: Number(value) }));
442
+ service
443
+ .getCharacteristic(Characteristic.Brightness)
444
+ .onGet(() => Math.round(((Number(state()?.attributes?.brightness) || 0) * 100) / 255))
445
+ .onSet(async (value) => this.callHaWithResponseBudget("light", "turn_on", {
446
+ brightness_pct: Number(value),
447
+ }));
379
448
  const color = () => state()?.attributes?.hs_color;
380
449
  if (Array.isArray(color())) {
381
- service.getCharacteristic(Characteristic.Hue).onGet(() => Number(color()?.[0]) || 0);
382
- service.getCharacteristic(Characteristic.Saturation).onGet(() => Number(color()?.[1]) || 0);
450
+ service
451
+ .getCharacteristic(Characteristic.Hue)
452
+ .onGet(() => Number(color()?.[0]) || 0);
453
+ service
454
+ .getCharacteristic(Characteristic.Saturation)
455
+ .onGet(() => Number(color()?.[1]) || 0);
383
456
  const setColor = async () => this.callHaWithResponseBudget("light", "turn_on", {
384
- hs_color: [Number(service.getCharacteristic(Characteristic.Hue).value || 0), Number(service.getCharacteristic(Characteristic.Saturation).value || 0)],
457
+ hs_color: [
458
+ Number(service.getCharacteristic(Characteristic.Hue).value || 0),
459
+ Number(service.getCharacteristic(Characteristic.Saturation)
460
+ .value || 0),
461
+ ],
385
462
  });
386
463
  service.getCharacteristic(Characteristic.Hue).onSet(setColor);
387
- service.getCharacteristic(Characteristic.Saturation).onSet(setColor);
464
+ service
465
+ .getCharacteristic(Characteristic.Saturation)
466
+ .onSet(setColor);
388
467
  }
389
468
  }
390
469
  break;
@@ -398,21 +477,30 @@ export class HapGenericAccessory {
398
477
  const min = Number(attrs.min ?? 0);
399
478
  const max = Number(attrs.max ?? 100);
400
479
  const step = Number(attrs.step ?? 1);
401
- return { min, max: max > min ? max : min + 1, step: step > 0 ? step : 1 };
480
+ return {
481
+ min,
482
+ max: max > min ? max : min + 1,
483
+ step: step > 0 ? step : 1,
484
+ };
402
485
  };
403
486
  const percentForValue = () => {
404
487
  const { min, max } = range();
405
488
  const value = Number(state()?.state);
406
- return Math.max(0, Math.min(100, Math.round(((Number.isFinite(value) ? value : min) - min) * 100 / (max - min))));
489
+ return Math.max(0, Math.min(100, Math.round((((Number.isFinite(value) ? value : min) - min) * 100) /
490
+ (max - min))));
407
491
  };
408
- service?.getCharacteristic(Characteristic.On)
492
+ service
493
+ ?.getCharacteristic(Characteristic.On)
409
494
  .onGet(() => 1)
410
495
  .onSet(async () => undefined);
411
- service?.getCharacteristic(Characteristic.Brightness)
496
+ service
497
+ ?.getCharacteristic(Characteristic.Brightness)
412
498
  .onGet(percentForValue)
413
499
  .onSet(async (percent) => {
414
500
  const { min, max, step } = range();
415
- const raw = min + (Math.max(0, Math.min(100, Number(percent) || 0)) / 100) * (max - min);
501
+ const raw = min +
502
+ (Math.max(0, Math.min(100, Number(percent) || 0)) / 100) *
503
+ (max - min);
416
504
  const value = Math.max(min, Math.min(max, Math.round((raw - min) / step) * step + min));
417
505
  await this.callHaWithResponseBudget(domain, "set_value", { value });
418
506
  });
@@ -422,9 +510,12 @@ export class HapGenericAccessory {
422
510
  const service = this.accessory.getService(Service.Fanv2);
423
511
  if (service) {
424
512
  bindPower(service, Characteristic.Active);
425
- service.getCharacteristic(Characteristic.RotationSpeed)
513
+ service
514
+ .getCharacteristic(Characteristic.RotationSpeed)
426
515
  .onGet(() => Number(state()?.attributes?.percentage) || 0)
427
- .onSet(async (value) => this.callHaWithResponseBudget(domain, "set_percentage", { percentage: Number(value) }));
516
+ .onSet(async (value) => this.callHaWithResponseBudget(domain, "set_percentage", {
517
+ percentage: Number(value),
518
+ }));
428
519
  }
429
520
  break;
430
521
  }
@@ -435,17 +526,21 @@ export class HapGenericAccessory {
435
526
  if (!service)
436
527
  break;
437
528
  const active = () => this.isValveActive(state());
438
- service.getCharacteristic(Characteristic.Active)
439
- .onGet(() => active() ? 1 : 0)
529
+ service
530
+ .getCharacteristic(Characteristic.Active)
531
+ .onGet(() => (active() ? 1 : 0))
440
532
  .onSet(async (value) => this.setValveActive(value === 1));
441
- service.getCharacteristic(Characteristic.InUse)
442
- .onGet(() => active() ? 1 : 0);
443
- service.getCharacteristic(Characteristic.SetDuration)
533
+ service
534
+ .getCharacteristic(Characteristic.InUse)
535
+ .onGet(() => (active() ? 1 : 0));
536
+ service
537
+ .getCharacteristic(Characteristic.SetDuration)
444
538
  .onGet(() => this.valveSetDurationSeconds)
445
539
  .onSet(async (value) => {
446
540
  const raw = Number(value);
447
541
  const seconds = Math.floor(raw);
448
- const maximum = Number(service.getCharacteristic(Characteristic.SetDuration).props?.maxValue ?? 86_400);
542
+ const maximum = Number(service.getCharacteristic(Characteristic.SetDuration).props
543
+ ?.maxValue ?? 86_400);
449
544
  if (!Number.isFinite(raw) || seconds < 0 || seconds > maximum)
450
545
  throw -70410;
451
546
  this.valveSetDurationSeconds = seconds;
@@ -462,7 +557,8 @@ export class HapGenericAccessory {
462
557
  service.updateCharacteristic(Characteristic.RemainingDuration, 0);
463
558
  }
464
559
  });
465
- service.getCharacteristic(Characteristic.RemainingDuration)
560
+ service
561
+ .getCharacteristic(Characteristic.RemainingDuration)
466
562
  .onGet(() => this.getValveRemainingDuration());
467
563
  break;
468
564
  }
@@ -477,7 +573,8 @@ export class HapGenericAccessory {
477
573
  case "humidifier":
478
574
  case "dehumidifier": {
479
575
  const svc = this.accessory.addService(Service.HumidifierDehumidifier, this.record.name);
480
- svc.getCharacteristic(Characteristic.Active)
576
+ svc
577
+ .getCharacteristic(Characteristic.Active)
481
578
  .onGet(() => {
482
579
  const ent = this.platform.entities.get(this.entityId);
483
580
  this.platform.log?.info?.(`[HAPCommandTrace][${this.entityId}] read characteristic=Active ha_state=${ent?.state?.state ?? "missing"}`);
@@ -488,33 +585,44 @@ export class HapGenericAccessory {
488
585
  const active = value === 1;
489
586
  await this.callHaWithResponseBudget(domain, active ? "turn_on" : "turn_off");
490
587
  });
491
- svc.getCharacteristic(Characteristic.CurrentHumidifierDehumidifierState)
588
+ svc
589
+ .getCharacteristic(Characteristic.CurrentHumidifierDehumidifierState)
492
590
  .onGet(() => {
493
591
  const ent = this.platform.entities.get(this.entityId);
494
592
  if (ent?.state?.state !== "on")
495
593
  return 1; // INACTIVE
496
594
  return profile === "humidifier" ? 2 : 3; // HUMIDIFYING or DEHUMIDIFYING
497
595
  });
498
- svc.getCharacteristic(Characteristic.TargetHumidifierDehumidifierState)
596
+ svc
597
+ .getCharacteristic(Characteristic.TargetHumidifierDehumidifierState)
499
598
  .setValue(profile === "humidifier" ? 1 : 2)
500
599
  .onGet(() => (profile === "humidifier" ? 1 : 2));
501
- svc.getCharacteristic(Characteristic.CurrentRelativeHumidity)
600
+ svc
601
+ .getCharacteristic(Characteristic.CurrentRelativeHumidity)
502
602
  .onGet(() => {
503
603
  const current = this.getCurrentHumidity();
504
604
  if (current !== undefined)
505
605
  return current;
506
606
  const target = Number(this.getHomeAssistantState(this.entityId)?.attributes?.humidity);
507
- return Number.isFinite(target) && target >= 0 && target <= 100 ? target : 0;
607
+ return Number.isFinite(target) && target >= 0 && target <= 100
608
+ ? target
609
+ : 0;
508
610
  });
509
- svc.getCharacteristic(Characteristic.RelativeHumidityHumidifierThreshold)
611
+ svc
612
+ .getCharacteristic(Characteristic.RelativeHumidityHumidifierThreshold)
510
613
  .onGet(() => {
511
- const value = Number(this.platform.entities.get(this.entityId)?.state?.attributes?.humidity);
512
- return Number.isFinite(value) && value >= 0 && value <= 100 ? value : 0;
614
+ const value = Number(this.platform.entities.get(this.entityId)?.state?.attributes
615
+ ?.humidity);
616
+ return Number.isFinite(value) && value >= 0 && value <= 100
617
+ ? value
618
+ : 0;
513
619
  })
514
620
  .onSet(async (value) => {
515
621
  const [domain] = this.entityId.split(".");
516
622
  svc.updateCharacteristic(Characteristic.RelativeHumidityHumidifierThreshold, Number(value));
517
- await this.callHaWithResponseBudget(domain, "set_humidity", { humidity: Number(value) });
623
+ await this.callHaWithResponseBudget(domain, "set_humidity", {
624
+ humidity: Number(value),
625
+ });
518
626
  });
519
627
  break;
520
628
  }
@@ -534,13 +642,16 @@ export class HapGenericAccessory {
534
642
  case "television": {
535
643
  const tv = this.accessory.addService(Service.Television, this.record.name);
536
644
  const targetMediaId = this.getMediaEntityId();
537
- const mediaState = () => this.platform.entities.get(targetMediaId)?.state ?? this.platform.entities.get(this.entityId)?.state;
645
+ const mediaState = () => this.platform.entities.get(targetMediaId)?.state ??
646
+ this.platform.entities.get(this.entityId)?.state;
538
647
  tv.setCharacteristic(Characteristic.ConfiguredName, this.record.name);
539
648
  tv.setCharacteristic(Characteristic.SleepDiscoveryMode, Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
540
649
  tv.getCharacteristic(Characteristic.Active)
541
650
  .onGet(() => {
542
651
  const st = String(mediaState()?.state ?? "off");
543
- return ["off", "standby", "unavailable", "unknown"].includes(st) ? 0 : 1;
652
+ return ["off", "standby", "unavailable", "unknown"].includes(st)
653
+ ? 0
654
+ : 1;
544
655
  })
545
656
  .onSet(async (value) => this.callHaWithResponseBudget("media_player", value ? "turn_on" : "turn_off", undefined, targetMediaId));
546
657
  const sources = Array.isArray(mediaState()?.attributes?.source_list)
@@ -614,21 +725,24 @@ export class HapGenericAccessory {
614
725
  break;
615
726
  case RemoteKey.SELECT:
616
727
  await sendRemote("DPAD_CENTER", async () => {
617
- const btn = this.getDeviceButton("select") || this.getDeviceButton("enter");
728
+ const btn = this.getDeviceButton("select") ||
729
+ this.getDeviceButton("enter");
618
730
  if (btn)
619
731
  await this.callHaWithResponseBudget("button", "press", undefined, btn);
620
732
  });
621
733
  break;
622
734
  case RemoteKey.BACK:
623
735
  await sendRemote("BACK", async () => {
624
- const btn = this.getDeviceButton("back") || this.getDeviceButton("return");
736
+ const btn = this.getDeviceButton("back") ||
737
+ this.getDeviceButton("return");
625
738
  if (btn)
626
739
  await this.callHaWithResponseBudget("button", "press", undefined, btn);
627
740
  });
628
741
  break;
629
742
  case RemoteKey.EXIT:
630
743
  await sendRemote("HOME", async () => {
631
- const btn = this.getDeviceButton("home") || this.getDeviceButton("exit");
744
+ const btn = this.getDeviceButton("home") ||
745
+ this.getDeviceButton("exit");
632
746
  if (btn)
633
747
  await this.callHaWithResponseBudget("button", "press", undefined, btn);
634
748
  });
@@ -638,7 +752,8 @@ export class HapGenericAccessory {
638
752
  break;
639
753
  case RemoteKey.INFORMATION:
640
754
  await sendRemote("MENU", async () => {
641
- const btn = this.getDeviceButton("menu") || this.getDeviceButton("info");
755
+ const btn = this.getDeviceButton("menu") ||
756
+ this.getDeviceButton("info");
642
757
  if (btn)
643
758
  await this.callHaWithResponseBudget("button", "press", undefined, btn);
644
759
  });
@@ -649,10 +764,13 @@ export class HapGenericAccessory {
649
764
  speaker.setCharacteristic(Characteristic.Active, Characteristic.Active.ACTIVE);
650
765
  speaker.setCharacteristic(Characteristic.VolumeControlType, Characteristic.VolumeControlType.RELATIVE_WITH_CURRENT);
651
766
  const muteSwitchId = this.getMuteSwitchEntityId();
652
- speaker.getCharacteristic(Characteristic.Mute)
767
+ speaker
768
+ .getCharacteristic(Characteristic.Mute)
653
769
  .onGet(() => {
654
770
  const isMediaMuted = Boolean(mediaState()?.attributes?.is_volume_muted);
655
- const isSwitchMuted = muteSwitchId ? this.getHomeAssistantState(muteSwitchId)?.state === "on" : false;
771
+ const isSwitchMuted = muteSwitchId
772
+ ? this.getHomeAssistantState(muteSwitchId)?.state === "on"
773
+ : false;
656
774
  return isMediaMuted || isSwitchMuted;
657
775
  })
658
776
  .onSet(async (value) => {
@@ -662,10 +780,12 @@ export class HapGenericAccessory {
662
780
  }
663
781
  await this.callHaWithResponseBudget("media_player", "volume_mute", { is_volume_muted: isMuted }, targetMediaId).catch(() => { });
664
782
  });
665
- speaker.getCharacteristic(Characteristic.Volume)
783
+ speaker
784
+ .getCharacteristic(Characteristic.Volume)
666
785
  .onGet(() => Math.round((Number(mediaState()?.attributes?.volume_level) || 0) * 100))
667
786
  .onSet(async (value) => this.callHaWithResponseBudget("media_player", "volume_set", { volume_level: Number(value) / 100 }, targetMediaId));
668
- speaker.getCharacteristic(Characteristic.VolumeSelector)
787
+ speaker
788
+ .getCharacteristic(Characteristic.VolumeSelector)
669
789
  .onSet(async (value) => {
670
790
  const inc = value === Characteristic.VolumeSelector.INCREMENT;
671
791
  const remoteId = this.getRemoteEntityId();
@@ -710,8 +830,12 @@ export class HapGenericAccessory {
710
830
  const svc = this.accessory.addService(Service.Valve, this.record.name);
711
831
  const initialState = this.getHomeAssistantState(this.entityId);
712
832
  const initialActive = this.isValveActive(initialState);
713
- svc.getCharacteristic(Characteristic.Active).setValue(initialActive ? 1 : 0);
714
- svc.getCharacteristic(Characteristic.InUse).setValue(initialActive ? 1 : 0);
833
+ svc
834
+ .getCharacteristic(Characteristic.Active)
835
+ .setValue(initialActive ? 1 : 0);
836
+ svc
837
+ .getCharacteristic(Characteristic.InUse)
838
+ .setValue(initialActive ? 1 : 0);
715
839
  svc.setCharacteristic(Characteristic.ValveType, valveType);
716
840
  break;
717
841
  }
@@ -737,7 +861,9 @@ export class HapGenericAccessory {
737
861
  svc
738
862
  .getCharacteristic(Characteristic.TargetDoorState)
739
863
  .setValue(Characteristic.TargetDoorState.CLOSED);
740
- svc.getCharacteristic(Characteristic.ObstructionDetected).setValue(false);
864
+ svc
865
+ .getCharacteristic(Characteristic.ObstructionDetected)
866
+ .setValue(false);
741
867
  break;
742
868
  }
743
869
  // ── Timbre / Videoportero ─────────────────────────────────────────────
@@ -761,20 +887,14 @@ export class HapGenericAccessory {
761
887
  svc
762
888
  .getCharacteristic(Characteristic.TargetHeaterCoolerState)
763
889
  .setValue(0);
764
- svc
765
- .getCharacteristic(Characteristic.CurrentTemperature)
766
- .setValue(20);
890
+ svc.getCharacteristic(Characteristic.CurrentTemperature).setValue(20);
767
891
  break;
768
892
  }
769
893
  // ── Termostato HAP ────────────────────────────────────────────────────
770
894
  case "thermostat_hap": {
771
895
  const svc = this.accessory.addService(Service.Thermostat, this.record.name);
772
- svc
773
- .getCharacteristic(Characteristic.CurrentTemperature)
774
- .setValue(20);
775
- svc
776
- .getCharacteristic(Characteristic.TargetTemperature)
777
- .setValue(21);
896
+ svc.getCharacteristic(Characteristic.CurrentTemperature).setValue(20);
897
+ svc.getCharacteristic(Characteristic.TargetTemperature).setValue(21);
778
898
  svc
779
899
  .getCharacteristic(Characteristic.CurrentHeatingCoolingState)
780
900
  .setValue(0);
@@ -825,12 +945,8 @@ export class HapGenericAccessory {
825
945
  // ── Persiana HAP ──────────────────────────────────────────────────────
826
946
  case "window_covering_hap": {
827
947
  const svc = this.accessory.addService(Service.WindowCovering, this.record.name);
828
- svc
829
- .getCharacteristic(Characteristic.CurrentPosition)
830
- .setValue(0);
831
- svc
832
- .getCharacteristic(Characteristic.TargetPosition)
833
- .setValue(0);
948
+ svc.getCharacteristic(Characteristic.CurrentPosition).setValue(0);
949
+ svc.getCharacteristic(Characteristic.TargetPosition).setValue(0);
834
950
  svc
835
951
  .getCharacteristic(Characteristic.PositionState)
836
952
  .setValue(Characteristic.PositionState.STOPPED);
@@ -859,9 +975,7 @@ export class HapGenericAccessory {
859
975
  // ── Sensor de movimiento ──────────────────────────────────────────────
860
976
  case "motion_sensor_hap": {
861
977
  const svc = this.accessory.addService(Service.MotionSensor, this.record.name);
862
- svc
863
- .getCharacteristic(Characteristic.MotionDetected)
864
- .setValue(false);
978
+ svc.getCharacteristic(Characteristic.MotionDetected).setValue(false);
865
979
  break;
866
980
  }
867
981
  // ── Sensor de contacto ────────────────────────────────────────────────
@@ -915,9 +1029,7 @@ export class HapGenericAccessory {
915
1029
  // ── Sensor temperatura ────────────────────────────────────────────────
916
1030
  case "temperature_sensor_hap": {
917
1031
  const svc = this.accessory.addService(Service.TemperatureSensor, this.record.name);
918
- svc
919
- .getCharacteristic(Characteristic.CurrentTemperature)
920
- .setValue(20);
1032
+ svc.getCharacteristic(Characteristic.CurrentTemperature).setValue(20);
921
1033
  break;
922
1034
  }
923
1035
  // ── Sensor humedad ────────────────────────────────────────────────────
@@ -1057,16 +1169,20 @@ export class HapGenericAccessory {
1057
1169
  this.isPublished = false;
1058
1170
  }
1059
1171
  handlesEntityId(entityId) {
1060
- return entityId === this.entityId || this.getDeviceMembers().some((member) => member.entityId === entityId);
1172
+ return (entityId === this.entityId ||
1173
+ this.getDeviceMembers().some((member) => member.entityId === entityId));
1061
1174
  }
1062
1175
  updateFromHassState(state, sourceEntityId = this.entityId) {
1063
1176
  try {
1064
1177
  if (sourceEntityId !== this.entityId) {
1065
- if ((this.record.hapProfile === "humidifier" || this.record.hapProfile === "dehumidifier") &&
1178
+ if ((this.record.hapProfile === "humidifier" ||
1179
+ this.record.hapProfile === "dehumidifier") &&
1066
1180
  state?.attributes?.device_class === "humidity") {
1067
1181
  const humidity = Number(state?.state);
1068
1182
  if (Number.isFinite(humidity) && humidity >= 0 && humidity <= 100) {
1069
- this.accessory.getService(Service.HumidifierDehumidifier)?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, humidity);
1183
+ this.accessory
1184
+ .getService(Service.HumidifierDehumidifier)
1185
+ ?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, humidity);
1070
1186
  }
1071
1187
  }
1072
1188
  if (this.record.hapProfile === "television") {
@@ -1074,14 +1190,23 @@ export class HapGenericAccessory {
1074
1190
  const targetMediaId = this.getMediaEntityId();
1075
1191
  if (sourceEntityId === muteSwitchId) {
1076
1192
  const isMuted = state?.state === "on";
1077
- this.accessory.getService(Service.TelevisionSpeaker)?.updateCharacteristic(Characteristic.Mute, isMuted);
1193
+ this.accessory
1194
+ .getService(Service.TelevisionSpeaker)
1195
+ ?.updateCharacteristic(Characteristic.Mute, isMuted);
1078
1196
  }
1079
1197
  else if (sourceEntityId === targetMediaId) {
1080
- const isOn = state?.state && !["off", "standby", "unavailable", "unknown"].includes(state.state);
1081
- this.accessory.getService(Service.Television)?.updateCharacteristic(Characteristic.Active, isOn ? 1 : 0);
1082
- this.accessory.getService(Service.TelevisionSpeaker)?.updateCharacteristic(Characteristic.Mute, Boolean(state?.attributes?.is_volume_muted));
1198
+ const isOn = state?.state &&
1199
+ !["off", "standby", "unavailable", "unknown"].includes(state.state);
1200
+ this.accessory
1201
+ .getService(Service.Television)
1202
+ ?.updateCharacteristic(Characteristic.Active, isOn ? 1 : 0);
1203
+ this.accessory
1204
+ .getService(Service.TelevisionSpeaker)
1205
+ ?.updateCharacteristic(Characteristic.Mute, Boolean(state?.attributes?.is_volume_muted));
1083
1206
  if (state?.attributes?.volume_level !== undefined) {
1084
- this.accessory.getService(Service.TelevisionSpeaker)?.updateCharacteristic(Characteristic.Volume, Math.round(Number(state.attributes.volume_level) * 100));
1207
+ this.accessory
1208
+ .getService(Service.TelevisionSpeaker)
1209
+ ?.updateCharacteristic(Characteristic.Volume, Math.round(Number(state.attributes.volume_level) * 100));
1085
1210
  }
1086
1211
  }
1087
1212
  }
@@ -1103,16 +1228,20 @@ export class HapGenericAccessory {
1103
1228
  const on = state?.state === "on";
1104
1229
  switch (this.record.hapProfile) {
1105
1230
  case "switch_hap":
1106
- this.accessory.getService(Service.Switch)?.updateCharacteristic(Characteristic.On, on);
1231
+ this.accessory
1232
+ .getService(Service.Switch)
1233
+ ?.updateCharacteristic(Characteristic.On, on);
1107
1234
  break;
1108
1235
  case "outlet_hap":
1109
- this.accessory.getService(Service.Outlet)?.updateCharacteristic(Characteristic.On, on);
1236
+ this.accessory
1237
+ .getService(Service.Outlet)
1238
+ ?.updateCharacteristic(Characteristic.On, on);
1110
1239
  break;
1111
1240
  case "lightbulb_hap": {
1112
1241
  const light = this.accessory.getService(Service.Lightbulb);
1113
1242
  light?.updateCharacteristic(Characteristic.On, on);
1114
1243
  if (state?.attributes?.brightness !== undefined)
1115
- light?.updateCharacteristic(Characteristic.Brightness, Math.round(Number(state.attributes.brightness) * 100 / 255));
1244
+ light?.updateCharacteristic(Characteristic.Brightness, Math.round((Number(state.attributes.brightness) * 100) / 255));
1116
1245
  if (Array.isArray(state?.attributes?.hs_color)) {
1117
1246
  light?.updateCharacteristic(Characteristic.Hue, Number(state.attributes.hs_color[0]) || 0);
1118
1247
  light?.updateCharacteristic(Characteristic.Saturation, Number(state.attributes.hs_color[1]) || 0);
@@ -1126,7 +1255,7 @@ export class HapGenericAccessory {
1126
1255
  const max = Number(attrs.max ?? 100);
1127
1256
  const value = Number(state?.state);
1128
1257
  const percent = max > min && Number.isFinite(value)
1129
- ? Math.max(0, Math.min(100, Math.round((value - min) * 100 / (max - min))))
1258
+ ? Math.max(0, Math.min(100, Math.round(((value - min) * 100) / (max - min))))
1130
1259
  : 0;
1131
1260
  light?.updateCharacteristic(Characteristic.On, true);
1132
1261
  light?.updateCharacteristic(Characteristic.Brightness, percent);
@@ -1141,14 +1270,25 @@ export class HapGenericAccessory {
1141
1270
  }
1142
1271
  case "television": {
1143
1272
  const targetMediaId = this.getMediaEntityId();
1144
- const targetState = targetMediaId === this.entityId ? state : this.platform.entities.get(targetMediaId)?.state;
1145
- const isOn = targetState?.state && !["off", "standby", "unavailable", "unknown"].includes(targetState.state);
1146
- this.accessory.getService(Service.Television)?.updateCharacteristic(Characteristic.Active, isOn ? 1 : 0);
1273
+ const targetState = targetMediaId === this.entityId
1274
+ ? state
1275
+ : this.platform.entities.get(targetMediaId)?.state;
1276
+ const isOn = targetState?.state &&
1277
+ !["off", "standby", "unavailable", "unknown"].includes(targetState.state);
1278
+ this.accessory
1279
+ .getService(Service.Television)
1280
+ ?.updateCharacteristic(Characteristic.Active, isOn ? 1 : 0);
1147
1281
  const muteSwitchId = this.getMuteSwitchEntityId();
1148
- const isSwitchMuted = muteSwitchId ? this.getHomeAssistantState(muteSwitchId)?.state === "on" : false;
1149
- this.accessory.getService(Service.TelevisionSpeaker)?.updateCharacteristic(Characteristic.Mute, Boolean(targetState?.attributes?.is_volume_muted || isSwitchMuted));
1282
+ const isSwitchMuted = muteSwitchId
1283
+ ? this.getHomeAssistantState(muteSwitchId)?.state === "on"
1284
+ : false;
1285
+ this.accessory
1286
+ .getService(Service.TelevisionSpeaker)
1287
+ ?.updateCharacteristic(Characteristic.Mute, Boolean(targetState?.attributes?.is_volume_muted || isSwitchMuted));
1150
1288
  if (targetState?.attributes?.volume_level !== undefined) {
1151
- this.accessory.getService(Service.TelevisionSpeaker)?.updateCharacteristic(Characteristic.Volume, Math.round(Number(targetState.attributes.volume_level) * 100));
1289
+ this.accessory
1290
+ .getService(Service.TelevisionSpeaker)
1291
+ ?.updateCharacteristic(Characteristic.Volume, Math.round(Number(targetState.attributes.volume_level) * 100));
1152
1292
  }
1153
1293
  break;
1154
1294
  }
@@ -1174,13 +1314,16 @@ export class HapGenericAccessory {
1174
1314
  catch { }
1175
1315
  }
1176
1316
  isValveProfile() {
1177
- return this.record.hapProfile === "valve_irrigation" ||
1317
+ return (this.record.hapProfile === "valve_irrigation" ||
1178
1318
  this.record.hapProfile === "valve_faucet" ||
1179
- this.record.hapProfile === "valve_shower";
1319
+ this.record.hapProfile === "valve_shower");
1180
1320
  }
1181
1321
  isValveActive(state) {
1182
1322
  const value = String(state?.state ?? "").toLowerCase();
1183
- return value === "open" || value === "opening" || value === "closing" || value === "on";
1323
+ return (value === "open" ||
1324
+ value === "opening" ||
1325
+ value === "closing" ||
1326
+ value === "on");
1184
1327
  }
1185
1328
  syncValveState(state) {
1186
1329
  const service = this.accessory.getService(Service.Valve);
@@ -1200,7 +1343,9 @@ export class HapGenericAccessory {
1200
1343
  this.armValveDurationTicker(Number(this.record.valveDeadlineAt));
1201
1344
  }
1202
1345
  }
1203
- else if (active && this.valveSetDurationSeconds > 0 && this.valveDeadlineMs === undefined) {
1346
+ else if (active &&
1347
+ this.valveSetDurationSeconds > 0 &&
1348
+ this.valveDeadlineMs === undefined) {
1204
1349
  // A configured HAP duration also applies when the valve is opened outside
1205
1350
  // HomeKit. Persist it before starting the close countdown.
1206
1351
  const deadline = Date.now() + this.valveSetDurationSeconds * 1000;
@@ -1226,8 +1371,12 @@ export class HapGenericAccessory {
1226
1371
  }
1227
1372
  const domain = this.entityId.split(".")[0];
1228
1373
  const service = domain === "valve"
1229
- ? (active ? "open_valve" : "close_valve")
1230
- : (active ? "turn_on" : "turn_off");
1374
+ ? active
1375
+ ? "open_valve"
1376
+ : "close_valve"
1377
+ : active
1378
+ ? "turn_on"
1379
+ : "turn_off";
1231
1380
  if (active && this.valveSetDurationSeconds > 0) {
1232
1381
  await this.persistValveDeadline(Date.now() + this.valveSetDurationSeconds * 1000);
1233
1382
  }
@@ -1259,7 +1408,10 @@ export class HapGenericAccessory {
1259
1408
  return Math.max(0, Math.ceil((this.valveDeadlineMs - Date.now()) / 1000));
1260
1409
  }
1261
1410
  isValidValveDuration(value) {
1262
- return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 86_400;
1411
+ return (typeof value === "number" &&
1412
+ Number.isInteger(value) &&
1413
+ value >= 0 &&
1414
+ value <= 86_400);
1263
1415
  }
1264
1416
  restoreValveDurationTimer() {
1265
1417
  if (!this.isValveProfile())
@@ -1295,7 +1447,8 @@ export class HapGenericAccessory {
1295
1447
  clearValveDurationTimer(persist = true) {
1296
1448
  this.stopValveDurationTicker();
1297
1449
  this.valveClosePending = false;
1298
- const hadDeadline = this.record.valveDeadlineAt !== undefined || this.record.valveCloseAttempts !== undefined;
1450
+ const hadDeadline = this.record.valveDeadlineAt !== undefined ||
1451
+ this.record.valveCloseAttempts !== undefined;
1299
1452
  delete this.record.valveDeadlineAt;
1300
1453
  delete this.record.valveCloseAttempts;
1301
1454
  if (persist && hadDeadline)
@@ -1326,7 +1479,9 @@ export class HapGenericAccessory {
1326
1479
  const currentValue = String(currentState?.state ?? "").toLowerCase();
1327
1480
  if (["closed", "off", "idle", "closing"].includes(currentValue)) {
1328
1481
  this.clearValveDurationTimer();
1329
- this.accessory.getService(Service.Valve)?.updateCharacteristic(Characteristic.RemainingDuration, 0);
1482
+ this.accessory
1483
+ .getService(Service.Valve)
1484
+ ?.updateCharacteristic(Characteristic.RemainingDuration, 0);
1330
1485
  return;
1331
1486
  }
1332
1487
  let lastError;
@@ -1337,13 +1492,18 @@ export class HapGenericAccessory {
1337
1492
  try {
1338
1493
  const state = this.getHomeAssistantState(this.entityId);
1339
1494
  const value = String(state?.state ?? "").toLowerCase();
1340
- if (value === "unavailable" || value === "unknown" || !value || this.platform.ha?.connected === false) {
1495
+ if (value === "unavailable" ||
1496
+ value === "unknown" ||
1497
+ !value ||
1498
+ this.platform.ha?.connected === false) {
1341
1499
  lastError = new Error("Home Assistant valve state is unavailable");
1342
1500
  break;
1343
1501
  }
1344
1502
  if (["closed", "off", "idle", "closing"].includes(value)) {
1345
1503
  this.clearValveDurationTimer();
1346
- this.accessory.getService(Service.Valve)?.updateCharacteristic(Characteristic.RemainingDuration, 0);
1504
+ this.accessory
1505
+ .getService(Service.Valve)
1506
+ ?.updateCharacteristic(Characteristic.RemainingDuration, 0);
1347
1507
  return;
1348
1508
  }
1349
1509
  if (!this.isValveActive(state))
@@ -1370,7 +1530,9 @@ export class HapGenericAccessory {
1370
1530
  this.valveClosePending = false;
1371
1531
  this.valveDeadlineMs = undefined;
1372
1532
  await this.platform.saveHapAccessoryRecords?.();
1373
- this.accessory.getService(Service.Valve)?.updateCharacteristic(Characteristic.RemainingDuration, 0);
1533
+ this.accessory
1534
+ .getService(Service.Valve)
1535
+ ?.updateCharacteristic(Characteristic.RemainingDuration, 0);
1374
1536
  return;
1375
1537
  }
1376
1538
  catch (error) {
@@ -1395,32 +1557,40 @@ export class HapGenericAccessory {
1395
1557
  supportsAlarmNight() {
1396
1558
  const night = Characteristic.SecuritySystemTargetState.NIGHT_ARM;
1397
1559
  const characteristic = this.getSecuritySystemService()?.getCharacteristic(Characteristic.SecuritySystemTargetState);
1398
- return Number.isInteger(night) &&
1560
+ return (Number.isInteger(night) &&
1399
1561
  Array.isArray(characteristic?.props?.validValues) &&
1400
- characteristic.props.validValues.includes(night);
1562
+ characteristic.props.validValues.includes(night));
1401
1563
  }
1402
1564
  mapAlarmMode(value) {
1403
1565
  switch (value) {
1404
- case "disarmed": return Characteristic.SecuritySystemCurrentState.DISARMED;
1405
- case "armed_home": return Characteristic.SecuritySystemCurrentState.STAY_ARM;
1406
- case "armed_away": return Characteristic.SecuritySystemCurrentState.AWAY_ARM;
1566
+ case "disarmed":
1567
+ return Characteristic.SecuritySystemCurrentState.DISARMED;
1568
+ case "armed_home":
1569
+ return Characteristic.SecuritySystemCurrentState.STAY_ARM;
1570
+ case "armed_away":
1571
+ return Characteristic.SecuritySystemCurrentState.AWAY_ARM;
1407
1572
  case "armed_night":
1408
1573
  return this.supportsAlarmNight()
1409
1574
  ? Characteristic.SecuritySystemCurrentState.NIGHT_ARM
1410
1575
  : undefined;
1411
- default: return undefined;
1576
+ default:
1577
+ return undefined;
1412
1578
  }
1413
1579
  }
1414
1580
  mapAlarmTarget(value) {
1415
1581
  switch (value) {
1416
- case "disarmed": return Characteristic.SecuritySystemTargetState.DISARM;
1417
- case "armed_home": return Characteristic.SecuritySystemTargetState.STAY_ARM;
1418
- case "armed_away": return Characteristic.SecuritySystemTargetState.AWAY_ARM;
1582
+ case "disarmed":
1583
+ return Characteristic.SecuritySystemTargetState.DISARM;
1584
+ case "armed_home":
1585
+ return Characteristic.SecuritySystemTargetState.STAY_ARM;
1586
+ case "armed_away":
1587
+ return Characteristic.SecuritySystemTargetState.AWAY_ARM;
1419
1588
  case "armed_night":
1420
1589
  return this.supportsAlarmNight()
1421
1590
  ? Characteristic.SecuritySystemTargetState.NIGHT_ARM
1422
1591
  : undefined;
1423
- default: return undefined;
1592
+ default:
1593
+ return undefined;
1424
1594
  }
1425
1595
  }
1426
1596
  getAlarmCurrentState() {