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

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 (86) 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
  86. package/.github/npm-version-script-esm.js +0 -103
@@ -42,7 +42,9 @@ import { DeviceBase } from './deviceBase.js'
42
42
 
43
43
  function validateBLEResponseLength(buf: Buffer | Uint8Array | any[], expected: number, context = '', log: import('homebridge').Logger): boolean {
44
44
  if (!buf || typeof buf.length !== 'number' || buf.length !== expected) {
45
- log.warn(`[BLE] Invalid response length${context ? ` for ${context}` : ''}: expected ${expected}, got ${buf?.length}`)
45
+ log.warn(`[BLE] Invalid response length${context
46
+ ? ` for ${context}`
47
+ : ''}: expected ${expected}, got ${buf?.length}`)
46
48
  return false
47
49
  }
48
50
  return true
@@ -211,7 +213,10 @@ export class GenericDevice extends DeviceBase {
211
213
  // at its fallback for the whole window after one transient error.
212
214
  return { id: this.opts.id, type: this.opts.type, unreadable: true }
213
215
  }
214
- this.stateCache = { at: Date.now(), value }
216
+ this.stateCache = {
217
+ at: Date.now(),
218
+ value,
219
+ }
215
220
  return value
216
221
  })
217
222
  .finally(() => {
@@ -229,7 +234,12 @@ export class GenericDevice extends DeviceBase {
229
234
  if (raw && (raw instanceof Buffer || Array.isArray(raw) || raw instanceof Uint8Array)) {
230
235
  // Default to 12, override per device if needed
231
236
  if (!validateBLEResponseLength(raw, 12, this.opts.type, this.log)) {
232
- return { id: this.opts.id, type: this.opts.type, error: 'invalid_ble_response_length', raw }
237
+ return {
238
+ id: this.opts.id,
239
+ type: this.opts.type,
240
+ error: 'invalid_ble_response_length',
241
+ raw,
242
+ }
233
243
  }
234
244
  }
235
245
  // Normalize common response shapes
@@ -249,7 +259,9 @@ export class GenericDevice extends DeviceBase {
249
259
  return device
250
260
  }
251
261
  } catch (e: any) {
252
- this.log?.debug?.(`getState: could not read status for ${this.opts.id}:`, e instanceof Error ? e.message : e)
262
+ this.log?.debug?.(`getState: could not read status for ${this.opts.id}:`, e instanceof Error
263
+ ? e.message
264
+ : e)
253
265
  }
254
266
  } catch (e) {
255
267
  // ignore and fallback
@@ -368,8 +380,14 @@ export class GenericDevice extends DeviceBase {
368
380
  type: 'OnOff',
369
381
  clusterId: MATTER_CLUSTER_IDS.OnOff,
370
382
  attributes: {
371
- onOff: { read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on', write: async (v: any) => this.setState({ on: !!v }) },
372
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on', write: async (v: any) => this.setState({ on: !!v }) },
383
+ onOff: {
384
+ read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on',
385
+ write: async (v: any) => this.setState({ on: !!v }),
386
+ },
387
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
388
+ read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on',
389
+ write: async (v: any) => this.setState({ on: !!v }),
390
+ },
373
391
  },
374
392
  })
375
393
  }
@@ -380,8 +398,18 @@ export class GenericDevice extends DeviceBase {
380
398
  type: 'LevelControl',
381
399
  clusterId: MATTER_CLUSTER_IDS.LevelControl,
382
400
  attributes: {
383
- currentLevel: { read: async () => (await this.getState()).brightness ?? 100, write: async (v: any) => this.setState({ brightness: Number(v) }) },
384
- [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => (await this.getState()).brightness ?? 100, write: async (v: any) => this.setState({ brightness: Number(v) }) },
401
+ currentLevel: {
402
+ read: async () => (await this.getState()).brightness ?? 100,
403
+ write: async (v: any) => this.setState({
404
+ brightness: Number(v),
405
+ }),
406
+ },
407
+ [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: {
408
+ read: async () => (await this.getState()).brightness ?? 100,
409
+ write: async (v: any) => this.setState({
410
+ brightness: Number(v),
411
+ }),
412
+ },
385
413
  },
386
414
  })
387
415
  }
@@ -392,15 +420,51 @@ export class GenericDevice extends DeviceBase {
392
420
  type: 'ColorControl',
393
421
  clusterId: MATTER_CLUSTER_IDS.ColorControl,
394
422
  attributes: {
395
- colorMode: { read: async () => 0 },
396
- colorHue: { read: async () => (await this.getState()).hue ?? 0, write: async (v: any) => this.setState({ hue: Number(v) }) },
397
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => (await this.getState()).hue ?? 0, write: async (v: any) => this.setState({ hue: Number(v) }) },
398
- colorSaturation: { read: async () => (await this.getState()).saturation ?? 0, write: async (v: any) => this.setState({ saturation: Number(v) }) },
399
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => (await this.getState()).saturation ?? 0, write: async (v: any) => this.setState({ saturation: Number(v) }) },
423
+ colorMode: {
424
+ read: async () => 0,
425
+ },
426
+ colorHue: {
427
+ read: async () => (await this.getState()).hue ?? 0,
428
+ write: async (v: any) => this.setState({
429
+ hue: Number(v),
430
+ }),
431
+ },
432
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: {
433
+ read: async () => (await this.getState()).hue ?? 0,
434
+ write: async (v: any) => this.setState({
435
+ hue: Number(v),
436
+ }),
437
+ },
438
+ colorSaturation: {
439
+ read: async () => (await this.getState()).saturation ?? 0,
440
+ write: async (v: any) => this.setState({
441
+ saturation: Number(v),
442
+ }),
443
+ },
444
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: {
445
+ read: async () => (await this.getState()).saturation ?? 0,
446
+ write: async (v: any) => this.setState({
447
+ saturation: Number(v),
448
+ }),
449
+ },
400
450
  ...(typeof state.colorTemperature === 'number' || typeof state.kelvin === 'number'
401
451
  ? {
402
- colorTemperature: { read: async () => typeof (await this.getState()).colorTemperature === 'number' ? (await this.getState()).colorTemperature : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)), write: async (v: any) => this.setState({ colorTemperature: Number(v) }) },
403
- [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: any) => this.setState({ colorTemperature: Number(v) }) },
452
+ colorTemperature: {
453
+ read: async () => typeof (await this.getState()).colorTemperature === 'number'
454
+ ? (await this.getState()).colorTemperature
455
+ : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)),
456
+ write: async (v: any) => this.setState({
457
+ colorTemperature: Number(v),
458
+ }),
459
+ },
460
+ [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: {
461
+ read: async () => typeof (await this.getState()).colorTemperature === 'number'
462
+ ? (await this.getState()).colorTemperature
463
+ : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)),
464
+ write: async (v: any) => this.setState({
465
+ colorTemperature: Number(v),
466
+ }),
467
+ },
404
468
  }
405
469
  : {}),
406
470
  },
@@ -413,7 +477,9 @@ export class GenericDevice extends DeviceBase {
413
477
  type: 'TemperatureMeasurement',
414
478
  // No clusterId, not present in MATTER_CLUSTER_IDS
415
479
  attributes: {
416
- measuredValue: { read: async () => (await this.getState()).temperature ?? 0 },
480
+ measuredValue: {
481
+ read: async () => (await this.getState()).temperature ?? 0,
482
+ },
417
483
  },
418
484
  })
419
485
  }
@@ -424,7 +490,9 @@ export class GenericDevice extends DeviceBase {
424
490
  type: 'RelativeHumidityMeasurement',
425
491
  clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
426
492
  attributes: {
427
- measuredValue: { read: async () => (await this.getState()).humidity ?? 0 },
493
+ measuredValue: {
494
+ read: async () => (await this.getState()).humidity ?? 0,
495
+ },
428
496
  },
429
497
  })
430
498
  }
@@ -434,7 +502,9 @@ export class GenericDevice extends DeviceBase {
434
502
  clusters.push({
435
503
  type: 'AirQuality',
436
504
  attributes: {
437
- CO2: { read: async () => (await this.getState()).CO2 ?? 0 },
505
+ CO2: {
506
+ read: async () => (await this.getState()).CO2 ?? 0,
507
+ },
438
508
  },
439
509
  })
440
510
  }
@@ -445,7 +515,12 @@ export class GenericDevice extends DeviceBase {
445
515
  type: 'DoorLock',
446
516
  clusterId: MATTER_CLUSTER_IDS.DoorLock,
447
517
  attributes: {
448
- lockState: { read: async () => (await this.getState()).lockState ?? (await this.getState()).locked ? 1 : 0, write: async (v: any) => this.setState({ locked: !!v }) },
518
+ lockState: {
519
+ read: async () => (await this.getState()).lockState ?? (await this.getState()).locked
520
+ ? 1
521
+ : 0,
522
+ write: async (v: any) => this.setState({ locked: !!v }),
523
+ },
449
524
  },
450
525
  })
451
526
  }
@@ -456,7 +531,11 @@ export class GenericDevice extends DeviceBase {
456
531
  type: 'OccupancySensing',
457
532
  // No clusterId, not present in MATTER_CLUSTER_IDS
458
533
  attributes: {
459
- occupancy: { read: async () => (await this.getState()).moveDetected === true || (await this.getState()).motion === true ? 1 : 0 },
534
+ occupancy: {
535
+ read: async () => (await this.getState()).moveDetected === true || (await this.getState()).motion === true
536
+ ? 1
537
+ : 0,
538
+ },
460
539
  },
461
540
  })
462
541
  }
@@ -467,7 +546,11 @@ export class GenericDevice extends DeviceBase {
467
546
  type: 'BooleanState',
468
547
  // No clusterId, not present in MATTER_CLUSTER_IDS
469
548
  attributes: {
470
- stateValue: { read: async () => (await this.getState()).openState === 'open' || (await this.getState()).open === true ? 1 : 0 },
549
+ stateValue: {
550
+ read: async () => (await this.getState()).openState === 'open' || (await this.getState()).open === true
551
+ ? 1
552
+ : 0,
553
+ },
471
554
  },
472
555
  })
473
556
  }
@@ -477,7 +560,11 @@ export class GenericDevice extends DeviceBase {
477
560
  clusters.push({
478
561
  type: 'LeakSensor',
479
562
  attributes: {
480
- leakDetected: { read: async () => (await this.getState()).leak === true || (await this.getState()).status === 1 ? 1 : 0 },
563
+ leakDetected: {
564
+ read: async () => (await this.getState()).leak === true || (await this.getState()).status === 1
565
+ ? 1
566
+ : 0,
567
+ },
481
568
  },
482
569
  })
483
570
  }
@@ -488,9 +575,15 @@ export class GenericDevice extends DeviceBase {
488
575
  type: 'ElectricalMeasurement',
489
576
  // No clusterId, not present in MATTER_CLUSTER_IDS
490
577
  attributes: {
491
- voltage: { read: async () => (await this.getState()).voltage ?? 0 },
492
- power: { read: async () => (await this.getState()).power ?? 0 },
493
- electricCurrent: { read: async () => (await this.getState()).electricCurrent ?? 0 },
578
+ voltage: {
579
+ read: async () => (await this.getState()).voltage ?? 0,
580
+ },
581
+ power: {
582
+ read: async () => (await this.getState()).power ?? 0,
583
+ },
584
+ electricCurrent: {
585
+ read: async () => (await this.getState()).electricCurrent ?? 0,
586
+ },
494
587
  },
495
588
  })
496
589
  }
@@ -501,7 +594,12 @@ export class GenericDevice extends DeviceBase {
501
594
  type: 'FanControl',
502
595
  clusterId: MATTER_CLUSTER_IDS.FanControl,
503
596
  attributes: {
504
- speedCurrent: { read: async () => (await this.getState()).speed ?? (await this.getState()).fanSpeed ?? 0, write: async (v: any) => this.setState({ speed: Number(v) }) },
597
+ speedCurrent: {
598
+ read: async () => (await this.getState()).speed ?? (await this.getState()).fanSpeed ?? 0,
599
+ write: async (v: any) => this.setState({
600
+ speed: Number(v),
601
+ }),
602
+ },
505
603
  },
506
604
  })
507
605
  }
@@ -511,7 +609,9 @@ export class GenericDevice extends DeviceBase {
511
609
  clusters.push({
512
610
  type: 'RobotVacuumCleaner',
513
611
  attributes: {
514
- workingStatus: { read: async () => (await this.getState()).workingStatus ?? 'StandBy' },
612
+ workingStatus: {
613
+ read: async () => (await this.getState()).workingStatus ?? 'StandBy',
614
+ },
515
615
  },
516
616
  })
517
617
  }
@@ -553,56 +653,125 @@ export class BotDevice extends GenericDevice {
553
653
  if (pressMode && !on) {
554
654
  return
555
655
  }
556
- const command = pressMode ? 'press' : on ? 'turnOn' : 'turnOff'
656
+ const command = pressMode
657
+ ? 'press'
658
+ : on ? 'turnOn' : 'turnOff'
557
659
  const result = await this.setState({ command, parameter: 'default', commandType: 'command' })
558
660
  if (result !== true && result?.success !== true) {
559
661
  throw new Error(`SwitchBot Bot ${command} failed: ${result?.reason ?? 'unknown error'}`)
560
662
  }
561
663
  if (!pressMode) {
562
- this.lastCommand = { on, at: Date.now() }
664
+ this.lastCommand = {
665
+ on,
666
+ at: Date.now(),
667
+ }
563
668
  }
564
669
  }
565
670
 
566
671
  const control = (name: string, active: number | boolean, inactive: number | boolean, requestedOn: (value: any) => boolean) => ({
567
- get: async () => (await isOn()) ? active : inactive,
672
+ get: async () => (await isOn())
673
+ ? active
674
+ : inactive,
568
675
  set: async (value: any) => setOn(requestedOn(value)),
569
- ...(pressMode ? { refreshAfterSet: [name] } : {}),
676
+ ...(pressMode
677
+ ? {
678
+ refreshAfterSet: [name],
679
+ }
680
+ : {}),
570
681
  })
571
682
  const position = () => ({
572
- CurrentPosition: { get: async () => (await isOn()) ? 100 : 0 },
573
- PositionState: { get: async () => 2 },
683
+ CurrentPosition: {
684
+ get: async () => (await isOn())
685
+ ? 100
686
+ : 0,
687
+ },
688
+ PositionState: {
689
+ get: async () => 2,
690
+ },
574
691
  TargetPosition: control('TargetPosition', 100, 0, value => Number(value) > 0),
575
692
  })
576
693
  const active = (value: any) => Number(value) === 1
577
694
  const presentations: Record<string, { type: string, characteristics: Record<string, any> }> = {
578
- switch: { type: 'Switch', characteristics: { On: control('On', true, false, value => value === true) } },
579
- outlet: { type: 'Outlet', characteristics: { On: control('On', true, false, value => value === true) } },
580
- door: { type: 'Door', characteristics: position() },
581
- window: { type: 'Window', characteristics: position() },
582
- windowcovering: { type: 'WindowCovering', characteristics: position() },
583
- garagedoor: { type: 'GarageDoorOpener', characteristics: {
584
- CurrentDoorState: { get: async () => (await isOn()) ? 0 : 1 },
585
- TargetDoorState: control('TargetDoorState', 0, 1, value => Number(value) === 0),
586
- ObstructionDetected: { get: async () => false },
587
- } },
588
- lock: { type: 'LockMechanism', characteristics: {
589
- LockCurrentState: { get: async () => (await isOn()) ? 0 : 1 },
590
- LockTargetState: control('LockTargetState', 0, 1, value => Number(value) === 0),
591
- } },
592
- faucet: { type: 'Faucet', characteristics: { Active: control('Active', 1, 0, active) } },
593
- fan: { type: 'Fanv2', characteristics: { Active: control('Active', 1, 0, active) } },
594
- stateful: { type: 'StatefulProgrammableSwitch', characteristics: {
595
- ProgrammableSwitchEvent: {},
596
- ProgrammableSwitchOutputState: {
597
- ...control('ProgrammableSwitchOutputState', 1, 0, active),
598
- ...(pressMode ? { refreshAfterSet: ['ProgrammableSwitchOutputState'] } : {}),
599
- afterSet: (value: any, service: any, hap: any) => {
600
- if (!pressMode || active(value)) {
601
- service.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).sendEventNotification(0)
602
- }
695
+ switch: {
696
+ type: 'Switch',
697
+ characteristics: {
698
+ On: control('On', true, false, value => value === true),
699
+ },
700
+ },
701
+ outlet: {
702
+ type: 'Outlet',
703
+ characteristics: {
704
+ On: control('On', true, false, value => value === true),
705
+ },
706
+ },
707
+ door: {
708
+ type: 'Door',
709
+ characteristics: position(),
710
+ },
711
+ window: {
712
+ type: 'Window',
713
+ characteristics: position(),
714
+ },
715
+ windowcovering: {
716
+ type: 'WindowCovering',
717
+ characteristics: position(),
718
+ },
719
+ garagedoor: {
720
+ type: 'GarageDoorOpener',
721
+ characteristics: {
722
+ CurrentDoorState: {
723
+ get: async () => (await isOn())
724
+ ? 0
725
+ : 1,
726
+ },
727
+ TargetDoorState: control('TargetDoorState', 0, 1, value => Number(value) === 0),
728
+ ObstructionDetected: {
729
+ get: async () => false,
603
730
  },
604
731
  },
605
- } },
732
+ },
733
+ lock: {
734
+ type: 'LockMechanism',
735
+ characteristics: {
736
+ LockCurrentState: {
737
+ get: async () => (await isOn())
738
+ ? 0
739
+ : 1,
740
+ },
741
+ LockTargetState: control('LockTargetState', 0, 1, value => Number(value) === 0),
742
+ },
743
+ },
744
+ faucet: {
745
+ type: 'Faucet',
746
+ characteristics: {
747
+ Active: control('Active', 1, 0, active),
748
+ },
749
+ },
750
+ fan: {
751
+ type: 'Fanv2',
752
+ characteristics: {
753
+ Active: control('Active', 1, 0, active),
754
+ },
755
+ },
756
+ stateful: {
757
+ type: 'StatefulProgrammableSwitch',
758
+ characteristics: {
759
+ ProgrammableSwitchEvent: {},
760
+ ProgrammableSwitchOutputState: {
761
+ ...control('ProgrammableSwitchOutputState', 1, 0, active),
762
+ ...(pressMode
763
+ ? {
764
+ refreshAfterSet: ['ProgrammableSwitchOutputState'],
765
+ }
766
+ : {}),
767
+ afterSet: (value: any, service: any, hap: any) => {
768
+ if (!pressMode || active(value)) {
769
+ service.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).sendEventNotification(0)
770
+ }
771
+ },
772
+ },
773
+ },
774
+ },
606
775
  }
607
776
 
608
777
  return {
@@ -692,9 +861,15 @@ export class CurtainDevice extends GenericDevice {
692
861
  }
693
862
  const previousPosition = this.lastKnownPosition
694
863
  this.lastTargetPosition = position
695
- this.positionState = position > this.lastKnownPosition ? 1 : position < this.lastKnownPosition ? 0 : 2
864
+ this.positionState = position > this.lastKnownPosition
865
+ ? 1
866
+ : position < this.lastKnownPosition
867
+ ? 0
868
+ : 2
696
869
  try {
697
- const result = await this.setState({ position: this.toSwitchBotPosition(position) })
870
+ const result = await this.setState({
871
+ position: this.toSwitchBotPosition(position),
872
+ })
698
873
  if (result === false || result?.success === false) {
699
874
  throw new Error(result?.reason ?? 'Curtain position command failed')
700
875
  }
@@ -727,16 +902,22 @@ export class CurtainDevice extends GenericDevice {
727
902
  currentPositionLiftPercent100ths: {
728
903
  read: async () => {
729
904
  const s = await this.getState()
730
- return typeof s.position === 'number' ? Math.round(s.position * 100) : 0
905
+ return typeof s.position === 'number'
906
+ ? Math.round(s.position * 100)
907
+ : 0
731
908
  },
732
909
  write: undefined,
733
910
  },
734
911
  targetPositionLiftPercent100ths: {
735
912
  read: async () => {
736
913
  const s = await this.getState()
737
- return typeof s.position === 'number' ? Math.round(s.position * 100) : 0
914
+ return typeof s.position === 'number'
915
+ ? Math.round(s.position * 100)
916
+ : 0
738
917
  },
739
- write: async (v: any) => this.setState({ position: Math.round(Number(v) / 100) }),
918
+ write: async (v: any) => this.setState({
919
+ position: Math.round(Number(v) / 100),
920
+ }),
740
921
  },
741
922
  operationalStatus: {
742
923
  read: async () => state.operationalStatus ?? { global: 0, lift: 0, tilt: 0 },
@@ -764,16 +945,22 @@ export class CurtainDevice extends GenericDevice {
764
945
  attributes.currentPositionTiltPercent100ths = {
765
946
  read: async () => {
766
947
  const s = await this.getState()
767
- return typeof s.tilt === 'number' ? Math.round(s.tilt * 100) : 0
948
+ return typeof s.tilt === 'number'
949
+ ? Math.round(s.tilt * 100)
950
+ : 0
768
951
  },
769
952
  write: undefined,
770
953
  }
771
954
  attributes.targetPositionTiltPercent100ths = {
772
955
  read: async () => {
773
956
  const s = await this.getState()
774
- return typeof s.tilt === 'number' ? Math.round(s.tilt * 100) : 0
957
+ return typeof s.tilt === 'number'
958
+ ? Math.round(s.tilt * 100)
959
+ : 0
775
960
  },
776
- write: async (v: any) => this.setState({ tilt: Math.round(Number(v) / 100) }),
961
+ write: async (v: any) => this.setState({
962
+ tilt: Math.round(Number(v) / 100),
963
+ }),
777
964
  }
778
965
  }
779
966
  const windowCoveringCluster = {
@@ -815,10 +1002,14 @@ export class FanDevice extends GenericDevice {
815
1002
  RotationSpeed: {
816
1003
  get: async () => {
817
1004
  const s = await this.getState()
818
- return typeof s.speed === 'number' ? s.speed : 0
1005
+ return typeof s.speed === 'number'
1006
+ ? s.speed
1007
+ : 0
819
1008
  },
820
1009
  set: async (v: any) => {
821
- await this.setState({ speed: Number(v) })
1010
+ await this.setState({
1011
+ speed: Number(v),
1012
+ })
822
1013
  },
823
1014
  },
824
1015
  },
@@ -832,7 +1023,11 @@ export class FanDevice extends GenericDevice {
832
1023
 
833
1024
  // Oscillation support
834
1025
  if (typeof change.oscillate === 'boolean') {
835
- const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' }
1026
+ const body = {
1027
+ command: 'setOscillation',
1028
+ parameter: change.oscillate ? 'on' : 'off',
1029
+ commandType: 'command',
1030
+ }
836
1031
  try {
837
1032
  return await this.client.setDeviceState(this.opts.id, body)
838
1033
  } catch (err) {
@@ -878,9 +1073,15 @@ export class FanDevice extends GenericDevice {
878
1073
  type: 'OnOff',
879
1074
  clusterId: MATTER_CLUSTER_IDS.OnOff,
880
1075
  attributes: {
881
- onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')) }, write: async (v: any) => this.setState({ on: !!v }) },
1076
+ onOff: {
1077
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')) },
1078
+ write: async (v: any) => this.setState({ on: !!v }),
1079
+ },
882
1080
  // numeric attribute id for onOff
883
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')) }, write: async (v: any) => this.setState({ on: !!v }) },
1081
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
1082
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')) },
1083
+ write: async (v: any) => this.setState({ on: !!v }),
1084
+ },
884
1085
  },
885
1086
  },
886
1087
  {
@@ -888,10 +1089,34 @@ export class FanDevice extends GenericDevice {
888
1089
  type: 'FanControl',
889
1090
  clusterId: MATTER_CLUSTER_IDS.FanControl,
890
1091
  attributes: {
891
- rotationSpeed: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0 }, write: async (v: any) => this.setState({ speed: Number(v) }) },
892
- [MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0 }, write: async (v: any) => this.setState({ speed: Number(v) }) },
893
- oscillation: { read: async () => { const s = await this.getState(); return !!s?.oscillating }, write: async (v: any) => this.setState({ oscillate: !!v }) },
894
- swingMode: { read: async () => { const s = await this.getState(); return s?.swingMode ?? null }, write: async (v: any) => this.setState({ swingMode: v }) },
1092
+ rotationSpeed: {
1093
+ read: async () => {
1094
+ const s = await this.getState(); return typeof s.speed === 'number'
1095
+ ? s.speed
1096
+ : 0
1097
+ },
1098
+ write: async (v: any) => this.setState({
1099
+ speed: Number(v),
1100
+ }),
1101
+ },
1102
+ [MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: {
1103
+ read: async () => {
1104
+ const s = await this.getState(); return typeof s.speed === 'number'
1105
+ ? s.speed
1106
+ : 0
1107
+ },
1108
+ write: async (v: any) => this.setState({
1109
+ speed: Number(v),
1110
+ }),
1111
+ },
1112
+ oscillation: {
1113
+ read: async () => { const s = await this.getState(); return !!s?.oscillating },
1114
+ write: async (v: any) => this.setState({ oscillate: !!v }),
1115
+ },
1116
+ swingMode: {
1117
+ read: async () => { const s = await this.getState(); return s?.swingMode ?? null },
1118
+ write: async (v: any) => this.setState({ swingMode: v }),
1119
+ },
895
1120
  },
896
1121
  },
897
1122
  ],
@@ -918,10 +1143,14 @@ export class LightDevice extends GenericDevice {
918
1143
  props: { minValue: 0, maxValue: 100, minStep: 1 },
919
1144
  get: async () => {
920
1145
  const s = await this.getState()
921
- return typeof s.brightness === 'number' ? s.brightness : 100
1146
+ return typeof s.brightness === 'number'
1147
+ ? s.brightness
1148
+ : 100
922
1149
  },
923
1150
  set: async (v: any) => {
924
- await this.setState({ brightness: Number(v) })
1151
+ await this.setState({
1152
+ brightness: Number(v),
1153
+ })
925
1154
  },
926
1155
  },
927
1156
  Hue: {
@@ -958,7 +1187,9 @@ export class LightDevice extends GenericDevice {
958
1187
  return 0
959
1188
  },
960
1189
  set: async (v: any) => {
961
- await this.setState({ hue: Number(v) })
1190
+ await this.setState({
1191
+ hue: Number(v),
1192
+ })
962
1193
  },
963
1194
  },
964
1195
  Saturation: {
@@ -975,13 +1206,17 @@ export class LightDevice extends GenericDevice {
975
1206
  const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255
976
1207
  const mx = Math.max(r, g, b); const mn = Math.min(r, g, b)
977
1208
  const d = mx - mn
978
- const sat = mx === 0 ? 0 : Math.round((d / mx) * 100)
1209
+ const sat = mx === 0
1210
+ ? 0
1211
+ : Math.round((d / mx) * 100)
979
1212
  return sat
980
1213
  }
981
1214
  return 0
982
1215
  },
983
1216
  set: async (v: any) => {
984
- await this.setState({ saturation: Number(v) })
1217
+ await this.setState({
1218
+ saturation: Number(v),
1219
+ })
985
1220
  },
986
1221
  },
987
1222
  ColorTemperature: {
@@ -998,7 +1233,9 @@ export class LightDevice extends GenericDevice {
998
1233
  return 400
999
1234
  },
1000
1235
  set: async (v: any) => {
1001
- await this.setState({ colorTemperature: Number(v) })
1236
+ await this.setState({
1237
+ colorTemperature: Number(v),
1238
+ })
1002
1239
  },
1003
1240
  },
1004
1241
  },
@@ -1067,8 +1304,14 @@ export class LightDevice extends GenericDevice {
1067
1304
  type: 'OnOff',
1068
1305
  clusterId: MATTER_CLUSTER_IDS.OnOff,
1069
1306
  attributes: {
1070
- onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')) }, write: async (v: any) => this.setState({ on: !!v }) },
1071
- [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: any) => this.setState({ on: !!v }) },
1307
+ onOff: {
1308
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')) },
1309
+ write: async (v: any) => this.setState({ on: !!v }),
1310
+ },
1311
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
1312
+ read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')) },
1313
+ write: async (v: any) => this.setState({ on: !!v }),
1314
+ },
1072
1315
  },
1073
1316
  },
1074
1317
  {
@@ -1076,8 +1319,26 @@ export class LightDevice extends GenericDevice {
1076
1319
  type: 'LevelControl',
1077
1320
  clusterId: MATTER_CLUSTER_IDS.LevelControl,
1078
1321
  attributes: {
1079
- currentLevel: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100 }, write: async (v: any) => this.setState({ brightness: Number(v) }) },
1080
- [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100 }, write: async (v: any) => this.setState({ brightness: Number(v) }) },
1322
+ currentLevel: {
1323
+ read: async () => {
1324
+ const s = await this.getState(); return typeof s.brightness === 'number'
1325
+ ? s.brightness
1326
+ : 100
1327
+ },
1328
+ write: async (v: any) => this.setState({
1329
+ brightness: Number(v),
1330
+ }),
1331
+ },
1332
+ [MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: {
1333
+ read: async () => {
1334
+ const s = await this.getState(); return typeof s.brightness === 'number'
1335
+ ? s.brightness
1336
+ : 100
1337
+ },
1338
+ write: async (v: any) => this.setState({
1339
+ brightness: Number(v),
1340
+ }),
1341
+ },
1081
1342
  },
1082
1343
  },
1083
1344
  {
@@ -1086,17 +1347,65 @@ export class LightDevice extends GenericDevice {
1086
1347
  clusterId: MATTER_CLUSTER_IDS.ColorControl,
1087
1348
  attributes: {
1088
1349
  // Required colorMode attribute for Matter conformance (0 = currentHueAndSaturation)
1089
- colorMode: { read: async () => 0 },
1090
- colorHue: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0 }, write: async (v: any) => this.setState({ hue: Number(v) }) },
1091
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0 }, write: async (v: any) => this.setState({ hue: Number(v) }) },
1092
- colorSaturation: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0 }, write: async (v: any) => this.setState({ saturation: Number(v) }) },
1093
- [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0 }, write: async (v: any) => this.setState({ saturation: Number(v) }) },
1094
- colorTemperature: { read: async () => {
1095
- const s = await this.getState(); if (typeof s.colorTemperature === 'number') { return s.colorTemperature } if (typeof s.kelvin === 'number') { return Math.round(1000000 / s.kelvin) } return 400
1096
- }, write: async (v: any) => this.setState({ colorTemperature: Number(v) }) },
1097
- [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => {
1098
- const s = await this.getState(); if (typeof s.colorTemperature === 'number') { return s.colorTemperature } if (typeof s.kelvin === 'number') { return Math.round(1000000 / s.kelvin) } return 400
1099
- }, write: async (v: any) => this.setState({ colorTemperature: Number(v) }) },
1350
+ colorMode: {
1351
+ read: async () => 0,
1352
+ },
1353
+ colorHue: {
1354
+ read: async () => {
1355
+ const s = await this.getState(); return typeof s.hue === 'number'
1356
+ ? s.hue
1357
+ : 0
1358
+ },
1359
+ write: async (v: any) => this.setState({
1360
+ hue: Number(v),
1361
+ }),
1362
+ },
1363
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: {
1364
+ read: async () => {
1365
+ const s = await this.getState(); return typeof s.hue === 'number'
1366
+ ? s.hue
1367
+ : 0
1368
+ },
1369
+ write: async (v: any) => this.setState({
1370
+ hue: Number(v),
1371
+ }),
1372
+ },
1373
+ colorSaturation: {
1374
+ read: async () => {
1375
+ const s = await this.getState(); return typeof s.saturation === 'number'
1376
+ ? s.saturation
1377
+ : 0
1378
+ },
1379
+ write: async (v: any) => this.setState({
1380
+ saturation: Number(v),
1381
+ }),
1382
+ },
1383
+ [MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: {
1384
+ read: async () => {
1385
+ const s = await this.getState(); return typeof s.saturation === 'number'
1386
+ ? s.saturation
1387
+ : 0
1388
+ },
1389
+ write: async (v: any) => this.setState({
1390
+ saturation: Number(v),
1391
+ }),
1392
+ },
1393
+ colorTemperature: {
1394
+ read: async () => {
1395
+ const s = await this.getState(); if (typeof s.colorTemperature === 'number') { return s.colorTemperature } if (typeof s.kelvin === 'number') { return Math.round(1000000 / s.kelvin) } return 400
1396
+ },
1397
+ write: async (v: any) => this.setState({
1398
+ colorTemperature: Number(v),
1399
+ }),
1400
+ },
1401
+ [MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: {
1402
+ read: async () => {
1403
+ const s = await this.getState(); if (typeof s.colorTemperature === 'number') { return s.colorTemperature } if (typeof s.kelvin === 'number') { return Math.round(1000000 / s.kelvin) } return 400
1404
+ },
1405
+ write: async (v: any) => this.setState({
1406
+ colorTemperature: Number(v),
1407
+ }),
1408
+ },
1100
1409
  },
1101
1410
  },
1102
1411
  ],
@@ -1130,7 +1439,11 @@ export class MotionSensorDevice extends GenericDevice {
1130
1439
 
1131
1440
  // Oscillation support
1132
1441
  if (typeof change.oscillate === 'boolean') {
1133
- const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' }
1442
+ const body = {
1443
+ command: 'setOscillation',
1444
+ parameter: change.oscillate ? 'on' : 'off',
1445
+ commandType: 'command',
1446
+ }
1134
1447
  try {
1135
1448
  return await this.client.setDeviceState(this.opts.id, body)
1136
1449
  } catch (err) {
@@ -1175,7 +1488,9 @@ export class ContactSensorDevice extends GenericDevice {
1175
1488
  ContactSensorState: {
1176
1489
  get: async () => {
1177
1490
  const s = await this.getState()
1178
- return s && s.open ? 1 : 0
1491
+ return s && s.open
1492
+ ? 1
1493
+ : 0
1179
1494
  },
1180
1495
  },
1181
1496
  },
@@ -1202,13 +1517,17 @@ export class LockDevice extends GenericDevice {
1202
1517
  LockCurrentState: {
1203
1518
  get: async () => {
1204
1519
  const s = await this.getState()
1205
- return s && s.locked ? 1 : 0
1520
+ return s && s.locked
1521
+ ? 1
1522
+ : 0
1206
1523
  },
1207
1524
  },
1208
1525
  LockTargetState: {
1209
1526
  get: async () => {
1210
1527
  const s = await this.getState()
1211
- return s && s.locked ? 1 : 0
1528
+ return s && s.locked
1529
+ ? 1
1530
+ : 0
1212
1531
  },
1213
1532
  set: async (v: any) => {
1214
1533
  await this.setState({ locked: !!v })
@@ -1236,7 +1555,11 @@ export class LockDevice extends GenericDevice {
1236
1555
 
1237
1556
  if (action === 'removeUser' && (change.user || change.userId)) {
1238
1557
  const user = change.user ?? change.userId
1239
- const body = { command: 'removeUserCode', parameter: String(user), commandType: 'command' }
1558
+ const body = {
1559
+ command: 'removeUserCode',
1560
+ parameter: String(user),
1561
+ commandType: 'command',
1562
+ }
1240
1563
  return await this.client.setDeviceState(this.opts.id, body)
1241
1564
  }
1242
1565
 
@@ -1262,7 +1585,11 @@ export class LockDevice extends GenericDevice {
1262
1585
  // Support setting lock PIN/passcode via `pin` or `passcode` (fallback)
1263
1586
  const pin = change?.pin ?? change?.passcode ?? change?.code
1264
1587
  if (typeof pin === 'string' || typeof pin === 'number') {
1265
- const body = { command: 'setLockPin', parameter: String(pin), commandType: 'command' }
1588
+ const body = {
1589
+ command: 'setLockPin',
1590
+ parameter: String(pin),
1591
+ commandType: 'command',
1592
+ }
1266
1593
  try {
1267
1594
  return await this.client.setDeviceState(this.opts.id, body)
1268
1595
  } catch (err) {
@@ -1289,8 +1616,14 @@ export class LockDevice extends GenericDevice {
1289
1616
  type: 'DoorLock',
1290
1617
  clusterId: MATTER_CLUSTER_IDS.DoorLock,
1291
1618
  attributes: {
1292
- lockState: { read: async () => { const s = await this.getState(); return !!(s && s.locked) }, write: async (v: any) => this.setState({ locked: !!v }) },
1293
- [MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: { read: async () => { const s = await this.getState(); return !!(s && s.locked) }, write: async (v: any) => this.setState({ locked: !!v }) },
1619
+ lockState: {
1620
+ read: async () => { const s = await this.getState(); return !!(s && s.locked) },
1621
+ write: async (v: any) => this.setState({ locked: !!v }),
1622
+ },
1623
+ [MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: {
1624
+ read: async () => { const s = await this.getState(); return !!(s && s.locked) },
1625
+ write: async (v: any) => this.setState({ locked: !!v }),
1626
+ },
1294
1627
  },
1295
1628
  },
1296
1629
  {
@@ -1298,10 +1631,19 @@ export class LockDevice extends GenericDevice {
1298
1631
  type: 'DoorLockUserManagement',
1299
1632
  clusterId: 0x0301,
1300
1633
  attributes: {
1301
- addUser: { write: async (v: any) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }) },
1302
- removeUser: { write: async (v: any) => this.setState({ action: 'removeUser', user: v?.user }) },
1303
- listUsers: { read: async () => { const r = await this.setState({ action: 'listUsers' }); return r }, write: undefined },
1304
- unlockWithPin: { write: async (v: any) => this.setState({ action: 'unlockWithPin', pin: v?.pin }) },
1634
+ addUser: {
1635
+ write: async (v: any) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }),
1636
+ },
1637
+ removeUser: {
1638
+ write: async (v: any) => this.setState({ action: 'removeUser', user: v?.user }),
1639
+ },
1640
+ listUsers: {
1641
+ read: async () => { const r = await this.setState({ action: 'listUsers' }); return r },
1642
+ write: undefined,
1643
+ },
1644
+ unlockWithPin: {
1645
+ write: async (v: any) => this.setState({ action: 'unlockWithPin', pin: v?.pin }),
1646
+ },
1305
1647
  },
1306
1648
  },
1307
1649
  ],
@@ -1319,7 +1661,9 @@ export class HumidifierDevice extends GenericDevice {
1319
1661
  Active: {
1320
1662
  get: async () => {
1321
1663
  const s = await this.getState()
1322
- return s && s.on ? 1 : 0
1664
+ return s && s.on
1665
+ ? 1
1666
+ : 0
1323
1667
  },
1324
1668
  set: async (v: any) => {
1325
1669
  await this.setState({ on: v === 1 })
@@ -1328,7 +1672,9 @@ export class HumidifierDevice extends GenericDevice {
1328
1672
  CurrentHumidifierDehumidifierState: {
1329
1673
  get: async () => {
1330
1674
  const s = await this.getState()
1331
- return s && s.on ? 2 : 0 // 0 = Inactive, 2 = Humidifying
1675
+ return s && s.on
1676
+ ? 2
1677
+ : 0 // 0 = Inactive, 2 = Humidifying
1332
1678
  },
1333
1679
  },
1334
1680
  TargetHumidifierDehumidifierState: {
@@ -1340,16 +1686,22 @@ export class HumidifierDevice extends GenericDevice {
1340
1686
  CurrentRelativeHumidity: {
1341
1687
  get: async () => {
1342
1688
  const s = await this.getState()
1343
- return typeof s.humidity === 'number' ? s.humidity : 0
1689
+ return typeof s.humidity === 'number'
1690
+ ? s.humidity
1691
+ : 0
1344
1692
  },
1345
1693
  },
1346
1694
  RelativeHumidityHumidifierThreshold: {
1347
1695
  get: async () => {
1348
1696
  const s = await this.getState()
1349
- return typeof s.targetHumidity === 'number' ? s.targetHumidity : 50
1697
+ return typeof s.targetHumidity === 'number'
1698
+ ? s.targetHumidity
1699
+ : 50
1350
1700
  },
1351
1701
  set: async (v: any) => {
1352
- await this.setState({ humidity: Number(v) })
1702
+ await this.setState({
1703
+ humidity: Number(v),
1704
+ })
1353
1705
  },
1354
1706
  },
1355
1707
  },
@@ -1376,7 +1728,11 @@ export class HumidifierDevice extends GenericDevice {
1376
1728
  }
1377
1729
 
1378
1730
  if (typeof change.dry === 'boolean') {
1379
- const body = { command: 'setDry', parameter: change.dry ? 'on' : 'off', commandType: 'command' }
1731
+ const body = {
1732
+ command: 'setDry',
1733
+ parameter: change.dry ? 'on' : 'off',
1734
+ commandType: 'command',
1735
+ }
1380
1736
  try {
1381
1737
  return await this.client.setDeviceState(this.opts.id, body)
1382
1738
  } catch (err) {
@@ -1405,16 +1761,36 @@ export class HumidifierMatterDevice extends HumidifierDevice {
1405
1761
  type: 'RelativeHumiditySensor',
1406
1762
  clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
1407
1763
  attributes: {
1408
- currentRelativeHumidity: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0 }, write: undefined },
1409
- [MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0 }, write: undefined },
1764
+ currentRelativeHumidity: {
1765
+ read: async () => {
1766
+ const s = await this.getState(); return typeof s.humidity === 'number'
1767
+ ? s.humidity
1768
+ : 0
1769
+ },
1770
+ write: undefined,
1771
+ },
1772
+ [MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: {
1773
+ read: async () => {
1774
+ const s = await this.getState(); return typeof s.humidity === 'number'
1775
+ ? s.humidity
1776
+ : 0
1777
+ },
1778
+ write: undefined,
1779
+ },
1410
1780
  },
1411
1781
  },
1412
1782
  {
1413
1783
  type: 'OnOff',
1414
1784
  clusterId: MATTER_CLUSTER_IDS.OnOff,
1415
1785
  attributes: {
1416
- onOff: { read: async () => { const s = await this.getState(); return !!s?.on }, write: async (v: any) => this.setState({ on: !!v }) },
1417
- [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!s?.on }, write: async (v: any) => this.setState({ on: !!v }) },
1786
+ onOff: {
1787
+ read: async () => { const s = await this.getState(); return !!s?.on },
1788
+ write: async (v: any) => this.setState({ on: !!v }),
1789
+ },
1790
+ [MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: {
1791
+ read: async () => { const s = await this.getState(); return !!s?.on },
1792
+ write: async (v: any) => this.setState({ on: !!v }),
1793
+ },
1418
1794
  },
1419
1795
  },
1420
1796
  ],
@@ -1432,7 +1808,9 @@ export class TemperatureSensorDevice extends GenericDevice {
1432
1808
  CurrentTemperature: {
1433
1809
  get: async () => {
1434
1810
  const s = await this.getState()
1435
- return typeof s.temperature === 'number' ? s.temperature : 0
1811
+ return typeof s.temperature === 'number'
1812
+ ? s.temperature
1813
+ : 0
1436
1814
  },
1437
1815
  },
1438
1816
  },
@@ -1464,7 +1842,9 @@ export class PlugDevice extends GenericDevice {
1464
1842
  OutletInUse: {
1465
1843
  get: async () => {
1466
1844
  const s = await this.getState()
1467
- return s && s.inUse ? 1 : 0
1845
+ return s && s.inUse
1846
+ ? 1
1847
+ : 0
1468
1848
  },
1469
1849
  },
1470
1850
  },
@@ -1497,7 +1877,9 @@ export class MeterDevice extends GenericDevice {
1497
1877
  /** The ppm at which HomeKit reports carbon dioxide as detected. */
1498
1878
  protected co2AbnormalThreshold(): number {
1499
1879
  const value = Number((this.cfg as any)?.co2AbnormalThreshold)
1500
- return Number.isFinite(value) && value > 0 ? value : CO2_ABNORMAL_PPM_DEFAULT
1880
+ return Number.isFinite(value) && value > 0
1881
+ ? value
1882
+ : CO2_ABNORMAL_PPM_DEFAULT
1501
1883
  }
1502
1884
 
1503
1885
  createHAPAccessory(api: any) {
@@ -1508,7 +1890,9 @@ export class MeterDevice extends GenericDevice {
1508
1890
  CurrentTemperature: {
1509
1891
  get: async () => {
1510
1892
  const s = await this.getState()
1511
- return typeof s.temperature === 'number' ? s.temperature : 0
1893
+ return typeof s.temperature === 'number'
1894
+ ? s.temperature
1895
+ : 0
1512
1896
  },
1513
1897
  },
1514
1898
  },
@@ -1519,7 +1903,9 @@ export class MeterDevice extends GenericDevice {
1519
1903
  CurrentRelativeHumidity: {
1520
1904
  get: async () => {
1521
1905
  const s = await this.getState()
1522
- return typeof s.humidity === 'number' ? s.humidity : 0
1906
+ return typeof s.humidity === 'number'
1907
+ ? s.humidity
1908
+ : 0
1523
1909
  },
1524
1910
  },
1525
1911
  },
@@ -1529,7 +1915,9 @@ export class MeterDevice extends GenericDevice {
1529
1915
  if (this.reportsCO2()) {
1530
1916
  const co2 = async (): Promise<number> => {
1531
1917
  const s = await this.getState()
1532
- return typeof s.co2 === 'number' ? s.co2 : 0
1918
+ return typeof s.co2 === 'number'
1919
+ ? s.co2
1920
+ : 0
1533
1921
  }
1534
1922
  services.push({
1535
1923
  type: 'CarbonDioxideSensor',
@@ -1538,7 +1926,9 @@ export class MeterDevice extends GenericDevice {
1538
1926
  get: co2,
1539
1927
  },
1540
1928
  CarbonDioxideDetected: {
1541
- get: async () => ((await co2()) >= this.co2AbnormalThreshold() ? 1 : 0),
1929
+ get: async () => ((await co2()) >= this.co2AbnormalThreshold()
1930
+ ? 1
1931
+ : 0),
1542
1932
  },
1543
1933
  },
1544
1934
  })
@@ -1561,7 +1951,9 @@ export class MeterDevice extends GenericDevice {
1561
1951
  get: battery,
1562
1952
  },
1563
1953
  StatusLowBattery: {
1564
- get: async () => ((await battery()) < 20 ? 1 : 0),
1954
+ get: async () => ((await battery()) < 20
1955
+ ? 1
1956
+ : 0),
1565
1957
  },
1566
1958
  ChargingState: {
1567
1959
  get: async () => 2,
@@ -1605,7 +1997,13 @@ export class WaterDetectorDevice extends GenericDevice {
1605
1997
  return status === 1
1606
1998
  }
1607
1999
  if (typeof status === 'string') {
1608
- return ['1', 'leak', 'leaked', 'detected', 'water_leak_detected'].includes(status.toLowerCase())
2000
+ return [
2001
+ '1',
2002
+ 'leak',
2003
+ 'leaked',
2004
+ 'detected',
2005
+ 'water_leak_detected',
2006
+ ].includes(status.toLowerCase())
1609
2007
  }
1610
2008
  return undefined
1611
2009
  }
@@ -1749,7 +2147,9 @@ export class WaterDetectorDevice extends GenericDevice {
1749
2147
  StatusLowBattery: {
1750
2148
  get: () => {
1751
2149
  const b = this.getBatteryFast(api)
1752
- return b < 20 ? 1 : 0
2150
+ return b < 20
2151
+ ? 1
2152
+ : 0
1753
2153
  },
1754
2154
  },
1755
2155
  ChargingState: {