@switchbot/homebridge-switchbot 5.0.0-beta.70 → 5.0.0-beta.72
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.
- package/.github/ISSUE_TEMPLATE/e2e-verification.md +36 -0
- package/.github/workflows/ci.yml +61 -0
- package/.github/workflows/manual-e2e.yml +103 -0
- package/CHANGELOG.md +20 -0
- package/E2E-VERIFICATION.md +121 -0
- package/MIGRATION.md +44 -0
- package/README.md +11 -0
- package/config.schema.json +99 -1940
- package/dist/deviceFactory.d.ts +13 -0
- package/dist/deviceFactory.d.ts.map +1 -0
- package/dist/deviceFactory.js +81 -0
- package/dist/deviceFactory.js.map +1 -0
- package/dist/devices/deviceBase.d.ts +50 -0
- package/dist/devices/deviceBase.d.ts.map +1 -0
- package/dist/devices/deviceBase.js +119 -0
- package/dist/devices/deviceBase.js.map +1 -0
- package/dist/devices/genericDevice.d.ts +283 -0
- package/dist/devices/genericDevice.d.ts.map +1 -0
- package/dist/devices/genericDevice.js +1035 -0
- package/dist/devices/genericDevice.js.map +1 -0
- package/dist/homebridge-ui/public/index.html +72 -440
- package/dist/homebridge-ui/server.d.ts +3 -1
- package/dist/homebridge-ui/server.d.ts.map +1 -1
- package/dist/homebridge-ui/server.js +47 -10
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +27 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +404 -0
- package/dist/platform.js.map +1 -0
- package/dist/settings.d.ts +10 -317
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +5 -30
- package/dist/settings.js.map +1 -1
- package/dist/switchbotClient.d.ts +32 -0
- package/dist/switchbotClient.d.ts.map +1 -0
- package/dist/switchbotClient.js +259 -0
- package/dist/switchbotClient.js.map +1 -0
- package/dist/utils.d.ts +36 -248
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -1367
- package/dist/utils.js.map +1 -1
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/style.css +3 -3
- package/docs/index.html +50 -15
- package/docs/variables/default.html +1 -1
- package/package.json +19 -18
- package/scripts/e2e/README.md +25 -0
- package/scripts/e2e/curtain-e2e.sh +70 -0
- package/scripts/e2e/fan-e2e.sh +75 -0
- package/scripts/e2e/light-advanced-e2e.sh +97 -0
- package/scripts/e2e/light-e2e.sh +75 -0
- package/scripts/e2e/list-accessories.sh +19 -0
- package/scripts/e2e/lock-e2e.sh +65 -0
- package/scripts/generate-matter-maps.js +60 -0
- package/scripts/run-e2e-local.sh +14 -0
- package/src/deviceFactory.ts +122 -0
- package/src/devices/deviceBase.ts +141 -0
- package/src/devices/genericDevice.ts +965 -0
- package/src/homebridge-ui/public/index.html +72 -440
- package/src/homebridge-ui/server.ts +52 -10
- package/src/index.ts +1 -3
- package/src/platform.ts +395 -0
- package/src/settings.ts +12 -352
- package/src/switchbotClient.ts +266 -0
- package/src/utils.ts +47 -1456
- package/test/accessory-restore.spec.ts +73 -0
- package/test/device-mapping.spec.ts +37 -0
- package/test/deviceFactory.spec.ts +18 -0
- package/test/e2e/run-e2e.spec.ts +50 -0
- package/test/fan-swing.spec.ts +29 -0
- package/test/helpers/matter-harness.ts +53 -0
- package/test/lock-users.spec.ts +44 -0
- package/test/matter-childbridge.spec.ts +55 -0
- package/test/matter-descriptors.spec.ts +97 -0
- package/test/matter-device-state.spec.ts +101 -0
- package/test/matter-integration.spec.ts +70 -0
- package/test/platform.integration.spec.ts +55 -0
- package/test/switchbot-client-debounce.spec.ts +131 -0
- package/test/switchbot-client-openapi.spec.ts +56 -0
- package/test/switchbotClient.spec.ts +10 -0
- package/test/utils.spec.ts +20 -0
- package/vitest.config.ts +7 -0
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -15847
- package/coverage/coverage-final.json +0 -42
- package/coverage/docs/assets/dmt/dmt-component-data.js.html +0 -85
- package/coverage/docs/assets/dmt/dmt-components.js.html +0 -286
- package/coverage/docs/assets/dmt/index.html +0 -131
- package/coverage/docs/assets/hierarchy.js.html +0 -85
- package/coverage/docs/assets/icons.js.html +0 -136
- package/coverage/docs/assets/index.html +0 -146
- package/coverage/docs/assets/main.js.html +0 -265
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -191
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/device/blindtilt.ts.html +0 -3238
- package/coverage/src/device/bot.ts.html +0 -2803
- package/coverage/src/device/ceilinglight.ts.html +0 -2338
- package/coverage/src/device/colorbulb.ts.html +0 -2824
- package/coverage/src/device/contact.ts.html +0 -1465
- package/coverage/src/device/curtain.ts.html +0 -2869
- package/coverage/src/device/device.ts.html +0 -2500
- package/coverage/src/device/fan.ts.html +0 -2242
- package/coverage/src/device/hub.ts.html +0 -1408
- package/coverage/src/device/humidifier.ts.html +0 -2116
- package/coverage/src/device/index.html +0 -416
- package/coverage/src/device/iosensor.ts.html +0 -1375
- package/coverage/src/device/lightstrip.ts.html +0 -2617
- package/coverage/src/device/lock.ts.html +0 -1963
- package/coverage/src/device/meter.ts.html +0 -1372
- package/coverage/src/device/meterplus.ts.html +0 -1384
- package/coverage/src/device/meterpro.ts.html +0 -1618
- package/coverage/src/device/motion.ts.html +0 -1264
- package/coverage/src/device/plug.ts.html +0 -1372
- package/coverage/src/device/relayswitch.ts.html +0 -2284
- package/coverage/src/device/robotvacuumcleaner.ts.html +0 -1810
- package/coverage/src/device/waterdetector.ts.html +0 -1294
- package/coverage/src/homebridge-ui/index.html +0 -116
- package/coverage/src/homebridge-ui/server.ts.html +0 -229
- package/coverage/src/index.html +0 -161
- package/coverage/src/index.ts.html +0 -124
- package/coverage/src/irdevice/airconditioner.ts.html +0 -1687
- package/coverage/src/irdevice/airpurifier.ts.html +0 -844
- package/coverage/src/irdevice/camera.ts.html +0 -475
- package/coverage/src/irdevice/fan.ts.html +0 -766
- package/coverage/src/irdevice/index.html +0 -251
- package/coverage/src/irdevice/irdevice.ts.html +0 -1117
- package/coverage/src/irdevice/light.ts.html +0 -826
- package/coverage/src/irdevice/other.ts.html +0 -2458
- package/coverage/src/irdevice/tv.ts.html +0 -1222
- package/coverage/src/irdevice/vacuumcleaner.ts.html +0 -466
- package/coverage/src/irdevice/waterheater.ts.html +0 -469
- package/coverage/src/platform.ts.html +0 -8776
- package/coverage/src/settings.ts.html +0 -934
- package/coverage/src/utils.ts.html +0 -2092
- package/dist/devices-hap/airpurifier.d.ts +0 -54
- package/dist/devices-hap/airpurifier.d.ts.map +0 -1
- package/dist/devices-hap/airpurifier.js +0 -533
- package/dist/devices-hap/airpurifier.js.map +0 -1
- package/dist/devices-hap/blindtilt.d.ts +0 -90
- package/dist/devices-hap/blindtilt.d.ts.map +0 -1
- package/dist/devices-hap/blindtilt.js +0 -974
- package/dist/devices-hap/blindtilt.js.map +0 -1
- package/dist/devices-hap/bot.d.ts +0 -102
- package/dist/devices-hap/bot.d.ts.map +0 -1
- package/dist/devices-hap/bot.js +0 -822
- package/dist/devices-hap/bot.js.map +0 -1
- package/dist/devices-hap/ceilinglight.d.ts +0 -85
- package/dist/devices-hap/ceilinglight.d.ts.map +0 -1
- package/dist/devices-hap/ceilinglight.js +0 -707
- package/dist/devices-hap/ceilinglight.js.map +0 -1
- package/dist/devices-hap/colorbulb.d.ts +0 -88
- package/dist/devices-hap/colorbulb.d.ts.map +0 -1
- package/dist/devices-hap/colorbulb.js +0 -921
- package/dist/devices-hap/colorbulb.js.map +0 -1
- package/dist/devices-hap/contact.d.ts +0 -44
- package/dist/devices-hap/contact.d.ts.map +0 -1
- package/dist/devices-hap/contact.js +0 -409
- package/dist/devices-hap/contact.js.map +0 -1
- package/dist/devices-hap/curtain.d.ts +0 -73
- package/dist/devices-hap/curtain.d.ts.map +0 -1
- package/dist/devices-hap/curtain.js +0 -869
- package/dist/devices-hap/curtain.js.map +0 -1
- package/dist/devices-hap/device.d.ts +0 -108
- package/dist/devices-hap/device.d.ts.map +0 -1
- package/dist/devices-hap/device.js +0 -821
- package/dist/devices-hap/device.js.map +0 -1
- package/dist/devices-hap/fan.d.ts +0 -69
- package/dist/devices-hap/fan.d.ts.map +0 -1
- package/dist/devices-hap/fan.js +0 -655
- package/dist/devices-hap/fan.js.map +0 -1
- package/dist/devices-hap/hub.d.ts +0 -37
- package/dist/devices-hap/hub.d.ts.map +0 -1
- package/dist/devices-hap/hub.js +0 -393
- package/dist/devices-hap/hub.js.map +0 -1
- package/dist/devices-hap/humidifier.d.ts +0 -73
- package/dist/devices-hap/humidifier.d.ts.map +0 -1
- package/dist/devices-hap/humidifier.js +0 -716
- package/dist/devices-hap/humidifier.js.map +0 -1
- package/dist/devices-hap/iosensor.d.ts +0 -42
- package/dist/devices-hap/iosensor.d.ts.map +0 -1
- package/dist/devices-hap/iosensor.js +0 -397
- package/dist/devices-hap/iosensor.js.map +0 -1
- package/dist/devices-hap/lightstrip.d.ts +0 -79
- package/dist/devices-hap/lightstrip.d.ts.map +0 -1
- package/dist/devices-hap/lightstrip.js +0 -827
- package/dist/devices-hap/lightstrip.js.map +0 -1
- package/dist/devices-hap/lock.d.ts +0 -53
- package/dist/devices-hap/lock.d.ts.map +0 -1
- package/dist/devices-hap/lock.js +0 -569
- package/dist/devices-hap/lock.js.map +0 -1
- package/dist/devices-hap/meter.d.ts +0 -37
- package/dist/devices-hap/meter.d.ts.map +0 -1
- package/dist/devices-hap/meter.js +0 -380
- package/dist/devices-hap/meter.js.map +0 -1
- package/dist/devices-hap/meterplus.d.ts +0 -42
- package/dist/devices-hap/meterplus.d.ts.map +0 -1
- package/dist/devices-hap/meterplus.js +0 -385
- package/dist/devices-hap/meterplus.js.map +0 -1
- package/dist/devices-hap/meterpro.d.ts +0 -43
- package/dist/devices-hap/meterpro.d.ts.map +0 -1
- package/dist/devices-hap/meterpro.js +0 -469
- package/dist/devices-hap/meterpro.js.map +0 -1
- package/dist/devices-hap/motion.d.ts +0 -42
- package/dist/devices-hap/motion.d.ts.map +0 -1
- package/dist/devices-hap/motion.js +0 -345
- package/dist/devices-hap/motion.js.map +0 -1
- package/dist/devices-hap/plug.d.ts +0 -49
- package/dist/devices-hap/plug.d.ts.map +0 -1
- package/dist/devices-hap/plug.js +0 -400
- package/dist/devices-hap/plug.js.map +0 -1
- package/dist/devices-hap/relayswitch.d.ts +0 -96
- package/dist/devices-hap/relayswitch.d.ts.map +0 -1
- package/dist/devices-hap/relayswitch.js +0 -642
- package/dist/devices-hap/relayswitch.js.map +0 -1
- package/dist/devices-hap/robotvacuumcleaner.d.ts +0 -54
- package/dist/devices-hap/robotvacuumcleaner.d.ts.map +0 -1
- package/dist/devices-hap/robotvacuumcleaner.js +0 -530
- package/dist/devices-hap/robotvacuumcleaner.js.map +0 -1
- package/dist/devices-hap/waterdetector.d.ts +0 -41
- package/dist/devices-hap/waterdetector.d.ts.map +0 -1
- package/dist/devices-hap/waterdetector.js +0 -356
- package/dist/devices-hap/waterdetector.js.map +0 -1
- package/dist/devices-matter/BaseMatterAccessory.d.ts +0 -90
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
- package/dist/devices-matter/BaseMatterAccessory.js +0 -264
- package/dist/devices-matter/BaseMatterAccessory.js.map +0 -1
- package/dist/devices-matter/ColorLightAccessory.d.ts +0 -20
- package/dist/devices-matter/ColorLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ColorLightAccessory.js +0 -95
- package/dist/devices-matter/ColorLightAccessory.js.map +0 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +0 -18
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.js +0 -76
- package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +0 -1
- package/dist/devices-matter/ContactSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/ContactSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ContactSensorAccessory.js +0 -34
- package/dist/devices-matter/ContactSensorAccessory.js.map +0 -1
- package/dist/devices-matter/DimmableLightAccessory.d.ts +0 -58
- package/dist/devices-matter/DimmableLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/DimmableLightAccessory.js +0 -167
- package/dist/devices-matter/DimmableLightAccessory.js.map +0 -1
- package/dist/devices-matter/DoorLockAccessory.d.ts +0 -14
- package/dist/devices-matter/DoorLockAccessory.d.ts.map +0 -1
- package/dist/devices-matter/DoorLockAccessory.js +0 -50
- package/dist/devices-matter/DoorLockAccessory.js.map +0 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +0 -21
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.js +0 -106
- package/dist/devices-matter/ExtendedColorLightAccessory.js.map +0 -1
- package/dist/devices-matter/FanAccessory.d.ts +0 -16
- package/dist/devices-matter/FanAccessory.d.ts.map +0 -1
- package/dist/devices-matter/FanAccessory.js +0 -81
- package/dist/devices-matter/FanAccessory.js.map +0 -1
- package/dist/devices-matter/HumiditySensorAccessory.d.ts +0 -12
- package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/HumiditySensorAccessory.js +0 -34
- package/dist/devices-matter/HumiditySensorAccessory.js.map +0 -1
- package/dist/devices-matter/LeakSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/LeakSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/LeakSensorAccessory.js +0 -33
- package/dist/devices-matter/LeakSensorAccessory.js.map +0 -1
- package/dist/devices-matter/LightSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/LightSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/LightSensorAccessory.js +0 -34
- package/dist/devices-matter/LightSensorAccessory.js.map +0 -1
- package/dist/devices-matter/OccupancySensorAccessory.d.ts +0 -12
- package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OccupancySensorAccessory.js +0 -39
- package/dist/devices-matter/OccupancySensorAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffLightAccessory.d.ts +0 -38
- package/dist/devices-matter/OnOffLightAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffLightAccessory.js +0 -110
- package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -14
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +0 -43
- package/dist/devices-matter/OnOffOutletAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffSwitchAccessory.d.ts +0 -14
- package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffSwitchAccessory.js +0 -42
- package/dist/devices-matter/OnOffSwitchAccessory.js.map +0 -1
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts +0 -61
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
- package/dist/devices-matter/RoboticVacuumAccessory.js +0 -544
- package/dist/devices-matter/RoboticVacuumAccessory.js.map +0 -1
- package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts +0 -11
- package/dist/devices-matter/SmokeCOAlarmAccessory.d.ts.map +0 -1
- package/dist/devices-matter/SmokeCOAlarmAccessory.js +0 -49
- package/dist/devices-matter/SmokeCOAlarmAccessory.js.map +0 -1
- package/dist/devices-matter/TemperatureSensorAccessory.d.ts +0 -12
- package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +0 -1
- package/dist/devices-matter/TemperatureSensorAccessory.js +0 -36
- package/dist/devices-matter/TemperatureSensorAccessory.js.map +0 -1
- package/dist/devices-matter/ThermostatAccessory.d.ts +0 -19
- package/dist/devices-matter/ThermostatAccessory.d.ts.map +0 -1
- package/dist/devices-matter/ThermostatAccessory.js +0 -95
- package/dist/devices-matter/ThermostatAccessory.js.map +0 -1
- package/dist/devices-matter/VenetianBlindAccessory.d.ts +0 -19
- package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +0 -1
- package/dist/devices-matter/VenetianBlindAccessory.js +0 -99
- package/dist/devices-matter/VenetianBlindAccessory.js.map +0 -1
- package/dist/devices-matter/WindowBlindAccessory.d.ts +0 -17
- package/dist/devices-matter/WindowBlindAccessory.d.ts.map +0 -1
- package/dist/devices-matter/WindowBlindAccessory.js +0 -131
- package/dist/devices-matter/WindowBlindAccessory.js.map +0 -1
- package/dist/devices-matter/custom/PowerStripAccessory.d.ts +0 -97
- package/dist/devices-matter/custom/PowerStripAccessory.d.ts.map +0 -1
- package/dist/devices-matter/custom/PowerStripAccessory.js +0 -265
- package/dist/devices-matter/custom/PowerStripAccessory.js.map +0 -1
- package/dist/devices-matter/custom/index.d.ts +0 -8
- package/dist/devices-matter/custom/index.d.ts.map +0 -1
- package/dist/devices-matter/custom/index.js +0 -8
- package/dist/devices-matter/custom/index.js.map +0 -1
- package/dist/devices-matter/index.d.ts +0 -29
- package/dist/devices-matter/index.d.ts.map +0 -1
- package/dist/devices-matter/index.js +0 -28
- package/dist/devices-matter/index.js.map +0 -1
- package/dist/irdevice/airconditioner.d.ts +0 -61
- package/dist/irdevice/airconditioner.d.ts.map +0 -1
- package/dist/irdevice/airconditioner.js +0 -472
- package/dist/irdevice/airconditioner.js.map +0 -1
- package/dist/irdevice/airpurifier.d.ts +0 -50
- package/dist/irdevice/airpurifier.d.ts.map +0 -1
- package/dist/irdevice/airpurifier.js +0 -213
- package/dist/irdevice/airpurifier.js.map +0 -1
- package/dist/irdevice/camera.d.ts +0 -32
- package/dist/irdevice/camera.d.ts.map +0 -1
- package/dist/irdevice/camera.js +0 -107
- package/dist/irdevice/camera.js.map +0 -1
- package/dist/irdevice/fan.d.ts +0 -36
- package/dist/irdevice/fan.d.ts.map +0 -1
- package/dist/irdevice/fan.js +0 -200
- package/dist/irdevice/fan.js.map +0 -1
- package/dist/irdevice/irdevice.d.ts +0 -69
- package/dist/irdevice/irdevice.d.ts.map +0 -1
- package/dist/irdevice/irdevice.js +0 -339
- package/dist/irdevice/irdevice.js.map +0 -1
- package/dist/irdevice/light.d.ts +0 -36
- package/dist/irdevice/light.d.ts.map +0 -1
- package/dist/irdevice/light.js +0 -206
- package/dist/irdevice/light.js.map +0 -1
- package/dist/irdevice/other.d.ts +0 -57
- package/dist/irdevice/other.d.ts.map +0 -1
- package/dist/irdevice/other.js +0 -778
- package/dist/irdevice/other.js.map +0 -1
- package/dist/irdevice/tv.d.ts +0 -45
- package/dist/irdevice/tv.d.ts.map +0 -1
- package/dist/irdevice/tv.js +0 -327
- package/dist/irdevice/tv.js.map +0 -1
- package/dist/irdevice/vacuumcleaner.d.ts +0 -28
- package/dist/irdevice/vacuumcleaner.d.ts.map +0 -1
- package/dist/irdevice/vacuumcleaner.js +0 -104
- package/dist/irdevice/vacuumcleaner.js.map +0 -1
- package/dist/irdevice/waterheater.d.ts +0 -30
- package/dist/irdevice/waterheater.d.ts.map +0 -1
- package/dist/irdevice/waterheater.js +0 -105
- package/dist/irdevice/waterheater.js.map +0 -1
- package/dist/platform-hap.d.ts +0 -160
- package/dist/platform-hap.d.ts.map +0 -1
- package/dist/platform-hap.js +0 -3041
- package/dist/platform-hap.js.map +0 -1
- package/dist/platform-matter.d.ts +0 -188
- package/dist/platform-matter.d.ts.map +0 -1
- package/dist/platform-matter.js +0 -2545
- package/dist/platform-matter.js.map +0 -1
- package/dist/test/apiRequestTracker.test.d.ts +0 -2
- package/dist/test/apiRequestTracker.test.d.ts.map +0 -1
- package/dist/test/apiRequestTracker.test.js +0 -392
- package/dist/test/apiRequestTracker.test.js.map +0 -1
- package/dist/test/hap/device-webhook-context.test.d.ts +0 -2
- package/dist/test/hap/device-webhook-context.test.d.ts.map +0 -1
- package/dist/test/hap/device-webhook-context.test.js +0 -128
- package/dist/test/hap/device-webhook-context.test.js.map +0 -1
- package/dist/test/hap/platform-hap.logging.test.d.ts +0 -2
- package/dist/test/hap/platform-hap.logging.test.d.ts.map +0 -1
- package/dist/test/hap/platform-hap.logging.test.js +0 -33
- package/dist/test/hap/platform-hap.logging.test.js.map +0 -1
- package/dist/test/hap/platform-hap.test.d.ts +0 -2
- package/dist/test/hap/platform-hap.test.d.ts.map +0 -1
- package/dist/test/hap/platform-hap.test.js +0 -62
- package/dist/test/hap/platform-hap.test.js.map +0 -1
- package/dist/test/helpers/platform-fixtures.d.ts +0 -9
- package/dist/test/helpers/platform-fixtures.d.ts.map +0 -1
- package/dist/test/helpers/platform-fixtures.js +0 -30
- package/dist/test/helpers/platform-fixtures.js.map +0 -1
- package/dist/test/homebridge-ui/server.test.d.ts +0 -2
- package/dist/test/homebridge-ui/server.test.d.ts.map +0 -1
- package/dist/test/homebridge-ui/server.test.js +0 -445
- package/dist/test/homebridge-ui/server.test.js.map +0 -1
- package/dist/test/index.test.d.ts +0 -2
- package/dist/test/index.test.d.ts.map +0 -1
- package/dist/test/index.test.js +0 -19
- package/dist/test/index.test.js.map +0 -1
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts +0 -2
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts.map +0 -1
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js +0 -71
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js.map +0 -1
- package/dist/test/matter/platform-matter.additional.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.additional.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.additional.test.js +0 -35
- package/dist/test/matter/platform-matter.additional.test.js.map +0 -1
- package/dist/test/matter/platform-matter.bleparse.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.bleparse.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.bleparse.test.js +0 -43
- package/dist/test/matter/platform-matter.bleparse.test.js.map +0 -1
- package/dist/test/matter/platform-matter.cleanup.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.cleanup.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.cleanup.test.js +0 -70
- package/dist/test/matter/platform-matter.cleanup.test.js.map +0 -1
- package/dist/test/matter/platform-matter.keepstale.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.keepstale.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.keepstale.test.js +0 -27
- package/dist/test/matter/platform-matter.keepstale.test.js.map +0 -1
- package/dist/test/matter/platform-matter.logging.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.logging.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.logging.test.js +0 -29
- package/dist/test/matter/platform-matter.logging.test.js.map +0 -1
- package/dist/test/matter/platform-matter.mapping.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.mapping.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.mapping.test.js +0 -43
- package/dist/test/matter/platform-matter.mapping.test.js.map +0 -1
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.openapi-mapping.test.js +0 -84
- package/dist/test/matter/platform-matter.openapi-mapping.test.js.map +0 -1
- package/dist/test/matter/platform-matter.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.test.js +0 -117
- package/dist/test/matter/platform-matter.test.js.map +0 -1
- package/dist/test/matter/platform-matter.unregister.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.unregister.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.unregister.test.js +0 -30
- package/dist/test/matter/platform-matter.unregister.test.js.map +0 -1
- package/dist/test/matter/platform-matter.webhook.test.d.ts +0 -2
- package/dist/test/matter/platform-matter.webhook.test.d.ts.map +0 -1
- package/dist/test/matter/platform-matter.webhook.test.js +0 -46
- package/dist/test/matter/platform-matter.webhook.test.js.map +0 -1
- package/dist/test/utils.test.d.ts +0 -2
- package/dist/test/utils.test.d.ts.map +0 -1
- package/dist/test/utils.test.js +0 -95
- package/dist/test/utils.test.js.map +0 -1
- package/dist/test/verifyconfig.test.d.ts +0 -2
- package/dist/test/verifyconfig.test.d.ts.map +0 -1
- package/dist/test/verifyconfig.test.js +0 -167
- package/dist/test/verifyconfig.test.js.map +0 -1
- package/src/custom.d.ts +0 -7
- package/src/devices-hap/airpurifier.ts +0 -568
- package/src/devices-hap/blindtilt.ts +0 -1049
- package/src/devices-hap/bot.ts +0 -910
- package/src/devices-hap/ceilinglight.ts +0 -747
- package/src/devices-hap/colorbulb.ts +0 -940
- package/src/devices-hap/contact.ts +0 -457
- package/src/devices-hap/curtain.ts +0 -944
- package/src/devices-hap/device.ts +0 -890
- package/src/devices-hap/fan.ts +0 -716
- package/src/devices-hap/hub.ts +0 -440
- package/src/devices-hap/humidifier.ts +0 -762
- package/src/devices-hap/iosensor.ts +0 -442
- package/src/devices-hap/lightstrip.ts +0 -863
- package/src/devices-hap/lock.ts +0 -627
- package/src/devices-hap/meter.ts +0 -427
- package/src/devices-hap/meterplus.ts +0 -431
- package/src/devices-hap/meterpro.ts +0 -523
- package/src/devices-hap/motion.ts +0 -390
- package/src/devices-hap/plug.ts +0 -427
- package/src/devices-hap/relayswitch.ts +0 -727
- package/src/devices-hap/robotvacuumcleaner.ts +0 -574
- package/src/devices-hap/waterdetector.ts +0 -400
- package/src/devices-matter/BaseMatterAccessory.ts +0 -302
- package/src/devices-matter/ColorLightAccessory.ts +0 -110
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -90
- package/src/devices-matter/ContactSensorAccessory.ts +0 -41
- package/src/devices-matter/DimmableLightAccessory.ts +0 -192
- package/src/devices-matter/DoorLockAccessory.ts +0 -60
- package/src/devices-matter/ExtendedColorLightAccessory.ts +0 -122
- package/src/devices-matter/FanAccessory.ts +0 -95
- package/src/devices-matter/HumiditySensorAccessory.ts +0 -41
- package/src/devices-matter/LeakSensorAccessory.ts +0 -40
- package/src/devices-matter/LightSensorAccessory.ts +0 -41
- package/src/devices-matter/OccupancySensorAccessory.ts +0 -48
- package/src/devices-matter/OnOffLightAccessory.ts +0 -125
- package/src/devices-matter/OnOffOutletAccessory.ts +0 -51
- package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
- package/src/devices-matter/RoboticVacuumAccessory.ts +0 -621
- package/src/devices-matter/SmokeCOAlarmAccessory.ts +0 -59
- package/src/devices-matter/TemperatureSensorAccessory.ts +0 -43
- package/src/devices-matter/ThermostatAccessory.ts +0 -110
- package/src/devices-matter/VenetianBlindAccessory.ts +0 -115
- package/src/devices-matter/WindowBlindAccessory.ts +0 -135
- package/src/devices-matter/custom/PowerStripAccessory.ts +0 -309
- package/src/devices-matter/custom/index.ts +0 -8
- package/src/devices-matter/index.ts +0 -29
- package/src/irdevice/airconditioner.ts +0 -533
- package/src/irdevice/airpurifier.ts +0 -252
- package/src/irdevice/camera.ts +0 -129
- package/src/irdevice/fan.ts +0 -226
- package/src/irdevice/irdevice.ts +0 -383
- package/src/irdevice/light.ts +0 -246
- package/src/irdevice/other.ts +0 -790
- package/src/irdevice/tv.ts +0 -378
- package/src/irdevice/vacuumcleaner.ts +0 -126
- package/src/irdevice/waterheater.ts +0 -127
- package/src/platform-hap.ts +0 -3193
- package/src/platform-matter.ts +0 -2703
- package/src/test/apiRequestTracker.test.ts +0 -417
- package/src/test/hap/device-webhook-context.test.ts +0 -136
- package/src/test/hap/platform-hap.logging.test.ts +0 -36
- package/src/test/hap/platform-hap.test.ts +0 -70
- package/src/test/helpers/platform-fixtures.ts +0 -33
- package/src/test/homebridge-ui/server.test.ts +0 -486
- package/src/test/index.test.ts +0 -24
- package/src/test/matter/devices-matter/baseMatterAccessory.test.ts +0 -88
- package/src/test/matter/platform-matter.additional.test.ts +0 -44
- package/src/test/matter/platform-matter.bleparse.test.ts +0 -47
- package/src/test/matter/platform-matter.cleanup.test.ts +0 -86
- package/src/test/matter/platform-matter.keepstale.test.ts +0 -37
- package/src/test/matter/platform-matter.logging.test.ts +0 -33
- package/src/test/matter/platform-matter.mapping.test.ts +0 -57
- package/src/test/matter/platform-matter.openapi-mapping.test.ts +0 -109
- package/src/test/matter/platform-matter.test.ts +0 -144
- package/src/test/matter/platform-matter.unregister.test.ts +0 -39
- package/src/test/matter/platform-matter.webhook.test.ts +0 -54
- package/src/test/utils.test.ts +0 -96
- package/src/test/verifyconfig.test.ts +0 -198
|
@@ -0,0 +1,1035 @@
|
|
|
1
|
+
import { MATTER_ATTRIBUTE_IDS, MATTER_CLUSTER_IDS } from '../utils.js';
|
|
2
|
+
import { DeviceBase } from './deviceBase.js';
|
|
3
|
+
export class GenericDevice extends DeviceBase {
|
|
4
|
+
constructor(opts, cfg) {
|
|
5
|
+
super(opts, cfg);
|
|
6
|
+
}
|
|
7
|
+
async getState() {
|
|
8
|
+
// Default: return minimal info; implementations should override
|
|
9
|
+
if (this.client && typeof this.client.getDevice === 'function') {
|
|
10
|
+
try {
|
|
11
|
+
const raw = await this.client.getDevice(this.opts.id);
|
|
12
|
+
// Normalize common response shapes
|
|
13
|
+
try {
|
|
14
|
+
const device = raw?.body ?? raw;
|
|
15
|
+
return device;
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return raw;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
// ignore and fallback
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { id: this.opts.id, type: this.opts.type };
|
|
26
|
+
}
|
|
27
|
+
async setState(change) {
|
|
28
|
+
// Apply change via SwitchBot API in real implementation
|
|
29
|
+
// Translate common high-level changes into SwitchBot OpenAPI commands
|
|
30
|
+
if (!this.client) {
|
|
31
|
+
return { success: false, reason: 'no client', change };
|
|
32
|
+
}
|
|
33
|
+
const cmdBody = {};
|
|
34
|
+
if (typeof change.on === 'boolean') {
|
|
35
|
+
cmdBody.command = change.on ? 'turnOn' : 'turnOff';
|
|
36
|
+
cmdBody.parameter = 'default';
|
|
37
|
+
cmdBody.commandType = 'command';
|
|
38
|
+
}
|
|
39
|
+
else if (typeof change.brightness === 'number') {
|
|
40
|
+
const v = Math.max(0, Math.min(100, Number(change.brightness)));
|
|
41
|
+
cmdBody.command = 'setBrightness';
|
|
42
|
+
cmdBody.parameter = String(v);
|
|
43
|
+
cmdBody.commandType = 'command';
|
|
44
|
+
}
|
|
45
|
+
else if (typeof change.speed === 'number') {
|
|
46
|
+
const v = Math.max(0, Math.min(100, Number(change.speed)));
|
|
47
|
+
cmdBody.command = 'setFanSpeed';
|
|
48
|
+
cmdBody.parameter = String(v);
|
|
49
|
+
cmdBody.commandType = 'command';
|
|
50
|
+
}
|
|
51
|
+
else if (typeof change.position === 'number') {
|
|
52
|
+
const v = Math.max(0, Math.min(100, Number(change.position)));
|
|
53
|
+
cmdBody.command = 'setPosition';
|
|
54
|
+
cmdBody.parameter = String(v);
|
|
55
|
+
cmdBody.commandType = 'command';
|
|
56
|
+
}
|
|
57
|
+
else if (typeof change.locked === 'boolean') {
|
|
58
|
+
cmdBody.command = change.locked ? 'lock' : 'unlock';
|
|
59
|
+
cmdBody.parameter = 'default';
|
|
60
|
+
cmdBody.commandType = 'command';
|
|
61
|
+
}
|
|
62
|
+
else if (typeof change.start === 'boolean') {
|
|
63
|
+
cmdBody.command = change.start ? 'start' : 'stop';
|
|
64
|
+
cmdBody.parameter = 'default';
|
|
65
|
+
cmdBody.commandType = 'command';
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// If caller supplied an explicit command body, pass through
|
|
69
|
+
if (change && typeof change.command === 'string') {
|
|
70
|
+
Object.assign(cmdBody, change);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Fallback: send raw change to client setDeviceState
|
|
74
|
+
try {
|
|
75
|
+
if (typeof this.client.setDeviceState === 'function') {
|
|
76
|
+
return await this.client.setDeviceState(this.opts.id, change);
|
|
77
|
+
}
|
|
78
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
79
|
+
return await this.client.sendCommand(this.opts.id, change);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
const e = err;
|
|
84
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
85
|
+
}
|
|
86
|
+
return { success: false, reason: 'unsupported change', change };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
return await this.client.setDeviceState(this.opts.id, cmdBody);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
// try alternative client API if available
|
|
94
|
+
try {
|
|
95
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
96
|
+
return await this.client.sendCommand(this.opts.id, cmdBody);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (e2) {
|
|
100
|
+
// ignore
|
|
101
|
+
}
|
|
102
|
+
const e = err;
|
|
103
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
createHAPAccessory(api) {
|
|
107
|
+
// Default HAP descriptor: a Switch service with On characteristic
|
|
108
|
+
return {
|
|
109
|
+
services: [
|
|
110
|
+
{
|
|
111
|
+
type: 'Switch',
|
|
112
|
+
characteristics: {
|
|
113
|
+
On: {
|
|
114
|
+
get: async () => {
|
|
115
|
+
const s = await this.getState();
|
|
116
|
+
return !!(s && (s.on === true || s.state === 'on' || s.power === 'on'));
|
|
117
|
+
},
|
|
118
|
+
set: async (v) => {
|
|
119
|
+
await this.setState({ on: !!v });
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// Default Matter descriptor mirrors HAP descriptor structure so the
|
|
128
|
+
// platform can construct a Matter accessory representation when
|
|
129
|
+
// Homebridge Matter APIs are available. Device subclasses may override
|
|
130
|
+
// this to provide Matter-specific clusters/attributes if desired.
|
|
131
|
+
createMatterAccessory(api) {
|
|
132
|
+
const hapDesc = this.createHAPAccessory(api);
|
|
133
|
+
const clusters = [];
|
|
134
|
+
const mapCharacteristic = (charName) => {
|
|
135
|
+
switch (charName) {
|
|
136
|
+
case 'On':
|
|
137
|
+
return { attr: 'onOff', get: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, set: async (v) => this.setState({ on: !!v }) };
|
|
138
|
+
case 'Brightness':
|
|
139
|
+
return { attr: 'brightness', get: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, set: async (v) => this.setState({ brightness: Number(v) }) };
|
|
140
|
+
case 'Hue':
|
|
141
|
+
return { attr: 'colorHue', get: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, set: async (v) => this.setState({ hue: Number(v) }) };
|
|
142
|
+
case 'Saturation':
|
|
143
|
+
return { attr: 'colorSaturation', get: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, set: async (v) => this.setState({ saturation: Number(v) }) };
|
|
144
|
+
case 'ColorTemperature':
|
|
145
|
+
return { attr: 'colorTemperature', get: async () => {
|
|
146
|
+
const s = await this.getState();
|
|
147
|
+
if (typeof s.colorTemperature === 'number') {
|
|
148
|
+
return s.colorTemperature;
|
|
149
|
+
}
|
|
150
|
+
if (typeof s.kelvin === 'number') {
|
|
151
|
+
return Math.round(1000000 / s.kelvin);
|
|
152
|
+
}
|
|
153
|
+
return 400;
|
|
154
|
+
}, set: async (v) => this.setState({ colorTemperature: Number(v) }) };
|
|
155
|
+
case 'RotationSpeed':
|
|
156
|
+
return { attr: 'rotationSpeed', get: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, set: async (v) => this.setState({ speed: Number(v) }) };
|
|
157
|
+
case 'TargetPosition':
|
|
158
|
+
case 'CurrentPosition':
|
|
159
|
+
return { attr: 'position', get: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, set: async (v) => this.setState({ position: Number(v) }) };
|
|
160
|
+
case 'LockCurrentState':
|
|
161
|
+
case 'LockTargetState':
|
|
162
|
+
return { attr: 'locked', get: async () => { const s = await this.getState(); return !!(s && s.locked); }, set: async (v) => this.setState({ locked: !!v }) };
|
|
163
|
+
case 'MotionDetected':
|
|
164
|
+
return { attr: 'motionDetected', get: async () => { const s = await this.getState(); return !!(s && s.motion === true); }, set: undefined };
|
|
165
|
+
case 'ContactSensorState':
|
|
166
|
+
return { attr: 'contact', get: async () => { const s = await this.getState(); return s && s.open ? 1 : 0; }, set: undefined };
|
|
167
|
+
default:
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
for (const s of (hapDesc.services || [])) {
|
|
172
|
+
const clusterType = (() => {
|
|
173
|
+
switch ((s.type || '').toLowerCase()) {
|
|
174
|
+
case 'lightbulb': return 'OnOff/LevelControl/ColorControl';
|
|
175
|
+
case 'fan': return 'FanControl';
|
|
176
|
+
case 'windowscovering': return 'Shade';
|
|
177
|
+
case 'motionsensor': return 'OccupancySensing';
|
|
178
|
+
case 'contactsensor': return 'DoorState';
|
|
179
|
+
case 'lockmechanism': return 'DoorLock';
|
|
180
|
+
case 'switch': return 'OnOff';
|
|
181
|
+
default: return s.type || 'Generic';
|
|
182
|
+
}
|
|
183
|
+
})();
|
|
184
|
+
const attributes = {};
|
|
185
|
+
for (const [charName] of Object.entries(s.characteristics || {})) {
|
|
186
|
+
const mapped = mapCharacteristic(charName);
|
|
187
|
+
if (mapped) {
|
|
188
|
+
attributes[mapped.attr] = { read: typeof mapped.get === 'function' ? mapped.get : undefined, write: typeof mapped.set === 'function' ? mapped.set : undefined };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
clusters.push({ type: clusterType, attributes });
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
id: this.opts.id,
|
|
195
|
+
name: this.opts.name ?? this.opts.type,
|
|
196
|
+
protocol: 'matter',
|
|
197
|
+
clusters,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Specific device classes can extend GenericDevice for custom behavior.
|
|
202
|
+
export class BotDevice extends GenericDevice {
|
|
203
|
+
}
|
|
204
|
+
export class CurtainDevice extends GenericDevice {
|
|
205
|
+
createHAPAccessory(api) {
|
|
206
|
+
return {
|
|
207
|
+
services: [
|
|
208
|
+
{
|
|
209
|
+
type: 'WindowCovering',
|
|
210
|
+
characteristics: {
|
|
211
|
+
CurrentPosition: {
|
|
212
|
+
get: async () => {
|
|
213
|
+
const s = await this.getState();
|
|
214
|
+
return typeof s.position === 'number' ? s.position : 0;
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
TargetPosition: {
|
|
218
|
+
get: async () => {
|
|
219
|
+
const s = await this.getState();
|
|
220
|
+
return typeof s.position === 'number' ? s.position : 0;
|
|
221
|
+
},
|
|
222
|
+
set: async (v) => {
|
|
223
|
+
await this.setState({ position: Number(v) });
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// Matter-specific descriptor for Curtain (Shade cluster)
|
|
232
|
+
createMatterAccessory(api) {
|
|
233
|
+
return {
|
|
234
|
+
id: this.opts.id,
|
|
235
|
+
name: this.opts.name ?? this.opts.type,
|
|
236
|
+
protocol: 'matter',
|
|
237
|
+
clusters: [
|
|
238
|
+
{
|
|
239
|
+
// Shade cluster
|
|
240
|
+
type: 'Shade',
|
|
241
|
+
clusterId: MATTER_CLUSTER_IDS.WindowCovering,
|
|
242
|
+
attributes: {
|
|
243
|
+
currentPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: undefined },
|
|
244
|
+
[MATTER_ATTRIBUTE_IDS.WindowCovering.CurrentPosition]: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: undefined },
|
|
245
|
+
targetPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: async (v) => this.setState({ position: Number(v) }) },
|
|
246
|
+
[MATTER_ATTRIBUTE_IDS.WindowCovering.TargetPosition]: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: async (v) => this.setState({ position: Number(v) }) },
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export class FanDevice extends GenericDevice {
|
|
254
|
+
createHAPAccessory(api) {
|
|
255
|
+
return {
|
|
256
|
+
services: [
|
|
257
|
+
{
|
|
258
|
+
type: 'Fan',
|
|
259
|
+
characteristics: {
|
|
260
|
+
On: {
|
|
261
|
+
get: async () => {
|
|
262
|
+
const s = await this.getState();
|
|
263
|
+
return !!(s && (s.on === true || s.state === 'on'));
|
|
264
|
+
},
|
|
265
|
+
set: async (v) => {
|
|
266
|
+
await this.setState({ on: !!v });
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
RotationSpeed: {
|
|
270
|
+
get: async () => {
|
|
271
|
+
const s = await this.getState();
|
|
272
|
+
return typeof s.speed === 'number' ? s.speed : 0;
|
|
273
|
+
},
|
|
274
|
+
set: async (v) => {
|
|
275
|
+
await this.setState({ speed: Number(v) });
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async setState(change) {
|
|
284
|
+
if (!this.client) {
|
|
285
|
+
return { success: false, reason: 'no client' };
|
|
286
|
+
}
|
|
287
|
+
// Oscillation support
|
|
288
|
+
if (typeof change.oscillate === 'boolean') {
|
|
289
|
+
const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
|
|
290
|
+
try {
|
|
291
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
try {
|
|
295
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
296
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
catch (e) { }
|
|
300
|
+
const e = err;
|
|
301
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// Swing / sweep support (angle or mode)
|
|
305
|
+
if (change && (typeof change.swing === 'boolean' || typeof change.swingAngle === 'number' || typeof change.swingMode === 'string')) {
|
|
306
|
+
let param = 'default';
|
|
307
|
+
if (typeof change.swingMode === 'string') {
|
|
308
|
+
param = change.swingMode;
|
|
309
|
+
}
|
|
310
|
+
else if (typeof change.swingAngle === 'number') {
|
|
311
|
+
param = String(Number(change.swingAngle));
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
param = change.swing ? 'on' : 'off';
|
|
315
|
+
}
|
|
316
|
+
const body = { command: 'setSwing', parameter: param, commandType: 'command' };
|
|
317
|
+
try {
|
|
318
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
try {
|
|
322
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
323
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (e) { }
|
|
327
|
+
const e = err;
|
|
328
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return super.setState(change);
|
|
332
|
+
}
|
|
333
|
+
// Matter-specific descriptor for Fan
|
|
334
|
+
createMatterAccessory(api) {
|
|
335
|
+
return {
|
|
336
|
+
id: this.opts.id,
|
|
337
|
+
name: this.opts.name ?? this.opts.type,
|
|
338
|
+
protocol: 'matter',
|
|
339
|
+
clusters: [
|
|
340
|
+
{
|
|
341
|
+
// OnOff cluster
|
|
342
|
+
type: 'OnOff',
|
|
343
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
344
|
+
attributes: {
|
|
345
|
+
onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
|
|
346
|
+
// numeric attribute id for onOff
|
|
347
|
+
[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 }) },
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
// Fan Control cluster
|
|
352
|
+
type: 'FanControl',
|
|
353
|
+
clusterId: MATTER_CLUSTER_IDS.FanControl,
|
|
354
|
+
attributes: {
|
|
355
|
+
rotationSpeed: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
|
|
356
|
+
[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) }) },
|
|
357
|
+
oscillation: { read: async () => { const s = await this.getState(); return !!s?.oscillating; }, write: async (v) => this.setState({ oscillate: !!v }) },
|
|
358
|
+
swingMode: { read: async () => { const s = await this.getState(); return s?.swingMode ?? null; }, write: async (v) => this.setState({ swingMode: v }) },
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
export class LightDevice extends GenericDevice {
|
|
366
|
+
createHAPAccessory(api) {
|
|
367
|
+
return {
|
|
368
|
+
services: [
|
|
369
|
+
{
|
|
370
|
+
type: 'Lightbulb',
|
|
371
|
+
characteristics: {
|
|
372
|
+
On: {
|
|
373
|
+
get: async () => {
|
|
374
|
+
const s = await this.getState();
|
|
375
|
+
return !!(s && (s.on === true || s.state === 'on' || s.power === 'on'));
|
|
376
|
+
},
|
|
377
|
+
set: async (v) => {
|
|
378
|
+
await this.setState({ on: !!v });
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
Brightness: {
|
|
382
|
+
props: { minValue: 0, maxValue: 100, minStep: 1 },
|
|
383
|
+
get: async () => {
|
|
384
|
+
const s = await this.getState();
|
|
385
|
+
return typeof s.brightness === 'number' ? s.brightness : 100;
|
|
386
|
+
},
|
|
387
|
+
set: async (v) => {
|
|
388
|
+
await this.setState({ brightness: Number(v) });
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
Hue: {
|
|
392
|
+
props: { minValue: 0, maxValue: 360, minStep: 1 },
|
|
393
|
+
get: async () => {
|
|
394
|
+
const s = await this.getState();
|
|
395
|
+
// prefer explicit hue if provided
|
|
396
|
+
if (s && typeof s.hue === 'number') {
|
|
397
|
+
return s.hue;
|
|
398
|
+
}
|
|
399
|
+
// try HSV from color hex
|
|
400
|
+
const hex = s?.color || s?.colorHex || s?.colour;
|
|
401
|
+
if (typeof hex === 'string' && /^#?[0-9A-F]{6}$/i.test(hex)) {
|
|
402
|
+
const h = (() => {
|
|
403
|
+
const hsl = (h, s, l) => ({ h, s, l });
|
|
404
|
+
// convert hex -> rgb -> hsv
|
|
405
|
+
const cleaned = hex.replace('#', '');
|
|
406
|
+
const r = Number.parseInt(cleaned.substr(0, 2), 16) / 255;
|
|
407
|
+
const g = Number.parseInt(cleaned.substr(2, 2), 16) / 255;
|
|
408
|
+
const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255;
|
|
409
|
+
const mx = Math.max(r, g, b);
|
|
410
|
+
const mn = Math.min(r, g, b);
|
|
411
|
+
const d = mx - mn;
|
|
412
|
+
if (d === 0) {
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
let hue = 0;
|
|
416
|
+
switch (mx) {
|
|
417
|
+
case r:
|
|
418
|
+
hue = ((g - b) / d) % 6;
|
|
419
|
+
break;
|
|
420
|
+
case g:
|
|
421
|
+
hue = (b - r) / d + 2;
|
|
422
|
+
break;
|
|
423
|
+
case b:
|
|
424
|
+
hue = (r - g) / d + 4;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
hue = Math.round(hue * 60);
|
|
428
|
+
if (hue < 0) {
|
|
429
|
+
hue += 360;
|
|
430
|
+
}
|
|
431
|
+
return hue;
|
|
432
|
+
})();
|
|
433
|
+
return h;
|
|
434
|
+
}
|
|
435
|
+
return 0;
|
|
436
|
+
},
|
|
437
|
+
set: async (v) => {
|
|
438
|
+
await this.setState({ hue: Number(v) });
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
Saturation: {
|
|
442
|
+
props: { minValue: 0, maxValue: 100, minStep: 1 },
|
|
443
|
+
get: async () => {
|
|
444
|
+
const s = await this.getState();
|
|
445
|
+
if (s && typeof s.saturation === 'number') {
|
|
446
|
+
return s.saturation;
|
|
447
|
+
}
|
|
448
|
+
// if color hex is available, derive saturation from rgb
|
|
449
|
+
const hex = s?.color || s?.colorHex || s?.colour;
|
|
450
|
+
if (typeof hex === 'string' && /^#?[0-9A-F]{6}$/i.test(hex)) {
|
|
451
|
+
const cleaned = hex.replace('#', '');
|
|
452
|
+
const r = Number.parseInt(cleaned.substr(0, 2), 16) / 255;
|
|
453
|
+
const g = Number.parseInt(cleaned.substr(2, 2), 16) / 255;
|
|
454
|
+
const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255;
|
|
455
|
+
const mx = Math.max(r, g, b);
|
|
456
|
+
const mn = Math.min(r, g, b);
|
|
457
|
+
const d = mx - mn;
|
|
458
|
+
const sat = mx === 0 ? 0 : Math.round((d / mx) * 100);
|
|
459
|
+
return sat;
|
|
460
|
+
}
|
|
461
|
+
return 0;
|
|
462
|
+
},
|
|
463
|
+
set: async (v) => {
|
|
464
|
+
await this.setState({ saturation: Number(v) });
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
ColorTemperature: {
|
|
468
|
+
props: { minValue: 153, maxValue: 500, minStep: 1 },
|
|
469
|
+
get: async () => {
|
|
470
|
+
const s = await this.getState();
|
|
471
|
+
// prefer mired if provided
|
|
472
|
+
if (s && typeof s.colorTemperature === 'number') {
|
|
473
|
+
return s.colorTemperature;
|
|
474
|
+
}
|
|
475
|
+
if (s && typeof s.color_temp === 'number') {
|
|
476
|
+
return s.color_temp;
|
|
477
|
+
}
|
|
478
|
+
// some devices provide kelvin
|
|
479
|
+
if (s && typeof s.kelvin === 'number' && s.kelvin > 0) {
|
|
480
|
+
return Math.round(1000000 / s.kelvin);
|
|
481
|
+
}
|
|
482
|
+
return 400;
|
|
483
|
+
},
|
|
484
|
+
set: async (v) => {
|
|
485
|
+
await this.setState({ colorTemperature: Number(v) });
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
async setState(change) {
|
|
494
|
+
if (!this.client) {
|
|
495
|
+
return { success: false, reason: 'no client' };
|
|
496
|
+
}
|
|
497
|
+
// Color temperature (mired) or brightness/hue/sat
|
|
498
|
+
if (typeof change.colorTemperature === 'number' || typeof change.color_temp === 'number') {
|
|
499
|
+
const v = String(Number(change.colorTemperature ?? change.color_temp));
|
|
500
|
+
const body = { command: 'setColorTemperature', parameter: v, commandType: 'command' };
|
|
501
|
+
try {
|
|
502
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
503
|
+
}
|
|
504
|
+
catch (err) {
|
|
505
|
+
try {
|
|
506
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
507
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
catch (e) { }
|
|
511
|
+
const e = err;
|
|
512
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (typeof change.hue === 'number' && typeof change.saturation === 'number') {
|
|
516
|
+
const body = { command: 'setColor', parameter: `${Number(change.hue)},${Number(change.saturation)}`, commandType: 'command' };
|
|
517
|
+
try {
|
|
518
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
519
|
+
}
|
|
520
|
+
catch (err) {
|
|
521
|
+
try {
|
|
522
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
523
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
catch (e) { }
|
|
527
|
+
const e = err;
|
|
528
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (change && typeof change.color === 'string') {
|
|
532
|
+
const body = { command: 'setColor', parameter: change.color, commandType: 'command' };
|
|
533
|
+
try {
|
|
534
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
535
|
+
}
|
|
536
|
+
catch (err) {
|
|
537
|
+
try {
|
|
538
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
539
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
catch (e) { }
|
|
543
|
+
const e = err;
|
|
544
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// Fallback to generic handler (brightness/on)
|
|
548
|
+
return super.setState(change);
|
|
549
|
+
}
|
|
550
|
+
// Matter-specific descriptor for lights (OnOff + Level + Color)
|
|
551
|
+
createMatterAccessory(api) {
|
|
552
|
+
return {
|
|
553
|
+
id: this.opts.id,
|
|
554
|
+
name: this.opts.name ?? this.opts.type,
|
|
555
|
+
protocol: 'matter',
|
|
556
|
+
clusters: [
|
|
557
|
+
{
|
|
558
|
+
// OnOff cluster
|
|
559
|
+
type: 'OnOff',
|
|
560
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
561
|
+
attributes: {
|
|
562
|
+
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 }) },
|
|
563
|
+
[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 }) },
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
// Level Control cluster
|
|
568
|
+
type: 'LevelControl',
|
|
569
|
+
clusterId: MATTER_CLUSTER_IDS.LevelControl,
|
|
570
|
+
attributes: {
|
|
571
|
+
currentLevel: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
|
|
572
|
+
[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) }) },
|
|
573
|
+
},
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
// Color Control cluster
|
|
577
|
+
type: 'ColorControl',
|
|
578
|
+
clusterId: MATTER_CLUSTER_IDS.ColorControl,
|
|
579
|
+
attributes: {
|
|
580
|
+
colorHue: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
|
|
581
|
+
[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) }) },
|
|
582
|
+
colorSaturation: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
|
|
583
|
+
[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) }) },
|
|
584
|
+
colorTemperature: { read: async () => {
|
|
585
|
+
const s = await this.getState();
|
|
586
|
+
if (typeof s.colorTemperature === 'number') {
|
|
587
|
+
return s.colorTemperature;
|
|
588
|
+
}
|
|
589
|
+
if (typeof s.kelvin === 'number') {
|
|
590
|
+
return Math.round(1000000 / s.kelvin);
|
|
591
|
+
}
|
|
592
|
+
return 400;
|
|
593
|
+
}, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
|
|
594
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => {
|
|
595
|
+
const s = await this.getState();
|
|
596
|
+
if (typeof s.colorTemperature === 'number') {
|
|
597
|
+
return s.colorTemperature;
|
|
598
|
+
}
|
|
599
|
+
if (typeof s.kelvin === 'number') {
|
|
600
|
+
return Math.round(1000000 / s.kelvin);
|
|
601
|
+
}
|
|
602
|
+
return 400;
|
|
603
|
+
}, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
],
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
export class LightStripDevice extends LightDevice {
|
|
611
|
+
}
|
|
612
|
+
export class MotionSensorDevice extends GenericDevice {
|
|
613
|
+
createHAPAccessory(api) {
|
|
614
|
+
return {
|
|
615
|
+
services: [
|
|
616
|
+
{
|
|
617
|
+
type: 'MotionSensor',
|
|
618
|
+
characteristics: {
|
|
619
|
+
MotionDetected: {
|
|
620
|
+
get: async () => {
|
|
621
|
+
const s = await this.getState();
|
|
622
|
+
return !!(s && s.motion === true);
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
async setState(change) {
|
|
631
|
+
if (!this.client) {
|
|
632
|
+
return { success: false, reason: 'no client' };
|
|
633
|
+
}
|
|
634
|
+
// Oscillation support
|
|
635
|
+
if (typeof change.oscillate === 'boolean') {
|
|
636
|
+
const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
|
|
637
|
+
try {
|
|
638
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
639
|
+
}
|
|
640
|
+
catch (err) {
|
|
641
|
+
try {
|
|
642
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
643
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
catch (e) { }
|
|
647
|
+
const e = err;
|
|
648
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
// Swing / sweep support (angle or mode)
|
|
652
|
+
if (change && (typeof change.swing === 'boolean' || typeof change.swingAngle === 'number' || typeof change.swingMode === 'string')) {
|
|
653
|
+
let param = 'default';
|
|
654
|
+
if (typeof change.swingMode === 'string') {
|
|
655
|
+
param = change.swingMode;
|
|
656
|
+
}
|
|
657
|
+
else if (typeof change.swingAngle === 'number') {
|
|
658
|
+
param = String(Number(change.swingAngle));
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
param = change.swing ? 'on' : 'off';
|
|
662
|
+
}
|
|
663
|
+
const body = { command: 'setSwing', parameter: param, commandType: 'command' };
|
|
664
|
+
try {
|
|
665
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
666
|
+
}
|
|
667
|
+
catch (err) {
|
|
668
|
+
try {
|
|
669
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
670
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
catch (e) { }
|
|
674
|
+
const e = err;
|
|
675
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return super.setState(change);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
export class ContactSensorDevice extends GenericDevice {
|
|
682
|
+
createHAPAccessory(api) {
|
|
683
|
+
return {
|
|
684
|
+
services: [
|
|
685
|
+
{
|
|
686
|
+
type: 'ContactSensor',
|
|
687
|
+
characteristics: {
|
|
688
|
+
ContactSensorState: {
|
|
689
|
+
get: async () => {
|
|
690
|
+
const s = await this.getState();
|
|
691
|
+
return s && s.open ? 1 : 0;
|
|
692
|
+
},
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
],
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
export class VacuumDevice extends GenericDevice {
|
|
701
|
+
// Use DeviceBase defaults (Switch-style) — no override needed
|
|
702
|
+
createHAPAccessory(api) {
|
|
703
|
+
return super.createHAPAccessory(api);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
export class LockDevice extends GenericDevice {
|
|
707
|
+
createHAPAccessory(api) {
|
|
708
|
+
return {
|
|
709
|
+
services: [
|
|
710
|
+
{
|
|
711
|
+
type: 'LockMechanism',
|
|
712
|
+
characteristics: {
|
|
713
|
+
LockCurrentState: {
|
|
714
|
+
get: async () => {
|
|
715
|
+
const s = await this.getState();
|
|
716
|
+
return s && s.locked ? 1 : 0;
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
LockTargetState: {
|
|
720
|
+
get: async () => {
|
|
721
|
+
const s = await this.getState();
|
|
722
|
+
return s && s.locked ? 1 : 0;
|
|
723
|
+
},
|
|
724
|
+
set: async (v) => {
|
|
725
|
+
await this.setState({ locked: !!v });
|
|
726
|
+
},
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
],
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
async setState(change) {
|
|
734
|
+
if (!this.client) {
|
|
735
|
+
return { success: false, reason: 'no client' };
|
|
736
|
+
}
|
|
737
|
+
// User management actions: add/remove/list users, unlock with pin
|
|
738
|
+
if (change && typeof change.action === 'string') {
|
|
739
|
+
const action = change.action;
|
|
740
|
+
try {
|
|
741
|
+
if (action === 'addUser' && (change.user || change.userId) && (change.pin || change.code)) {
|
|
742
|
+
const user = change.user ?? change.userId;
|
|
743
|
+
const p = String(change.pin ?? change.code);
|
|
744
|
+
const body = { command: 'addUserCode', parameter: `${user}:${p}`, commandType: 'command' };
|
|
745
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
746
|
+
}
|
|
747
|
+
if (action === 'removeUser' && (change.user || change.userId)) {
|
|
748
|
+
const user = change.user ?? change.userId;
|
|
749
|
+
const body = { command: 'removeUserCode', parameter: String(user), commandType: 'command' };
|
|
750
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
751
|
+
}
|
|
752
|
+
if (action === 'listUsers') {
|
|
753
|
+
const body = { command: 'listUsers', parameter: 'default', commandType: 'command' };
|
|
754
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
755
|
+
}
|
|
756
|
+
if (action === 'unlockWithPin' && (change.pin || change.code)) {
|
|
757
|
+
const p = String(change.pin ?? change.code);
|
|
758
|
+
const body = { command: 'unlockWithPin', parameter: p, commandType: 'command' };
|
|
759
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
catch (err) {
|
|
763
|
+
try {
|
|
764
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
765
|
+
return await this.client.sendCommand(this.opts.id, { command: action, parameter: change.parameter ?? 'default', commandType: 'command' });
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
catch (e) { }
|
|
769
|
+
const e = err;
|
|
770
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
// Support setting lock PIN/passcode via `pin` or `passcode` (fallback)
|
|
774
|
+
const pin = change?.pin ?? change?.passcode ?? change?.code;
|
|
775
|
+
if (typeof pin === 'string' || typeof pin === 'number') {
|
|
776
|
+
const body = { command: 'setLockPin', parameter: String(pin), commandType: 'command' };
|
|
777
|
+
try {
|
|
778
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
779
|
+
}
|
|
780
|
+
catch (err) {
|
|
781
|
+
try {
|
|
782
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
783
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
catch (e) { }
|
|
787
|
+
const e = err;
|
|
788
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
return super.setState(change);
|
|
792
|
+
}
|
|
793
|
+
// Matter DoorLock descriptor including simple user-management actions
|
|
794
|
+
createMatterAccessory(api) {
|
|
795
|
+
return {
|
|
796
|
+
id: this.opts.id,
|
|
797
|
+
name: this.opts.name ?? this.opts.type,
|
|
798
|
+
protocol: 'matter',
|
|
799
|
+
clusters: [
|
|
800
|
+
{
|
|
801
|
+
// DoorLock cluster
|
|
802
|
+
type: 'DoorLock',
|
|
803
|
+
clusterId: MATTER_CLUSTER_IDS.DoorLock,
|
|
804
|
+
attributes: {
|
|
805
|
+
lockState: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
|
|
806
|
+
[MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
|
|
807
|
+
},
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
// DoorLock user mgmt cluster (conceptual)
|
|
811
|
+
type: 'DoorLockUserManagement',
|
|
812
|
+
clusterId: 0x0301,
|
|
813
|
+
attributes: {
|
|
814
|
+
addUser: { write: async (v) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }) },
|
|
815
|
+
removeUser: { write: async (v) => this.setState({ action: 'removeUser', user: v?.user }) },
|
|
816
|
+
listUsers: { read: async () => { const r = await this.setState({ action: 'listUsers' }); return r; }, write: undefined },
|
|
817
|
+
unlockWithPin: { write: async (v) => this.setState({ action: 'unlockWithPin', pin: v?.pin }) },
|
|
818
|
+
},
|
|
819
|
+
},
|
|
820
|
+
],
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
export class HumidifierDevice extends GenericDevice {
|
|
825
|
+
createHAPAccessory(api) {
|
|
826
|
+
return {
|
|
827
|
+
services: [
|
|
828
|
+
{
|
|
829
|
+
type: 'HumiditySensor',
|
|
830
|
+
characteristics: {
|
|
831
|
+
CurrentRelativeHumidity: {
|
|
832
|
+
get: async () => {
|
|
833
|
+
const s = await this.getState();
|
|
834
|
+
return typeof s.humidity === 'number' ? s.humidity : 0;
|
|
835
|
+
},
|
|
836
|
+
},
|
|
837
|
+
},
|
|
838
|
+
},
|
|
839
|
+
],
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
async setState(change) {
|
|
843
|
+
if (!this.client) {
|
|
844
|
+
return { success: false, reason: 'no client' };
|
|
845
|
+
}
|
|
846
|
+
if (typeof change.humidity === 'number') {
|
|
847
|
+
const v = String(Number(change.humidity));
|
|
848
|
+
const body = { command: 'setHumidity', parameter: v, commandType: 'command' };
|
|
849
|
+
try {
|
|
850
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
851
|
+
}
|
|
852
|
+
catch (err) {
|
|
853
|
+
try {
|
|
854
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
855
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
catch (e) { }
|
|
859
|
+
const e = err;
|
|
860
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (typeof change.dry === 'boolean') {
|
|
864
|
+
const body = { command: 'setDry', parameter: change.dry ? 'on' : 'off', commandType: 'command' };
|
|
865
|
+
try {
|
|
866
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
867
|
+
}
|
|
868
|
+
catch (err) {
|
|
869
|
+
try {
|
|
870
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
871
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
catch (e) { }
|
|
875
|
+
const e = err;
|
|
876
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return super.setState(change);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
// Provide Matter descriptor for humidifier (humidity and on/off)
|
|
883
|
+
export class HumidifierMatterDevice extends HumidifierDevice {
|
|
884
|
+
createMatterAccessory(api) {
|
|
885
|
+
return {
|
|
886
|
+
id: this.opts.id,
|
|
887
|
+
name: this.opts.name ?? this.opts.type,
|
|
888
|
+
protocol: 'matter',
|
|
889
|
+
clusters: [
|
|
890
|
+
{
|
|
891
|
+
// Relative Humidity Sensor cluster
|
|
892
|
+
type: 'RelativeHumiditySensor',
|
|
893
|
+
clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
|
|
894
|
+
attributes: {
|
|
895
|
+
currentRelativeHumidity: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
|
|
896
|
+
[MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
|
|
897
|
+
},
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
type: 'OnOff',
|
|
901
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
902
|
+
attributes: {
|
|
903
|
+
onOff: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
|
|
904
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
|
|
905
|
+
},
|
|
906
|
+
},
|
|
907
|
+
],
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
export class TemperatureSensorDevice extends GenericDevice {
|
|
912
|
+
createHAPAccessory(api) {
|
|
913
|
+
return {
|
|
914
|
+
services: [
|
|
915
|
+
{
|
|
916
|
+
type: 'TemperatureSensor',
|
|
917
|
+
characteristics: {
|
|
918
|
+
CurrentTemperature: {
|
|
919
|
+
get: async () => {
|
|
920
|
+
const s = await this.getState();
|
|
921
|
+
return typeof s.temperature === 'number' ? s.temperature : 0;
|
|
922
|
+
},
|
|
923
|
+
},
|
|
924
|
+
},
|
|
925
|
+
},
|
|
926
|
+
],
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
// Additional device classes (aliases / specialized variants)
|
|
931
|
+
export class RelaySwitchDevice extends GenericDevice {
|
|
932
|
+
}
|
|
933
|
+
export class RelaySwitch1PMDevice extends GenericDevice {
|
|
934
|
+
}
|
|
935
|
+
export class PlugDevice extends GenericDevice {
|
|
936
|
+
createHAPAccessory(api) {
|
|
937
|
+
return {
|
|
938
|
+
services: [
|
|
939
|
+
{
|
|
940
|
+
type: 'Outlet',
|
|
941
|
+
characteristics: {
|
|
942
|
+
On: {
|
|
943
|
+
get: async () => {
|
|
944
|
+
const s = await this.getState();
|
|
945
|
+
return !!(s && (s.on === true || s.state === 'on'));
|
|
946
|
+
},
|
|
947
|
+
set: async (v) => {
|
|
948
|
+
await this.setState({ on: !!v });
|
|
949
|
+
},
|
|
950
|
+
},
|
|
951
|
+
OutletInUse: {
|
|
952
|
+
get: async () => {
|
|
953
|
+
const s = await this.getState();
|
|
954
|
+
return s && s.inUse ? 1 : 0;
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
},
|
|
958
|
+
},
|
|
959
|
+
],
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
export class PlugMiniDevice extends PlugDevice {
|
|
964
|
+
}
|
|
965
|
+
export class BlindTiltDevice extends CurtainDevice {
|
|
966
|
+
}
|
|
967
|
+
export class Curtain3Device extends CurtainDevice {
|
|
968
|
+
}
|
|
969
|
+
export class RollerShadeDevice extends CurtainDevice {
|
|
970
|
+
}
|
|
971
|
+
export class Hub2Device extends GenericDevice {
|
|
972
|
+
}
|
|
973
|
+
export class MeterDevice extends GenericDevice {
|
|
974
|
+
createHAPAccessory(api) {
|
|
975
|
+
return {
|
|
976
|
+
services: [
|
|
977
|
+
{
|
|
978
|
+
type: 'TemperatureSensor',
|
|
979
|
+
characteristics: {
|
|
980
|
+
CurrentTemperature: {
|
|
981
|
+
get: async () => {
|
|
982
|
+
const s = await this.getState();
|
|
983
|
+
return typeof s.temperature === 'number' ? s.temperature : 0;
|
|
984
|
+
},
|
|
985
|
+
},
|
|
986
|
+
},
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
type: 'HumiditySensor',
|
|
990
|
+
characteristics: {
|
|
991
|
+
CurrentRelativeHumidity: {
|
|
992
|
+
get: async () => {
|
|
993
|
+
const s = await this.getState();
|
|
994
|
+
return typeof s.humidity === 'number' ? s.humidity : 0;
|
|
995
|
+
},
|
|
996
|
+
},
|
|
997
|
+
},
|
|
998
|
+
},
|
|
999
|
+
],
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
export class WaterDetectorDevice extends GenericDevice {
|
|
1004
|
+
createHAPAccessory(api) {
|
|
1005
|
+
return {
|
|
1006
|
+
services: [
|
|
1007
|
+
{
|
|
1008
|
+
type: 'LeakSensor',
|
|
1009
|
+
characteristics: {
|
|
1010
|
+
LeakDetected: {
|
|
1011
|
+
get: async () => {
|
|
1012
|
+
const s = await this.getState();
|
|
1013
|
+
return s && s.leak ? 1 : 0;
|
|
1014
|
+
},
|
|
1015
|
+
},
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
],
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
export class SmartFanDevice extends FanDevice {
|
|
1023
|
+
}
|
|
1024
|
+
export class StripLightDevice extends LightStripDevice {
|
|
1025
|
+
}
|
|
1026
|
+
export class WalletFinderDevice extends GenericDevice {
|
|
1027
|
+
}
|
|
1028
|
+
// K10 / WoSweeper variants map to VacuumDevice
|
|
1029
|
+
export class WoSweeperDevice extends VacuumDevice {
|
|
1030
|
+
}
|
|
1031
|
+
export class WoSweeperMiniDevice extends VacuumDevice {
|
|
1032
|
+
}
|
|
1033
|
+
export class WoSweeperMiniProDevice extends VacuumDevice {
|
|
1034
|
+
}
|
|
1035
|
+
//# sourceMappingURL=genericDevice.js.map
|