@switchbot/homebridge-switchbot 5.2.9-beta.1 → 5.2.10-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/devices/genericDevice.d.ts.map +1 -1
  2. package/dist/devices/genericDevice.js +528 -118
  3. package/dist/devices/genericDevice.js.map +1 -1
  4. package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -1
  5. package/dist/homebridge-ui/public/js/advanced-settings.js +3 -1
  6. package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -1
  7. package/dist/homebridge-ui/public/js/advanced-settings.ts +3 -1
  8. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
  9. package/dist/homebridge-ui/public/js/api.js +21 -7
  10. package/dist/homebridge-ui/public/js/api.js.map +1 -1
  11. package/dist/homebridge-ui/public/js/api.ts +21 -7
  12. package/dist/homebridge-ui/public/js/app.js +74 -16
  13. package/dist/homebridge-ui/public/js/app.js.map +2 -2
  14. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -1
  15. package/dist/homebridge-ui/public/js/credentials.js +9 -3
  16. package/dist/homebridge-ui/public/js/credentials.js.map +1 -1
  17. package/dist/homebridge-ui/public/js/credentials.ts +9 -3
  18. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -1
  19. package/dist/homebridge-ui/public/js/devices-delete.js +6 -2
  20. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -1
  21. package/dist/homebridge-ui/public/js/devices-delete.ts +6 -2
  22. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
  23. package/dist/homebridge-ui/public/js/devices.js +3 -1
  24. package/dist/homebridge-ui/public/js/devices.js.map +1 -1
  25. package/dist/homebridge-ui/public/js/devices.ts +3 -1
  26. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -1
  27. package/dist/homebridge-ui/public/js/discovery.js +89 -25
  28. package/dist/homebridge-ui/public/js/discovery.js.map +1 -1
  29. package/dist/homebridge-ui/public/js/discovery.ts +89 -25
  30. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -1
  31. package/dist/homebridge-ui/public/js/modals.js +13 -3
  32. package/dist/homebridge-ui/public/js/modals.js.map +1 -1
  33. package/dist/homebridge-ui/public/js/modals.ts +13 -3
  34. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -1
  35. package/dist/homebridge-ui/public/js/render.js +67 -17
  36. package/dist/homebridge-ui/public/js/render.js.map +1 -1
  37. package/dist/homebridge-ui/public/js/render.ts +67 -17
  38. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -1
  39. package/dist/homebridge-ui/public/js/toast.js +6 -2
  40. package/dist/homebridge-ui/public/js/toast.js.map +1 -1
  41. package/dist/homebridge-ui/public/js/toast.ts +6 -2
  42. package/docs/variables/default.html +1 -1
  43. package/package.json +9 -9
  44. package/src/devices/genericDevice.ts +529 -129
  45. package/src/homebridge-ui/public/js/advanced-settings.ts +3 -1
  46. package/src/homebridge-ui/public/js/api.ts +21 -7
  47. package/src/homebridge-ui/public/js/credentials.ts +9 -3
  48. package/src/homebridge-ui/public/js/devices-delete.ts +6 -2
  49. package/src/homebridge-ui/public/js/devices.ts +3 -1
  50. package/src/homebridge-ui/public/js/discovery.ts +89 -25
  51. package/src/homebridge-ui/public/js/modals.ts +13 -3
  52. package/src/homebridge-ui/public/js/render.ts +67 -17
  53. package/src/homebridge-ui/public/js/toast.ts +6 -2
  54. package/test/client/node-switchbot-commands.spec.ts +44 -8
  55. package/test/client/switchbot-client-debounce.spec.ts +24 -3
  56. package/test/client/switchbot-client-discovery.spec.ts +26 -5
  57. package/test/client/switchbot-client-keys.spec.ts +30 -7
  58. package/test/client/switchbot-client-openapi.spec.ts +6 -1
  59. package/test/client/switchbotClient.spec.ts +30 -6
  60. package/test/device/bot-hap.spec.ts +131 -22
  61. package/test/device/curtain-ble-position.spec.ts +15 -3
  62. package/test/device/deviceBase.spec.ts +6 -1
  63. package/test/device/deviceFactory-edge.spec.ts +12 -2
  64. package/test/device/deviceFactory.spec.ts +6 -1
  65. package/test/device/fan-swing.spec.ts +9 -2
  66. package/test/device/genericDevice-blepoll.spec.ts +17 -3
  67. package/test/device/getstate-cache.spec.ts +37 -6
  68. package/test/device/getstate-returns-status.spec.ts +65 -13
  69. package/test/device/lock-users.spec.ts +24 -7
  70. package/test/device/matter-descriptors.spec.ts +6 -1
  71. package/test/device/matter-device-state.spec.ts +6 -1
  72. package/test/device/meter-battery.spec.ts +86 -14
  73. package/test/device/meter-co2.spec.ts +65 -10
  74. package/test/device/model-identities.spec.ts +6 -1
  75. package/test/device/water-detector-battery.spec.ts +19 -3
  76. package/test/device/water-detector-leak.spec.ts +6 -1
  77. package/test/helpers/matter-harness.ts +21 -4
  78. package/test/platform/accessory-restore.spec.ts +18 -3
  79. package/test/platform/hap-cache-restart.spec.ts +66 -13
  80. package/test/platform/matter-childbridge.spec.ts +16 -3
  81. package/test/platform/matter-integration.spec.ts +6 -1
  82. package/test/platform/matter-registration.spec.ts +47 -10
  83. package/test/platform/platform-edge.spec.ts +13 -3
  84. package/test/platform/platform.integration.spec.ts +16 -3
  85. package/test/utils/utils.spec.ts +42 -8
@@ -5,7 +5,9 @@ import { MATTER_ATTRIBUTE_IDS, MATTER_CLUSTER_IDS } from '../utils.js';
5
5
  import { DeviceBase } from './deviceBase.js';
6
6
  function validateBLEResponseLength(buf, expected, context = '', log) {
7
7
  if (!buf || typeof buf.length !== 'number' || buf.length !== expected) {
8
- log.warn(`[BLE] Invalid response length${context ? ` for ${context}` : ''}: expected ${expected}, got ${buf?.length}`);
8
+ log.warn(`[BLE] Invalid response length${context
9
+ ? ` for ${context}`
10
+ : ''}: expected ${expected}, got ${buf?.length}`);
9
11
  return false;
10
12
  }
11
13
  return true;
@@ -176,7 +178,10 @@ export class GenericDevice extends DeviceBase {
176
178
  // at its fallback for the whole window after one transient error.
177
179
  return { id: this.opts.id, type: this.opts.type, unreadable: true };
178
180
  }
179
- this.stateCache = { at: Date.now(), value };
181
+ this.stateCache = {
182
+ at: Date.now(),
183
+ value,
184
+ };
180
185
  return value;
181
186
  })
182
187
  .finally(() => {
@@ -193,7 +198,12 @@ export class GenericDevice extends DeviceBase {
193
198
  if (raw && (raw instanceof Buffer || Array.isArray(raw) || raw instanceof Uint8Array)) {
194
199
  // Default to 12, override per device if needed
195
200
  if (!validateBLEResponseLength(raw, 12, this.opts.type, this.log)) {
196
- return { id: this.opts.id, type: this.opts.type, error: 'invalid_ble_response_length', raw };
201
+ return {
202
+ id: this.opts.id,
203
+ type: this.opts.type,
204
+ error: 'invalid_ble_response_length',
205
+ raw,
206
+ };
197
207
  }
198
208
  }
199
209
  // Normalize common response shapes
@@ -215,7 +225,9 @@ export class GenericDevice extends DeviceBase {
215
225
  }
216
226
  }
217
227
  catch (e) {
218
- this.log?.debug?.(`getState: could not read status for ${this.opts.id}:`, e instanceof Error ? e.message : e);
228
+ this.log?.debug?.(`getState: could not read status for ${this.opts.id}:`, e instanceof Error
229
+ ? e.message
230
+ : e);
219
231
  }
220
232
  }
221
233
  catch (e) {
@@ -338,8 +350,14 @@ export class GenericDevice extends DeviceBase {
338
350
  type: 'OnOff',
339
351
  clusterId: MATTER_CLUSTER_IDS.OnOff,
340
352
  attributes: {
341
- onOff: { read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on', write: async (v) => this.setState({ on: !!v }) },
342
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on', write: async (v) => this.setState({ on: !!v }) },
353
+ onOff: {
354
+ read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on',
355
+ write: async (v) => this.setState({ on: !!v }),
356
+ },
357
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
358
+ read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on',
359
+ write: async (v) => this.setState({ on: !!v }),
360
+ },
343
361
  },
344
362
  });
345
363
  }
@@ -349,8 +367,18 @@ export class GenericDevice extends DeviceBase {
349
367
  type: 'LevelControl',
350
368
  clusterId: MATTER_CLUSTER_IDS.LevelControl,
351
369
  attributes: {
352
- currentLevel: { read: async () => (await this.getState()).brightness ?? 100, write: async (v) => this.setState({ brightness: Number(v) }) },
353
- [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => (await this.getState()).brightness ?? 100, write: async (v) => this.setState({ brightness: Number(v) }) },
370
+ currentLevel: {
371
+ read: async () => (await this.getState()).brightness ?? 100,
372
+ write: async (v) => this.setState({
373
+ brightness: Number(v),
374
+ }),
375
+ },
376
+ [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: {
377
+ read: async () => (await this.getState()).brightness ?? 100,
378
+ write: async (v) => this.setState({
379
+ brightness: Number(v),
380
+ }),
381
+ },
354
382
  },
355
383
  });
356
384
  }
@@ -360,15 +388,51 @@ export class GenericDevice extends DeviceBase {
360
388
  type: 'ColorControl',
361
389
  clusterId: MATTER_CLUSTER_IDS.ColorControl,
362
390
  attributes: {
363
- colorMode: { read: async () => 0 },
364
- colorHue: { read: async () => (await this.getState()).hue ?? 0, write: async (v) => this.setState({ hue: Number(v) }) },
365
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => (await this.getState()).hue ?? 0, write: async (v) => this.setState({ hue: Number(v) }) },
366
- colorSaturation: { read: async () => (await this.getState()).saturation ?? 0, write: async (v) => this.setState({ saturation: Number(v) }) },
367
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => (await this.getState()).saturation ?? 0, write: async (v) => this.setState({ saturation: Number(v) }) },
391
+ colorMode: {
392
+ read: async () => 0,
393
+ },
394
+ colorHue: {
395
+ read: async () => (await this.getState()).hue ?? 0,
396
+ write: async (v) => this.setState({
397
+ hue: Number(v),
398
+ }),
399
+ },
400
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: {
401
+ read: async () => (await this.getState()).hue ?? 0,
402
+ write: async (v) => this.setState({
403
+ hue: Number(v),
404
+ }),
405
+ },
406
+ colorSaturation: {
407
+ read: async () => (await this.getState()).saturation ?? 0,
408
+ write: async (v) => this.setState({
409
+ saturation: Number(v),
410
+ }),
411
+ },
412
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: {
413
+ read: async () => (await this.getState()).saturation ?? 0,
414
+ write: async (v) => this.setState({
415
+ saturation: Number(v),
416
+ }),
417
+ },
368
418
  ...(typeof state.colorTemperature === 'number' || typeof state.kelvin === 'number'
369
419
  ? {
370
- colorTemperature: { read: async () => typeof (await this.getState()).colorTemperature === 'number' ? (await this.getState()).colorTemperature : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)), write: async (v) => this.setState({ colorTemperature: Number(v) }) },
371
- [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => typeof (await this.getState()).colorTemperature === 'number' ? (await this.getState()).colorTemperature : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)), write: async (v) => this.setState({ colorTemperature: Number(v) }) },
420
+ colorTemperature: {
421
+ read: async () => typeof (await this.getState()).colorTemperature === 'number'
422
+ ? (await this.getState()).colorTemperature
423
+ : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)),
424
+ write: async (v) => this.setState({
425
+ colorTemperature: Number(v),
426
+ }),
427
+ },
428
+ [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: {
429
+ read: async () => typeof (await this.getState()).colorTemperature === 'number'
430
+ ? (await this.getState()).colorTemperature
431
+ : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)),
432
+ write: async (v) => this.setState({
433
+ colorTemperature: Number(v),
434
+ }),
435
+ },
372
436
  }
373
437
  : {}),
374
438
  },
@@ -380,7 +444,9 @@ export class GenericDevice extends DeviceBase {
380
444
  type: 'TemperatureMeasurement',
381
445
  // No clusterId, not present in MATTER_CLUSTER_IDS
382
446
  attributes: {
383
- measuredValue: { read: async () => (await this.getState()).temperature ?? 0 },
447
+ measuredValue: {
448
+ read: async () => (await this.getState()).temperature ?? 0,
449
+ },
384
450
  },
385
451
  });
386
452
  }
@@ -390,7 +456,9 @@ export class GenericDevice extends DeviceBase {
390
456
  type: 'RelativeHumidityMeasurement',
391
457
  clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
392
458
  attributes: {
393
- measuredValue: { read: async () => (await this.getState()).humidity ?? 0 },
459
+ measuredValue: {
460
+ read: async () => (await this.getState()).humidity ?? 0,
461
+ },
394
462
  },
395
463
  });
396
464
  }
@@ -399,7 +467,9 @@ export class GenericDevice extends DeviceBase {
399
467
  clusters.push({
400
468
  type: 'AirQuality',
401
469
  attributes: {
402
- CO2: { read: async () => (await this.getState()).CO2 ?? 0 },
470
+ CO2: {
471
+ read: async () => (await this.getState()).CO2 ?? 0,
472
+ },
403
473
  },
404
474
  });
405
475
  }
@@ -409,7 +479,12 @@ export class GenericDevice extends DeviceBase {
409
479
  type: 'DoorLock',
410
480
  clusterId: MATTER_CLUSTER_IDS.DoorLock,
411
481
  attributes: {
412
- lockState: { read: async () => (await this.getState()).lockState ?? (await this.getState()).locked ? 1 : 0, write: async (v) => this.setState({ locked: !!v }) },
482
+ lockState: {
483
+ read: async () => (await this.getState()).lockState ?? (await this.getState()).locked
484
+ ? 1
485
+ : 0,
486
+ write: async (v) => this.setState({ locked: !!v }),
487
+ },
413
488
  },
414
489
  });
415
490
  }
@@ -419,7 +494,11 @@ export class GenericDevice extends DeviceBase {
419
494
  type: 'OccupancySensing',
420
495
  // No clusterId, not present in MATTER_CLUSTER_IDS
421
496
  attributes: {
422
- occupancy: { read: async () => (await this.getState()).moveDetected === true || (await this.getState()).motion === true ? 1 : 0 },
497
+ occupancy: {
498
+ read: async () => (await this.getState()).moveDetected === true || (await this.getState()).motion === true
499
+ ? 1
500
+ : 0,
501
+ },
423
502
  },
424
503
  });
425
504
  }
@@ -429,7 +508,11 @@ export class GenericDevice extends DeviceBase {
429
508
  type: 'BooleanState',
430
509
  // No clusterId, not present in MATTER_CLUSTER_IDS
431
510
  attributes: {
432
- stateValue: { read: async () => (await this.getState()).openState === 'open' || (await this.getState()).open === true ? 1 : 0 },
511
+ stateValue: {
512
+ read: async () => (await this.getState()).openState === 'open' || (await this.getState()).open === true
513
+ ? 1
514
+ : 0,
515
+ },
433
516
  },
434
517
  });
435
518
  }
@@ -438,7 +521,11 @@ export class GenericDevice extends DeviceBase {
438
521
  clusters.push({
439
522
  type: 'LeakSensor',
440
523
  attributes: {
441
- leakDetected: { read: async () => (await this.getState()).leak === true || (await this.getState()).status === 1 ? 1 : 0 },
524
+ leakDetected: {
525
+ read: async () => (await this.getState()).leak === true || (await this.getState()).status === 1
526
+ ? 1
527
+ : 0,
528
+ },
442
529
  },
443
530
  });
444
531
  }
@@ -448,9 +535,15 @@ export class GenericDevice extends DeviceBase {
448
535
  type: 'ElectricalMeasurement',
449
536
  // No clusterId, not present in MATTER_CLUSTER_IDS
450
537
  attributes: {
451
- voltage: { read: async () => (await this.getState()).voltage ?? 0 },
452
- power: { read: async () => (await this.getState()).power ?? 0 },
453
- electricCurrent: { read: async () => (await this.getState()).electricCurrent ?? 0 },
538
+ voltage: {
539
+ read: async () => (await this.getState()).voltage ?? 0,
540
+ },
541
+ power: {
542
+ read: async () => (await this.getState()).power ?? 0,
543
+ },
544
+ electricCurrent: {
545
+ read: async () => (await this.getState()).electricCurrent ?? 0,
546
+ },
454
547
  },
455
548
  });
456
549
  }
@@ -460,7 +553,12 @@ export class GenericDevice extends DeviceBase {
460
553
  type: 'FanControl',
461
554
  clusterId: MATTER_CLUSTER_IDS.FanControl,
462
555
  attributes: {
463
- speedCurrent: { read: async () => (await this.getState()).speed ?? (await this.getState()).fanSpeed ?? 0, write: async (v) => this.setState({ speed: Number(v) }) },
556
+ speedCurrent: {
557
+ read: async () => (await this.getState()).speed ?? (await this.getState()).fanSpeed ?? 0,
558
+ write: async (v) => this.setState({
559
+ speed: Number(v),
560
+ }),
561
+ },
464
562
  },
465
563
  });
466
564
  }
@@ -469,7 +567,9 @@ export class GenericDevice extends DeviceBase {
469
567
  clusters.push({
470
568
  type: 'RobotVacuumCleaner',
471
569
  attributes: {
472
- workingStatus: { read: async () => (await this.getState()).workingStatus ?? 'StandBy' },
570
+ workingStatus: {
571
+ read: async () => (await this.getState()).workingStatus ?? 'StandBy',
572
+ },
473
573
  },
474
574
  });
475
575
  }
@@ -506,55 +606,124 @@ export class BotDevice extends GenericDevice {
506
606
  if (pressMode && !on) {
507
607
  return;
508
608
  }
509
- const command = pressMode ? 'press' : on ? 'turnOn' : 'turnOff';
609
+ const command = pressMode
610
+ ? 'press'
611
+ : on ? 'turnOn' : 'turnOff';
510
612
  const result = await this.setState({ command, parameter: 'default', commandType: 'command' });
511
613
  if (result !== true && result?.success !== true) {
512
614
  throw new Error(`SwitchBot Bot ${command} failed: ${result?.reason ?? 'unknown error'}`);
513
615
  }
514
616
  if (!pressMode) {
515
- this.lastCommand = { on, at: Date.now() };
617
+ this.lastCommand = {
618
+ on,
619
+ at: Date.now(),
620
+ };
516
621
  }
517
622
  };
518
623
  const control = (name, active, inactive, requestedOn) => ({
519
- get: async () => (await isOn()) ? active : inactive,
624
+ get: async () => (await isOn())
625
+ ? active
626
+ : inactive,
520
627
  set: async (value) => setOn(requestedOn(value)),
521
- ...(pressMode ? { refreshAfterSet: [name] } : {}),
628
+ ...(pressMode
629
+ ? {
630
+ refreshAfterSet: [name],
631
+ }
632
+ : {}),
522
633
  });
523
634
  const position = () => ({
524
- CurrentPosition: { get: async () => (await isOn()) ? 100 : 0 },
525
- PositionState: { get: async () => 2 },
635
+ CurrentPosition: {
636
+ get: async () => (await isOn())
637
+ ? 100
638
+ : 0,
639
+ },
640
+ PositionState: {
641
+ get: async () => 2,
642
+ },
526
643
  TargetPosition: control('TargetPosition', 100, 0, value => Number(value) > 0),
527
644
  });
528
645
  const active = (value) => Number(value) === 1;
529
646
  const presentations = {
530
- switch: { type: 'Switch', characteristics: { On: control('On', true, false, value => value === true) } },
531
- outlet: { type: 'Outlet', characteristics: { On: control('On', true, false, value => value === true) } },
532
- door: { type: 'Door', characteristics: position() },
533
- window: { type: 'Window', characteristics: position() },
534
- windowcovering: { type: 'WindowCovering', characteristics: position() },
535
- garagedoor: { type: 'GarageDoorOpener', characteristics: {
536
- CurrentDoorState: { get: async () => (await isOn()) ? 0 : 1 },
647
+ switch: {
648
+ type: 'Switch',
649
+ characteristics: {
650
+ On: control('On', true, false, value => value === true),
651
+ },
652
+ },
653
+ outlet: {
654
+ type: 'Outlet',
655
+ characteristics: {
656
+ On: control('On', true, false, value => value === true),
657
+ },
658
+ },
659
+ door: {
660
+ type: 'Door',
661
+ characteristics: position(),
662
+ },
663
+ window: {
664
+ type: 'Window',
665
+ characteristics: position(),
666
+ },
667
+ windowcovering: {
668
+ type: 'WindowCovering',
669
+ characteristics: position(),
670
+ },
671
+ garagedoor: {
672
+ type: 'GarageDoorOpener',
673
+ characteristics: {
674
+ CurrentDoorState: {
675
+ get: async () => (await isOn())
676
+ ? 0
677
+ : 1,
678
+ },
537
679
  TargetDoorState: control('TargetDoorState', 0, 1, value => Number(value) === 0),
538
- ObstructionDetected: { get: async () => false },
539
- } },
540
- lock: { type: 'LockMechanism', characteristics: {
541
- LockCurrentState: { get: async () => (await isOn()) ? 0 : 1 },
680
+ ObstructionDetected: {
681
+ get: async () => false,
682
+ },
683
+ },
684
+ },
685
+ lock: {
686
+ type: 'LockMechanism',
687
+ characteristics: {
688
+ LockCurrentState: {
689
+ get: async () => (await isOn())
690
+ ? 0
691
+ : 1,
692
+ },
542
693
  LockTargetState: control('LockTargetState', 0, 1, value => Number(value) === 0),
543
- } },
544
- faucet: { type: 'Faucet', characteristics: { Active: control('Active', 1, 0, active) } },
545
- fan: { type: 'Fanv2', characteristics: { Active: control('Active', 1, 0, active) } },
546
- stateful: { type: 'StatefulProgrammableSwitch', characteristics: {
694
+ },
695
+ },
696
+ faucet: {
697
+ type: 'Faucet',
698
+ characteristics: {
699
+ Active: control('Active', 1, 0, active),
700
+ },
701
+ },
702
+ fan: {
703
+ type: 'Fanv2',
704
+ characteristics: {
705
+ Active: control('Active', 1, 0, active),
706
+ },
707
+ },
708
+ stateful: {
709
+ type: 'StatefulProgrammableSwitch',
710
+ characteristics: {
547
711
  ProgrammableSwitchEvent: {},
548
712
  ProgrammableSwitchOutputState: {
549
713
  ...control('ProgrammableSwitchOutputState', 1, 0, active),
550
- ...(pressMode ? { refreshAfterSet: ['ProgrammableSwitchOutputState'] } : {}),
714
+ ...(pressMode
715
+ ? {
716
+ refreshAfterSet: ['ProgrammableSwitchOutputState'],
717
+ }
718
+ : {}),
551
719
  afterSet: (value, service, hap) => {
552
720
  if (!pressMode || active(value)) {
553
721
  service.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).sendEventNotification(0);
554
722
  }
555
723
  },
556
724
  },
557
- } },
725
+ },
726
+ },
558
727
  };
559
728
  return {
560
729
  services: [presentations[display] ?? presentations.switch],
@@ -637,9 +806,15 @@ export class CurtainDevice extends GenericDevice {
637
806
  }
638
807
  const previousPosition = this.lastKnownPosition;
639
808
  this.lastTargetPosition = position;
640
- this.positionState = position > this.lastKnownPosition ? 1 : position < this.lastKnownPosition ? 0 : 2;
809
+ this.positionState = position > this.lastKnownPosition
810
+ ? 1
811
+ : position < this.lastKnownPosition
812
+ ? 0
813
+ : 2;
641
814
  try {
642
- const result = await this.setState({ position: this.toSwitchBotPosition(position) });
815
+ const result = await this.setState({
816
+ position: this.toSwitchBotPosition(position),
817
+ });
643
818
  if (result === false || result?.success === false) {
644
819
  throw new Error(result?.reason ?? 'Curtain position command failed');
645
820
  }
@@ -673,16 +848,22 @@ export class CurtainDevice extends GenericDevice {
673
848
  currentPositionLiftPercent100ths: {
674
849
  read: async () => {
675
850
  const s = await this.getState();
676
- return typeof s.position === 'number' ? Math.round(s.position * 100) : 0;
851
+ return typeof s.position === 'number'
852
+ ? Math.round(s.position * 100)
853
+ : 0;
677
854
  },
678
855
  write: undefined,
679
856
  },
680
857
  targetPositionLiftPercent100ths: {
681
858
  read: async () => {
682
859
  const s = await this.getState();
683
- return typeof s.position === 'number' ? Math.round(s.position * 100) : 0;
860
+ return typeof s.position === 'number'
861
+ ? Math.round(s.position * 100)
862
+ : 0;
684
863
  },
685
- write: async (v) => this.setState({ position: Math.round(Number(v) / 100) }),
864
+ write: async (v) => this.setState({
865
+ position: Math.round(Number(v) / 100),
866
+ }),
686
867
  },
687
868
  operationalStatus: {
688
869
  read: async () => state.operationalStatus ?? { global: 0, lift: 0, tilt: 0 },
@@ -710,16 +891,22 @@ export class CurtainDevice extends GenericDevice {
710
891
  attributes.currentPositionTiltPercent100ths = {
711
892
  read: async () => {
712
893
  const s = await this.getState();
713
- return typeof s.tilt === 'number' ? Math.round(s.tilt * 100) : 0;
894
+ return typeof s.tilt === 'number'
895
+ ? Math.round(s.tilt * 100)
896
+ : 0;
714
897
  },
715
898
  write: undefined,
716
899
  };
717
900
  attributes.targetPositionTiltPercent100ths = {
718
901
  read: async () => {
719
902
  const s = await this.getState();
720
- return typeof s.tilt === 'number' ? Math.round(s.tilt * 100) : 0;
903
+ return typeof s.tilt === 'number'
904
+ ? Math.round(s.tilt * 100)
905
+ : 0;
721
906
  },
722
- write: async (v) => this.setState({ tilt: Math.round(Number(v) / 100) }),
907
+ write: async (v) => this.setState({
908
+ tilt: Math.round(Number(v) / 100),
909
+ }),
723
910
  };
724
911
  }
725
912
  const windowCoveringCluster = {
@@ -760,10 +947,14 @@ export class FanDevice extends GenericDevice {
760
947
  RotationSpeed: {
761
948
  get: async () => {
762
949
  const s = await this.getState();
763
- return typeof s.speed === 'number' ? s.speed : 0;
950
+ return typeof s.speed === 'number'
951
+ ? s.speed
952
+ : 0;
764
953
  },
765
954
  set: async (v) => {
766
- await this.setState({ speed: Number(v) });
955
+ await this.setState({
956
+ speed: Number(v),
957
+ });
767
958
  },
768
959
  },
769
960
  },
@@ -777,7 +968,11 @@ export class FanDevice extends GenericDevice {
777
968
  }
778
969
  // Oscillation support
779
970
  if (typeof change.oscillate === 'boolean') {
780
- const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
971
+ const body = {
972
+ command: 'setOscillation',
973
+ parameter: change.oscillate ? 'on' : 'off',
974
+ commandType: 'command',
975
+ };
781
976
  try {
782
977
  return await this.client.setDeviceState(this.opts.id, body);
783
978
  }
@@ -833,9 +1028,15 @@ export class FanDevice extends GenericDevice {
833
1028
  type: 'OnOff',
834
1029
  clusterId: MATTER_CLUSTER_IDS.OnOff,
835
1030
  attributes: {
836
- onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
1031
+ onOff: {
1032
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); },
1033
+ write: async (v) => this.setState({ on: !!v }),
1034
+ },
837
1035
  // numeric attribute id for onOff
838
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
1036
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
1037
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); },
1038
+ write: async (v) => this.setState({ on: !!v }),
1039
+ },
839
1040
  },
840
1041
  },
841
1042
  {
@@ -843,10 +1044,36 @@ export class FanDevice extends GenericDevice {
843
1044
  type: 'FanControl',
844
1045
  clusterId: MATTER_CLUSTER_IDS.FanControl,
845
1046
  attributes: {
846
- rotationSpeed: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
847
- [MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
848
- oscillation: { read: async () => { const s = await this.getState(); return !!s?.oscillating; }, write: async (v) => this.setState({ oscillate: !!v }) },
849
- swingMode: { read: async () => { const s = await this.getState(); return s?.swingMode ?? null; }, write: async (v) => this.setState({ swingMode: v }) },
1047
+ rotationSpeed: {
1048
+ read: async () => {
1049
+ const s = await this.getState();
1050
+ return typeof s.speed === 'number'
1051
+ ? s.speed
1052
+ : 0;
1053
+ },
1054
+ write: async (v) => this.setState({
1055
+ speed: Number(v),
1056
+ }),
1057
+ },
1058
+ [MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: {
1059
+ read: async () => {
1060
+ const s = await this.getState();
1061
+ return typeof s.speed === 'number'
1062
+ ? s.speed
1063
+ : 0;
1064
+ },
1065
+ write: async (v) => this.setState({
1066
+ speed: Number(v),
1067
+ }),
1068
+ },
1069
+ oscillation: {
1070
+ read: async () => { const s = await this.getState(); return !!s?.oscillating; },
1071
+ write: async (v) => this.setState({ oscillate: !!v }),
1072
+ },
1073
+ swingMode: {
1074
+ read: async () => { const s = await this.getState(); return s?.swingMode ?? null; },
1075
+ write: async (v) => this.setState({ swingMode: v }),
1076
+ },
850
1077
  },
851
1078
  },
852
1079
  ],
@@ -873,10 +1100,14 @@ export class LightDevice extends GenericDevice {
873
1100
  props: { minValue: 0, maxValue: 100, minStep: 1 },
874
1101
  get: async () => {
875
1102
  const s = await this.getState();
876
- return typeof s.brightness === 'number' ? s.brightness : 100;
1103
+ return typeof s.brightness === 'number'
1104
+ ? s.brightness
1105
+ : 100;
877
1106
  },
878
1107
  set: async (v) => {
879
- await this.setState({ brightness: Number(v) });
1108
+ await this.setState({
1109
+ brightness: Number(v),
1110
+ });
880
1111
  },
881
1112
  },
882
1113
  Hue: {
@@ -926,7 +1157,9 @@ export class LightDevice extends GenericDevice {
926
1157
  return 0;
927
1158
  },
928
1159
  set: async (v) => {
929
- await this.setState({ hue: Number(v) });
1160
+ await this.setState({
1161
+ hue: Number(v),
1162
+ });
930
1163
  },
931
1164
  },
932
1165
  Saturation: {
@@ -946,13 +1179,17 @@ export class LightDevice extends GenericDevice {
946
1179
  const mx = Math.max(r, g, b);
947
1180
  const mn = Math.min(r, g, b);
948
1181
  const d = mx - mn;
949
- const sat = mx === 0 ? 0 : Math.round((d / mx) * 100);
1182
+ const sat = mx === 0
1183
+ ? 0
1184
+ : Math.round((d / mx) * 100);
950
1185
  return sat;
951
1186
  }
952
1187
  return 0;
953
1188
  },
954
1189
  set: async (v) => {
955
- await this.setState({ saturation: Number(v) });
1190
+ await this.setState({
1191
+ saturation: Number(v),
1192
+ });
956
1193
  },
957
1194
  },
958
1195
  ColorTemperature: {
@@ -973,7 +1210,9 @@ export class LightDevice extends GenericDevice {
973
1210
  return 400;
974
1211
  },
975
1212
  set: async (v) => {
976
- await this.setState({ colorTemperature: Number(v) });
1213
+ await this.setState({
1214
+ colorTemperature: Number(v),
1215
+ });
977
1216
  },
978
1217
  },
979
1218
  },
@@ -1050,8 +1289,14 @@ export class LightDevice extends GenericDevice {
1050
1289
  type: 'OnOff',
1051
1290
  clusterId: MATTER_CLUSTER_IDS.OnOff,
1052
1291
  attributes: {
1053
- onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
1054
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
1292
+ onOff: {
1293
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); },
1294
+ write: async (v) => this.setState({ on: !!v }),
1295
+ },
1296
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
1297
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); },
1298
+ write: async (v) => this.setState({ on: !!v }),
1299
+ },
1055
1300
  },
1056
1301
  },
1057
1302
  {
@@ -1059,8 +1304,28 @@ export class LightDevice extends GenericDevice {
1059
1304
  type: 'LevelControl',
1060
1305
  clusterId: MATTER_CLUSTER_IDS.LevelControl,
1061
1306
  attributes: {
1062
- currentLevel: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
1063
- [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
1307
+ currentLevel: {
1308
+ read: async () => {
1309
+ const s = await this.getState();
1310
+ return typeof s.brightness === 'number'
1311
+ ? s.brightness
1312
+ : 100;
1313
+ },
1314
+ write: async (v) => this.setState({
1315
+ brightness: Number(v),
1316
+ }),
1317
+ },
1318
+ [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: {
1319
+ read: async () => {
1320
+ const s = await this.getState();
1321
+ return typeof s.brightness === 'number'
1322
+ ? s.brightness
1323
+ : 100;
1324
+ },
1325
+ write: async (v) => this.setState({
1326
+ brightness: Number(v),
1327
+ }),
1328
+ },
1064
1329
  },
1065
1330
  },
1066
1331
  {
@@ -1069,12 +1334,55 @@ export class LightDevice extends GenericDevice {
1069
1334
  clusterId: MATTER_CLUSTER_IDS.ColorControl,
1070
1335
  attributes: {
1071
1336
  // Required colorMode attribute for Matter conformance (0 = currentHueAndSaturation)
1072
- colorMode: { read: async () => 0 },
1073
- colorHue: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
1074
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
1075
- colorSaturation: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
1076
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
1077
- colorTemperature: { read: async () => {
1337
+ colorMode: {
1338
+ read: async () => 0,
1339
+ },
1340
+ colorHue: {
1341
+ read: async () => {
1342
+ const s = await this.getState();
1343
+ return typeof s.hue === 'number'
1344
+ ? s.hue
1345
+ : 0;
1346
+ },
1347
+ write: async (v) => this.setState({
1348
+ hue: Number(v),
1349
+ }),
1350
+ },
1351
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: {
1352
+ read: async () => {
1353
+ const s = await this.getState();
1354
+ return typeof s.hue === 'number'
1355
+ ? s.hue
1356
+ : 0;
1357
+ },
1358
+ write: async (v) => this.setState({
1359
+ hue: Number(v),
1360
+ }),
1361
+ },
1362
+ colorSaturation: {
1363
+ read: async () => {
1364
+ const s = await this.getState();
1365
+ return typeof s.saturation === 'number'
1366
+ ? s.saturation
1367
+ : 0;
1368
+ },
1369
+ write: async (v) => this.setState({
1370
+ saturation: Number(v),
1371
+ }),
1372
+ },
1373
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: {
1374
+ read: async () => {
1375
+ const s = await this.getState();
1376
+ return typeof s.saturation === 'number'
1377
+ ? s.saturation
1378
+ : 0;
1379
+ },
1380
+ write: async (v) => this.setState({
1381
+ saturation: Number(v),
1382
+ }),
1383
+ },
1384
+ colorTemperature: {
1385
+ read: async () => {
1078
1386
  const s = await this.getState();
1079
1387
  if (typeof s.colorTemperature === 'number') {
1080
1388
  return s.colorTemperature;
@@ -1083,8 +1391,13 @@ export class LightDevice extends GenericDevice {
1083
1391
  return Math.round(1000000 / s.kelvin);
1084
1392
  }
1085
1393
  return 400;
1086
- }, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
1087
- [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => {
1394
+ },
1395
+ write: async (v) => this.setState({
1396
+ colorTemperature: Number(v),
1397
+ }),
1398
+ },
1399
+ [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: {
1400
+ read: async () => {
1088
1401
  const s = await this.getState();
1089
1402
  if (typeof s.colorTemperature === 'number') {
1090
1403
  return s.colorTemperature;
@@ -1093,7 +1406,11 @@ export class LightDevice extends GenericDevice {
1093
1406
  return Math.round(1000000 / s.kelvin);
1094
1407
  }
1095
1408
  return 400;
1096
- }, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
1409
+ },
1410
+ write: async (v) => this.setState({
1411
+ colorTemperature: Number(v),
1412
+ }),
1413
+ },
1097
1414
  },
1098
1415
  },
1099
1416
  ],
@@ -1126,7 +1443,11 @@ export class MotionSensorDevice extends GenericDevice {
1126
1443
  }
1127
1444
  // Oscillation support
1128
1445
  if (typeof change.oscillate === 'boolean') {
1129
- const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
1446
+ const body = {
1447
+ command: 'setOscillation',
1448
+ parameter: change.oscillate ? 'on' : 'off',
1449
+ commandType: 'command',
1450
+ };
1130
1451
  try {
1131
1452
  return await this.client.setDeviceState(this.opts.id, body);
1132
1453
  }
@@ -1181,7 +1502,9 @@ export class ContactSensorDevice extends GenericDevice {
1181
1502
  ContactSensorState: {
1182
1503
  get: async () => {
1183
1504
  const s = await this.getState();
1184
- return s && s.open ? 1 : 0;
1505
+ return s && s.open
1506
+ ? 1
1507
+ : 0;
1185
1508
  },
1186
1509
  },
1187
1510
  },
@@ -1206,13 +1529,17 @@ export class LockDevice extends GenericDevice {
1206
1529
  LockCurrentState: {
1207
1530
  get: async () => {
1208
1531
  const s = await this.getState();
1209
- return s && s.locked ? 1 : 0;
1532
+ return s && s.locked
1533
+ ? 1
1534
+ : 0;
1210
1535
  },
1211
1536
  },
1212
1537
  LockTargetState: {
1213
1538
  get: async () => {
1214
1539
  const s = await this.getState();
1215
- return s && s.locked ? 1 : 0;
1540
+ return s && s.locked
1541
+ ? 1
1542
+ : 0;
1216
1543
  },
1217
1544
  set: async (v) => {
1218
1545
  await this.setState({ locked: !!v });
@@ -1239,7 +1566,11 @@ export class LockDevice extends GenericDevice {
1239
1566
  }
1240
1567
  if (action === 'removeUser' && (change.user || change.userId)) {
1241
1568
  const user = change.user ?? change.userId;
1242
- const body = { command: 'removeUserCode', parameter: String(user), commandType: 'command' };
1569
+ const body = {
1570
+ command: 'removeUserCode',
1571
+ parameter: String(user),
1572
+ commandType: 'command',
1573
+ };
1243
1574
  return await this.client.setDeviceState(this.opts.id, body);
1244
1575
  }
1245
1576
  if (action === 'listUsers') {
@@ -1266,7 +1597,11 @@ export class LockDevice extends GenericDevice {
1266
1597
  // Support setting lock PIN/passcode via `pin` or `passcode` (fallback)
1267
1598
  const pin = change?.pin ?? change?.passcode ?? change?.code;
1268
1599
  if (typeof pin === 'string' || typeof pin === 'number') {
1269
- const body = { command: 'setLockPin', parameter: String(pin), commandType: 'command' };
1600
+ const body = {
1601
+ command: 'setLockPin',
1602
+ parameter: String(pin),
1603
+ commandType: 'command',
1604
+ };
1270
1605
  try {
1271
1606
  return await this.client.setDeviceState(this.opts.id, body);
1272
1607
  }
@@ -1295,8 +1630,14 @@ export class LockDevice extends GenericDevice {
1295
1630
  type: 'DoorLock',
1296
1631
  clusterId: MATTER_CLUSTER_IDS.DoorLock,
1297
1632
  attributes: {
1298
- lockState: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
1299
- [MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
1633
+ lockState: {
1634
+ read: async () => { const s = await this.getState(); return !!(s && s.locked); },
1635
+ write: async (v) => this.setState({ locked: !!v }),
1636
+ },
1637
+ [MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: {
1638
+ read: async () => { const s = await this.getState(); return !!(s && s.locked); },
1639
+ write: async (v) => this.setState({ locked: !!v }),
1640
+ },
1300
1641
  },
1301
1642
  },
1302
1643
  {
@@ -1304,10 +1645,19 @@ export class LockDevice extends GenericDevice {
1304
1645
  type: 'DoorLockUserManagement',
1305
1646
  clusterId: 0x0301,
1306
1647
  attributes: {
1307
- addUser: { write: async (v) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }) },
1308
- removeUser: { write: async (v) => this.setState({ action: 'removeUser', user: v?.user }) },
1309
- listUsers: { read: async () => { const r = await this.setState({ action: 'listUsers' }); return r; }, write: undefined },
1310
- unlockWithPin: { write: async (v) => this.setState({ action: 'unlockWithPin', pin: v?.pin }) },
1648
+ addUser: {
1649
+ write: async (v) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }),
1650
+ },
1651
+ removeUser: {
1652
+ write: async (v) => this.setState({ action: 'removeUser', user: v?.user }),
1653
+ },
1654
+ listUsers: {
1655
+ read: async () => { const r = await this.setState({ action: 'listUsers' }); return r; },
1656
+ write: undefined,
1657
+ },
1658
+ unlockWithPin: {
1659
+ write: async (v) => this.setState({ action: 'unlockWithPin', pin: v?.pin }),
1660
+ },
1311
1661
  },
1312
1662
  },
1313
1663
  ],
@@ -1324,7 +1674,9 @@ export class HumidifierDevice extends GenericDevice {
1324
1674
  Active: {
1325
1675
  get: async () => {
1326
1676
  const s = await this.getState();
1327
- return s && s.on ? 1 : 0;
1677
+ return s && s.on
1678
+ ? 1
1679
+ : 0;
1328
1680
  },
1329
1681
  set: async (v) => {
1330
1682
  await this.setState({ on: v === 1 });
@@ -1333,7 +1685,9 @@ export class HumidifierDevice extends GenericDevice {
1333
1685
  CurrentHumidifierDehumidifierState: {
1334
1686
  get: async () => {
1335
1687
  const s = await this.getState();
1336
- return s && s.on ? 2 : 0; // 0 = Inactive, 2 = Humidifying
1688
+ return s && s.on
1689
+ ? 2
1690
+ : 0; // 0 = Inactive, 2 = Humidifying
1337
1691
  },
1338
1692
  },
1339
1693
  TargetHumidifierDehumidifierState: {
@@ -1345,16 +1699,22 @@ export class HumidifierDevice extends GenericDevice {
1345
1699
  CurrentRelativeHumidity: {
1346
1700
  get: async () => {
1347
1701
  const s = await this.getState();
1348
- return typeof s.humidity === 'number' ? s.humidity : 0;
1702
+ return typeof s.humidity === 'number'
1703
+ ? s.humidity
1704
+ : 0;
1349
1705
  },
1350
1706
  },
1351
1707
  RelativeHumidityHumidifierThreshold: {
1352
1708
  get: async () => {
1353
1709
  const s = await this.getState();
1354
- return typeof s.targetHumidity === 'number' ? s.targetHumidity : 50;
1710
+ return typeof s.targetHumidity === 'number'
1711
+ ? s.targetHumidity
1712
+ : 50;
1355
1713
  },
1356
1714
  set: async (v) => {
1357
- await this.setState({ humidity: Number(v) });
1715
+ await this.setState({
1716
+ humidity: Number(v),
1717
+ });
1358
1718
  },
1359
1719
  },
1360
1720
  },
@@ -1384,7 +1744,11 @@ export class HumidifierDevice extends GenericDevice {
1384
1744
  }
1385
1745
  }
1386
1746
  if (typeof change.dry === 'boolean') {
1387
- const body = { command: 'setDry', parameter: change.dry ? 'on' : 'off', commandType: 'command' };
1747
+ const body = {
1748
+ command: 'setDry',
1749
+ parameter: change.dry ? 'on' : 'off',
1750
+ commandType: 'command',
1751
+ };
1388
1752
  try {
1389
1753
  return await this.client.setDeviceState(this.opts.id, body);
1390
1754
  }
@@ -1415,16 +1779,38 @@ export class HumidifierMatterDevice extends HumidifierDevice {
1415
1779
  type: 'RelativeHumiditySensor',
1416
1780
  clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
1417
1781
  attributes: {
1418
- currentRelativeHumidity: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
1419
- [MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
1782
+ currentRelativeHumidity: {
1783
+ read: async () => {
1784
+ const s = await this.getState();
1785
+ return typeof s.humidity === 'number'
1786
+ ? s.humidity
1787
+ : 0;
1788
+ },
1789
+ write: undefined,
1790
+ },
1791
+ [MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: {
1792
+ read: async () => {
1793
+ const s = await this.getState();
1794
+ return typeof s.humidity === 'number'
1795
+ ? s.humidity
1796
+ : 0;
1797
+ },
1798
+ write: undefined,
1799
+ },
1420
1800
  },
1421
1801
  },
1422
1802
  {
1423
1803
  type: 'OnOff',
1424
1804
  clusterId: MATTER_CLUSTER_IDS.OnOff,
1425
1805
  attributes: {
1426
- onOff: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
1427
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
1806
+ onOff: {
1807
+ read: async () => { const s = await this.getState(); return !!s?.on; },
1808
+ write: async (v) => this.setState({ on: !!v }),
1809
+ },
1810
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
1811
+ read: async () => { const s = await this.getState(); return !!s?.on; },
1812
+ write: async (v) => this.setState({ on: !!v }),
1813
+ },
1428
1814
  },
1429
1815
  },
1430
1816
  ],
@@ -1441,7 +1827,9 @@ export class TemperatureSensorDevice extends GenericDevice {
1441
1827
  CurrentTemperature: {
1442
1828
  get: async () => {
1443
1829
  const s = await this.getState();
1444
- return typeof s.temperature === 'number' ? s.temperature : 0;
1830
+ return typeof s.temperature === 'number'
1831
+ ? s.temperature
1832
+ : 0;
1445
1833
  },
1446
1834
  },
1447
1835
  },
@@ -1474,7 +1862,9 @@ export class PlugDevice extends GenericDevice {
1474
1862
  OutletInUse: {
1475
1863
  get: async () => {
1476
1864
  const s = await this.getState();
1477
- return s && s.inUse ? 1 : 0;
1865
+ return s && s.inUse
1866
+ ? 1
1867
+ : 0;
1478
1868
  },
1479
1869
  },
1480
1870
  },
@@ -1506,7 +1896,9 @@ export class MeterDevice extends GenericDevice {
1506
1896
  /** The ppm at which HomeKit reports carbon dioxide as detected. */
1507
1897
  co2AbnormalThreshold() {
1508
1898
  const value = Number(this.cfg?.co2AbnormalThreshold);
1509
- return Number.isFinite(value) && value > 0 ? value : CO2_ABNORMAL_PPM_DEFAULT;
1899
+ return Number.isFinite(value) && value > 0
1900
+ ? value
1901
+ : CO2_ABNORMAL_PPM_DEFAULT;
1510
1902
  }
1511
1903
  createHAPAccessory(api) {
1512
1904
  const services = [
@@ -1516,7 +1908,9 @@ export class MeterDevice extends GenericDevice {
1516
1908
  CurrentTemperature: {
1517
1909
  get: async () => {
1518
1910
  const s = await this.getState();
1519
- return typeof s.temperature === 'number' ? s.temperature : 0;
1911
+ return typeof s.temperature === 'number'
1912
+ ? s.temperature
1913
+ : 0;
1520
1914
  },
1521
1915
  },
1522
1916
  },
@@ -1527,7 +1921,9 @@ export class MeterDevice extends GenericDevice {
1527
1921
  CurrentRelativeHumidity: {
1528
1922
  get: async () => {
1529
1923
  const s = await this.getState();
1530
- return typeof s.humidity === 'number' ? s.humidity : 0;
1924
+ return typeof s.humidity === 'number'
1925
+ ? s.humidity
1926
+ : 0;
1531
1927
  },
1532
1928
  },
1533
1929
  },
@@ -1536,7 +1932,9 @@ export class MeterDevice extends GenericDevice {
1536
1932
  if (this.reportsCO2()) {
1537
1933
  const co2 = async () => {
1538
1934
  const s = await this.getState();
1539
- return typeof s.co2 === 'number' ? s.co2 : 0;
1935
+ return typeof s.co2 === 'number'
1936
+ ? s.co2
1937
+ : 0;
1540
1938
  };
1541
1939
  services.push({
1542
1940
  type: 'CarbonDioxideSensor',
@@ -1545,7 +1943,9 @@ export class MeterDevice extends GenericDevice {
1545
1943
  get: co2,
1546
1944
  },
1547
1945
  CarbonDioxideDetected: {
1548
- get: async () => ((await co2()) >= this.co2AbnormalThreshold() ? 1 : 0),
1946
+ get: async () => ((await co2()) >= this.co2AbnormalThreshold()
1947
+ ? 1
1948
+ : 0),
1549
1949
  },
1550
1950
  },
1551
1951
  });
@@ -1567,7 +1967,9 @@ export class MeterDevice extends GenericDevice {
1567
1967
  get: battery,
1568
1968
  },
1569
1969
  StatusLowBattery: {
1570
- get: async () => ((await battery()) < 20 ? 1 : 0),
1970
+ get: async () => ((await battery()) < 20
1971
+ ? 1
1972
+ : 0),
1571
1973
  },
1572
1974
  ChargingState: {
1573
1975
  get: async () => 2,
@@ -1606,7 +2008,13 @@ export class WaterDetectorDevice extends GenericDevice {
1606
2008
  return status === 1;
1607
2009
  }
1608
2010
  if (typeof status === 'string') {
1609
- return ['1', 'leak', 'leaked', 'detected', 'water_leak_detected'].includes(status.toLowerCase());
2011
+ return [
2012
+ '1',
2013
+ 'leak',
2014
+ 'leaked',
2015
+ 'detected',
2016
+ 'water_leak_detected',
2017
+ ].includes(status.toLowerCase());
1610
2018
  }
1611
2019
  return undefined;
1612
2020
  }
@@ -1742,7 +2150,9 @@ export class WaterDetectorDevice extends GenericDevice {
1742
2150
  StatusLowBattery: {
1743
2151
  get: () => {
1744
2152
  const b = this.getBatteryFast(api);
1745
- return b < 20 ? 1 : 0;
2153
+ return b < 20
2154
+ ? 1
2155
+ : 0;
1746
2156
  },
1747
2157
  },
1748
2158
  ChargingState: {