@switchbot/homebridge-switchbot 5.0.0-beta.7 → 5.0.0-beta.71
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 +35 -0
- package/E2E-VERIFICATION.md +121 -0
- package/MIGRATION.md +44 -0
- package/README.md +56 -3
- package/config.schema.json +99 -14823
- 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 +77 -245
- 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 +42 -36
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -12
- 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 -249
- 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 +39 -50
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +39 -688
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +14 -0
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/assets/style.css +3 -3
- package/docs/index.html +77 -13
- package/docs/variables/default.html +1 -1
- package/package.json +22 -21
- 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 +77 -245
- package/src/homebridge-ui/server.ts +49 -41
- package/src/index.ts +5 -13
- package/src/platform.ts +395 -0
- package/src/settings.ts +12 -277
- package/src/switchbotClient.ts +266 -0
- package/src/utils.ts +45 -713
- 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 -527
- 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 -811
- 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 -701
- 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 -881
- 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 -98
- package/dist/devices-hap/device.d.ts.map +0 -1
- package/dist/devices-hap/device.js +0 -749
- 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 -649
- 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 -392
- package/dist/devices-hap/hub.js.map +0 -1
- package/dist/devices-hap/humidifier.d.ts +0 -68
- package/dist/devices-hap/humidifier.d.ts.map +0 -1
- package/dist/devices-hap/humidifier.js +0 -628
- 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 -382
- 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 -797
- 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 -561
- 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 -379
- 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 -384
- 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 -468
- 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 -395
- 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 -523
- 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 -63
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
- package/dist/devices-matter/BaseMatterAccessory.js +0 -100
- 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 -78
- 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 -107
- 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 -118
- package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -12
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +0 -40
- 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 -68
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +0 -1
- package/dist/devices-matter/RoboticVacuumAccessory.js +0 -334
- 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 -80
- 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/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -14
- package/dist/index.test.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 -68
- package/dist/irdevice/irdevice.d.ts.map +0 -1
- package/dist/irdevice/irdevice.js +0 -298
- 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 -149
- package/dist/platform-hap.d.ts.map +0 -1
- package/dist/platform-hap.js +0 -2861
- package/dist/platform-hap.js.map +0 -1
- package/dist/platform-matter.d.ts +0 -101
- package/dist/platform-matter.d.ts.map +0 -1
- package/dist/platform-matter.js +0 -896
- package/dist/platform-matter.js.map +0 -1
- package/dist/verifyconfig.test.d.ts +0 -2
- package/dist/verifyconfig.test.d.ts.map +0 -1
- package/dist/verifyconfig.test.js +0 -167
- package/dist/verifyconfig.test.js.map +0 -1
- package/src/custom.d.ts +0 -7
- package/src/devices-hap/airpurifier.ts +0 -563
- package/src/devices-hap/blindtilt.ts +0 -1049
- package/src/devices-hap/bot.ts +0 -900
- package/src/devices-hap/ceilinglight.ts +0 -742
- package/src/devices-hap/colorbulb.ts +0 -904
- package/src/devices-hap/contact.ts +0 -457
- package/src/devices-hap/curtain.ts +0 -944
- package/src/devices-hap/device.ts +0 -811
- package/src/devices-hap/fan.ts +0 -711
- package/src/devices-hap/hub.ts +0 -439
- package/src/devices-hap/humidifier.ts +0 -669
- package/src/devices-hap/iosensor.ts +0 -427
- package/src/devices-hap/lightstrip.ts +0 -836
- package/src/devices-hap/lock.ts +0 -620
- package/src/devices-hap/meter.ts +0 -426
- package/src/devices-hap/meterplus.ts +0 -430
- package/src/devices-hap/meterpro.ts +0 -522
- package/src/devices-hap/motion.ts +0 -390
- package/src/devices-hap/plug.ts +0 -423
- package/src/devices-hap/relayswitch.ts +0 -727
- package/src/devices-hap/robotvacuumcleaner.ts +0 -568
- package/src/devices-hap/waterdetector.ts +0 -400
- package/src/devices-matter/BaseMatterAccessory.ts +0 -131
- package/src/devices-matter/ColorLightAccessory.ts +0 -110
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -92
- 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 -123
- 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 -133
- package/src/devices-matter/OnOffOutletAccessory.ts +0 -46
- package/src/devices-matter/OnOffSwitchAccessory.ts +0 -51
- package/src/devices-matter/RoboticVacuumAccessory.ts +0 -407
- 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 -92
- 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/index.test.ts +0 -19
- 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 -344
- 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 -2997
- package/src/platform-matter.ts +0 -1010
- package/src/verifyconfig.test.ts +0 -197
package/src/platform.ts
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import type { API, Logger, PlatformConfig } from 'homebridge'
|
|
2
|
+
import { SwitchBotClient } from './switchbotClient'
|
|
3
|
+
import { createDevice } from './deviceFactory'
|
|
4
|
+
import type { SwitchBotPluginConfig } from './settings'
|
|
5
|
+
import { PLUGIN_NAME, PLATFORM_NAME } from './settings'
|
|
6
|
+
|
|
7
|
+
// Which device types should prefer Matter if available
|
|
8
|
+
const DEVICE_MATTER_SUPPORTED: Record<string, boolean> = {
|
|
9
|
+
bot: false,
|
|
10
|
+
curtain: true,
|
|
11
|
+
fan: true,
|
|
12
|
+
light: true,
|
|
13
|
+
lightstrip: true,
|
|
14
|
+
motion: true,
|
|
15
|
+
contact: true,
|
|
16
|
+
vacuum: false,
|
|
17
|
+
lock: true,
|
|
18
|
+
humidifier: true,
|
|
19
|
+
temperature: true,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class SwitchBotHAPPlatform {
|
|
23
|
+
api: API | undefined
|
|
24
|
+
log: Logger
|
|
25
|
+
config: SwitchBotPluginConfig
|
|
26
|
+
devices: any[] = []
|
|
27
|
+
// cached accessories restored by Homebridge
|
|
28
|
+
accessories: Map<string, any>
|
|
29
|
+
|
|
30
|
+
constructor(log: Logger, config: PlatformConfig, api?: API) {
|
|
31
|
+
this.log = log
|
|
32
|
+
this.config = (config as any) ?? {}
|
|
33
|
+
this.api = api
|
|
34
|
+
this.accessories = new Map()
|
|
35
|
+
this.log.info('SwitchBot HAP platform initialized')
|
|
36
|
+
|
|
37
|
+
// Create/shared SwitchBot client and attach to config so child devices reuse it.
|
|
38
|
+
try {
|
|
39
|
+
const client = new SwitchBotClient(this.config)
|
|
40
|
+
void client.init()
|
|
41
|
+
;(this.config as any)._client = client
|
|
42
|
+
} catch (e) {
|
|
43
|
+
this.log.debug('Failed to create shared SwitchBot client', e)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Create/shared SwitchBot client and attach to config so child devices reuse it.
|
|
47
|
+
try {
|
|
48
|
+
const client = new SwitchBotClient(this.config)
|
|
49
|
+
void client.init()
|
|
50
|
+
;(this.config as any)._client = client
|
|
51
|
+
} catch (e) {
|
|
52
|
+
this.log.debug('Failed to create shared SwitchBot client', e)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Wait for Homebridge to finish launching to create/register accessories
|
|
56
|
+
if (this.api && typeof (this.api as any).on === 'function') {
|
|
57
|
+
;(this.api as any).on('didFinishLaunching', () => {
|
|
58
|
+
void this.loadDevices()
|
|
59
|
+
})
|
|
60
|
+
} else {
|
|
61
|
+
void this.loadDevices()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async loadDevices() {
|
|
66
|
+
const devices = (this.config as any)?.devices ?? []
|
|
67
|
+
for (const raw of devices) {
|
|
68
|
+
// Normalize config keys from UI schema to internal shape
|
|
69
|
+
const d: any = {
|
|
70
|
+
id: raw.deviceId ?? raw.id,
|
|
71
|
+
name: raw.configDeviceName ?? raw.name,
|
|
72
|
+
type: raw.configDeviceType ?? raw.type ?? raw.deviceType ?? 'unknown',
|
|
73
|
+
_raw: raw,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const type: string = d.type
|
|
77
|
+
const matterSupported = !!DEVICE_MATTER_SUPPORTED[(type || '').toLowerCase()]
|
|
78
|
+
const useMatter = !!this.config.enableMatter && matterSupported && !!this.config.preferMatter
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const created = await createDevice({ id: d.id, type, name: d.name }, this.config, useMatter)
|
|
82
|
+
this.devices.push(created)
|
|
83
|
+
// Prefer Matter: try registering to the Matter child bridge first.
|
|
84
|
+
let matterRegistered = false
|
|
85
|
+
if (useMatter) {
|
|
86
|
+
this.log.info(`Attempting Matter registration for ${d.id} (${type})`)
|
|
87
|
+
// If Homebridge Matter APIs are available, register the accessory
|
|
88
|
+
try {
|
|
89
|
+
const matterApi = (this.api as any)?.matter
|
|
90
|
+
if (this.api?.isMatterAvailable?.() && this.api?.isMatterEnabled?.() && matterApi && typeof matterApi.registerPlatformAccessories === 'function') {
|
|
91
|
+
const createdDesc = created.createAccessory?.(this.api) || { id: d.id, name: d.name || type }
|
|
92
|
+
const uuid = matterApi.uuid.generate(`${d.id}`)
|
|
93
|
+
const accessory: any = {
|
|
94
|
+
uuid,
|
|
95
|
+
displayName: createdDesc.name || d.name || type,
|
|
96
|
+
context: { deviceId: d.id, type: type, _created: true },
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
await matterApi.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory])
|
|
100
|
+
this.accessories.set(uuid, accessory)
|
|
101
|
+
matterRegistered = true
|
|
102
|
+
this.log.info(`Registered Matter accessory ${d.id} (${type}) with uuid=${uuid}`)
|
|
103
|
+
} catch (e) {
|
|
104
|
+
this.log.warn('Failed to register Matter accessory with Homebridge matter API', e)
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
this.log.info('Homebridge Matter API not available or not enabled; will fallback to HAP')
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
this.log.warn('Matter registration attempt failed', e)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// If Matter wasn't registered (either not supported, API missing, or registration failed), fall back to HAP registration.
|
|
115
|
+
if (!matterRegistered && this.api && (this.api as any).hap) {
|
|
116
|
+
// Basic HAP accessory creation using homebridge API when available
|
|
117
|
+
try {
|
|
118
|
+
const hap = (this.api as any).hap
|
|
119
|
+
const uuid = hap.uuid.generate(`${d.id}`)
|
|
120
|
+
// Reuse cached accessory if available by uuid
|
|
121
|
+
let accessory: any = this.accessories.get(uuid)
|
|
122
|
+
// If not found by uuid, attempt to find by stored deviceId in accessory.context
|
|
123
|
+
if (!accessory) {
|
|
124
|
+
for (const [k, a] of Array.from(this.accessories.entries())) {
|
|
125
|
+
try {
|
|
126
|
+
if (a && a.context && a.context.deviceId === d.id) {
|
|
127
|
+
accessory = a
|
|
128
|
+
break
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
// ignore
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!accessory) {
|
|
137
|
+
accessory = new (this.api as any).platformAccessory(d.name || type, uuid)
|
|
138
|
+
// Store device metadata on accessory.context for persistence across restarts
|
|
139
|
+
try {
|
|
140
|
+
accessory.context = accessory.context || {}
|
|
141
|
+
accessory.context.deviceId = d.id
|
|
142
|
+
accessory.context.type = type
|
|
143
|
+
} catch (e) {
|
|
144
|
+
// ignore context failures
|
|
145
|
+
}
|
|
146
|
+
// Register new accessory with Homebridge so it's cached
|
|
147
|
+
try {
|
|
148
|
+
;(this.api as any).registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory])
|
|
149
|
+
} catch (e) {
|
|
150
|
+
// older API variations may require different registration; ignore if unavailable
|
|
151
|
+
}
|
|
152
|
+
this.accessories.set(uuid, accessory)
|
|
153
|
+
} else {
|
|
154
|
+
// ensure context includes deviceId (in case restored accessory lacked it)
|
|
155
|
+
try {
|
|
156
|
+
accessory.context = accessory.context || {}
|
|
157
|
+
accessory.context.deviceId = accessory.context.deviceId || d.id
|
|
158
|
+
accessory.context.type = accessory.context.type || type
|
|
159
|
+
} catch (e) {
|
|
160
|
+
// ignore
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Add basic service descriptor from device
|
|
164
|
+
const accDesc = created.createAccessory?.(this.api)
|
|
165
|
+
if (accDesc && accDesc.services) {
|
|
166
|
+
for (const s of accDesc.services) {
|
|
167
|
+
const Service = hap.Service[s.type] || hap.Service[s.type]
|
|
168
|
+
if (!Service) continue
|
|
169
|
+
const service = accessory.getService(Service) || accessory.addService(Service)
|
|
170
|
+
for (const [charName, getterSetterRaw] of Object.entries(s.characteristics || {})) {
|
|
171
|
+
const getterSetter: any = getterSetterRaw
|
|
172
|
+
const Characteristic = (hap.Characteristic as any)[charName]
|
|
173
|
+
if (!Characteristic) continue
|
|
174
|
+
// Apply characteristic props if provided (min/max/step)
|
|
175
|
+
if (getterSetter && getterSetter.props) {
|
|
176
|
+
try {
|
|
177
|
+
service.getCharacteristic(Characteristic).setProps(getterSetter.props)
|
|
178
|
+
} catch (e) {
|
|
179
|
+
// ignore setProps failures on older HAP implementations
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Wire simple get/set handlers if provided
|
|
184
|
+
if (getterSetter && typeof getterSetter.get === 'function') {
|
|
185
|
+
service.getCharacteristic(Characteristic).onGet(getterSetter.get)
|
|
186
|
+
}
|
|
187
|
+
if (getterSetter && typeof getterSetter.set === 'function') {
|
|
188
|
+
service.getCharacteristic(Characteristic).onSet(getterSetter.set)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this.log.info(`Created/updated HAP accessory ${d.id} (${type})`)
|
|
194
|
+
} catch (e) {
|
|
195
|
+
this.log.warn('HAP accessory creation failed', e)
|
|
196
|
+
}
|
|
197
|
+
} else if (!matterRegistered) {
|
|
198
|
+
this.log.info(`Created HAP descriptor for ${d.id} (${type}) (API not available to register)`)
|
|
199
|
+
}
|
|
200
|
+
} catch (e) {
|
|
201
|
+
this.log.error(`Failed to create device ${d.id}:`, e as any)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Example lifecycle method called by Homebridge
|
|
207
|
+
async configureAccessory(accessory: any) {
|
|
208
|
+
// Homebridge calls this for restored cached accessories — keep a reference.
|
|
209
|
+
try {
|
|
210
|
+
const uuid = accessory.UUID || accessory.UUID
|
|
211
|
+
this.accessories.set(uuid, accessory)
|
|
212
|
+
this.log.info(`Restored cached accessory ${accessory.displayName || uuid}`)
|
|
213
|
+
} catch (e) {
|
|
214
|
+
this.log.warn('configureAccessory failed to restore accessory', e)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Called by Homebridge when a cached Matter accessory is restored
|
|
219
|
+
configureMatterAccessory?(accessory: any) {
|
|
220
|
+
try {
|
|
221
|
+
const uuid = accessory.uuid || accessory.UUID || accessory.uuid
|
|
222
|
+
this.accessories.set(uuid, accessory)
|
|
223
|
+
this.log.info(`Restored cached Matter accessory ${accessory.displayName || uuid}`)
|
|
224
|
+
} catch (e) {
|
|
225
|
+
this.log.warn('configureMatterAccessory failed to restore accessory', e)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Matter platform implementation (placeholder)
|
|
231
|
+
export class SwitchBotMatterPlatform {
|
|
232
|
+
api: API | undefined
|
|
233
|
+
log: Logger
|
|
234
|
+
config: SwitchBotPluginConfig
|
|
235
|
+
devices: any[] = []
|
|
236
|
+
accessories: Map<string, any>
|
|
237
|
+
|
|
238
|
+
constructor(log: Logger, config: PlatformConfig, api?: API) {
|
|
239
|
+
this.log = log
|
|
240
|
+
this.config = (config as any) ?? {}
|
|
241
|
+
this.api = api
|
|
242
|
+
this.accessories = new Map()
|
|
243
|
+
this.log.info('SwitchBot Matter platform initialized')
|
|
244
|
+
|
|
245
|
+
if (this.api && typeof (this.api as any).on === 'function') {
|
|
246
|
+
;(this.api as any).on('didFinishLaunching', () => {
|
|
247
|
+
;(async () => {
|
|
248
|
+
// After launch, perform discovery (if any) and register Matter accessories
|
|
249
|
+
try {
|
|
250
|
+
await this.loadDevices()
|
|
251
|
+
if ((this.api as any).isMatterAvailable?.() && (this.api as any).isMatterEnabled?.() && (this.api as any).matter && typeof (this.api as any).matter.registerPlatformAccessories === 'function') {
|
|
252
|
+
try {
|
|
253
|
+
await (this as any).registerMatterAccessories?.()
|
|
254
|
+
} catch (e) {
|
|
255
|
+
this.log.warn('registerMatterAccessories failed', e)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} catch (e) {
|
|
259
|
+
this.log.warn('Error during Matter platform startup', e)
|
|
260
|
+
}
|
|
261
|
+
})()
|
|
262
|
+
})
|
|
263
|
+
} else {
|
|
264
|
+
void this.loadDevices()
|
|
265
|
+
}
|
|
266
|
+
// Create/shared SwitchBot client and attach to config so child devices reuse it.
|
|
267
|
+
try {
|
|
268
|
+
const client = new SwitchBotClient(this.config)
|
|
269
|
+
void client.init()
|
|
270
|
+
;(this.config as any)._client = client
|
|
271
|
+
} catch (e) {
|
|
272
|
+
this.log.debug('Failed to create shared SwitchBot client', e)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async loadDevices() {
|
|
277
|
+
const devices = (this.config as any)?.devices ?? []
|
|
278
|
+
for (const raw of devices) {
|
|
279
|
+
// Normalize config keys produced by the UI schema
|
|
280
|
+
const d: any = {
|
|
281
|
+
id: raw.deviceId ?? raw.id,
|
|
282
|
+
name: raw.configDeviceName ?? raw.name,
|
|
283
|
+
type: raw.configDeviceType ?? raw.type ?? raw.deviceType ?? 'unknown',
|
|
284
|
+
_raw: raw,
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const type: string = d.type
|
|
288
|
+
const matterSupported = !!DEVICE_MATTER_SUPPORTED[(type || '').toLowerCase()]
|
|
289
|
+
const useMatter = !!this.config.enableMatter && matterSupported
|
|
290
|
+
try {
|
|
291
|
+
const created = await createDevice({ id: d.id, type, name: d.name }, this.config, useMatter)
|
|
292
|
+
this.devices.push(created)
|
|
293
|
+
if (useMatter) {
|
|
294
|
+
this.log.info(`Prepared Matter accessory for ${d.id} (${type})`)
|
|
295
|
+
} else {
|
|
296
|
+
this.log.info(`Skipping Matter for ${d.id} (${type}) - not supported`)
|
|
297
|
+
}
|
|
298
|
+
} catch (e) {
|
|
299
|
+
this.log.error(`Failed to create Matter device ${d.id}:`, e as any)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async configureAccessory(accessory: any) {
|
|
305
|
+
try {
|
|
306
|
+
const uuid = accessory.UUID || accessory.UUID
|
|
307
|
+
this.accessories.set(uuid, accessory)
|
|
308
|
+
this.log.info(`Restored cached Matter accessory ${accessory.displayName || uuid}`)
|
|
309
|
+
} catch (e) {
|
|
310
|
+
this.log.warn('configureAccessory failed to restore Matter accessory', e)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Homebridge calls this when restoring cached Matter accessories
|
|
315
|
+
configureMatterAccessory(accessory: any) {
|
|
316
|
+
try {
|
|
317
|
+
const uuid = accessory.uuid || accessory.UUID || accessory.uuid
|
|
318
|
+
this.accessories.set(uuid, accessory)
|
|
319
|
+
this.log.info(`Restored cached Matter accessory ${accessory.displayName || uuid}`)
|
|
320
|
+
} catch (e) {
|
|
321
|
+
this.log.warn('configureMatterAccessory failed to restore Matter accessory', e)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Register serialized Matter accessories via Homebridge Matter API
|
|
326
|
+
async registerMatterAccessories() {
|
|
327
|
+
if (!this.api) return
|
|
328
|
+
const matterApi = (this.api as any).matter
|
|
329
|
+
if (!matterApi || typeof matterApi.registerPlatformAccessories !== 'function') {
|
|
330
|
+
this.log.info('Homebridge Matter API not available; skipping Matter accessory registration')
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const devices = (this.config as any)?.devices ?? []
|
|
335
|
+
const accessoriesToRegister: any[] = []
|
|
336
|
+
|
|
337
|
+
for (const d of devices) {
|
|
338
|
+
const type: string = d.type || d.deviceType || 'unknown'
|
|
339
|
+
const matterSupported = !!DEVICE_MATTER_SUPPORTED[(type || '').toLowerCase()]
|
|
340
|
+
const useMatter = !!this.config.enableMatter && matterSupported
|
|
341
|
+
if (!useMatter) continue
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
const created = await createDevice({ id: d.id, type, name: d.name }, this.config, true)
|
|
345
|
+
const createdDesc = created.createAccessory?.(this.api) || { id: d.id, name: d.name || type }
|
|
346
|
+
const uuid = matterApi.uuid.generate(`${d.id}`)
|
|
347
|
+
// Try to find existing restored accessory by deviceId
|
|
348
|
+
let existing: any | undefined
|
|
349
|
+
for (const [k, a] of Array.from(this.accessories.entries())) {
|
|
350
|
+
try {
|
|
351
|
+
if (a && a.context && a.context.deviceId === d.id) {
|
|
352
|
+
existing = a
|
|
353
|
+
break
|
|
354
|
+
}
|
|
355
|
+
} catch (e) {
|
|
356
|
+
// ignore
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (existing) {
|
|
361
|
+
// Ensure context and displayName are up to date
|
|
362
|
+
existing.context = existing.context || {}
|
|
363
|
+
existing.context.deviceId = existing.context.deviceId || d.id
|
|
364
|
+
existing.context.type = existing.context.type || type
|
|
365
|
+
existing.displayName = createdDesc.name || d.name || type
|
|
366
|
+
accessoriesToRegister.push(existing)
|
|
367
|
+
this.accessories.set(existing.uuid || uuid, existing)
|
|
368
|
+
} else {
|
|
369
|
+
const serialized: any = {
|
|
370
|
+
uuid,
|
|
371
|
+
displayName: createdDesc.name || d.name || type,
|
|
372
|
+
context: { deviceId: d.id, type, created: true },
|
|
373
|
+
}
|
|
374
|
+
accessoriesToRegister.push(serialized)
|
|
375
|
+
this.accessories.set(uuid, serialized)
|
|
376
|
+
}
|
|
377
|
+
} catch (e) {
|
|
378
|
+
this.log.warn(`Failed to prepare Matter accessory for ${d.id} (${type})`, e)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (accessoriesToRegister.length > 0) {
|
|
383
|
+
try {
|
|
384
|
+
await matterApi.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, accessoriesToRegister)
|
|
385
|
+
this.log.info(`Registered ${accessoriesToRegister.length} Matter accessory(ies) with Homebridge`)
|
|
386
|
+
} catch (e) {
|
|
387
|
+
this.log.warn('Failed to register Matter accessories', e)
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
this.log.info('No Matter accessories to register')
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export default SwitchBotHAPPlatform
|
package/src/settings.ts
CHANGED
|
@@ -1,283 +1,18 @@
|
|
|
1
|
-
/* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
-
*
|
|
3
|
-
* settings.ts: @switchbot/homebridge-switchbot platform class.
|
|
4
|
-
*/
|
|
5
|
-
import type { IClientOptions } from 'async-mqtt'
|
|
6
|
-
import type { PlatformConfig } from 'homebridge'
|
|
7
|
-
/*
|
|
8
|
-
* For Testing Locally:
|
|
9
|
-
* import type { device, irdevice, SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
|
-
*/
|
|
11
|
-
import type { device, irdevice, SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName, SwitchBotModel } from 'node-switchbot'
|
|
12
|
-
/**
|
|
13
|
-
* This is the name of the platform that users will use to register the plugin in the Homebridge config.json
|
|
14
|
-
*/
|
|
15
|
-
export const PLATFORM_NAME = 'SwitchBot'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This must match the name of your plugin as defined the package.json
|
|
19
|
-
*/
|
|
20
1
|
export const PLUGIN_NAME = '@switchbot/homebridge-switchbot'
|
|
2
|
+
export const PLATFORM_NAME = 'SwitchBot'
|
|
21
3
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
secret?: string
|
|
30
|
-
notice?: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface options {
|
|
34
|
-
devices?: devicesConfig[]
|
|
35
|
-
deviceConfig?: { [deviceType: string]: devicesConfig }
|
|
36
|
-
irdevices?: irDevicesConfig[]
|
|
37
|
-
irdeviceConfig?: { [remoteType: string]: irDevicesConfig }
|
|
38
|
-
allowInvalidCharacters?: boolean
|
|
39
|
-
mqttURL?: string
|
|
40
|
-
mqttOptions?: IClientOptions
|
|
41
|
-
mqttPubOptions?: IClientOptions
|
|
42
|
-
BLE?: boolean
|
|
43
|
-
discoverBLE?: boolean
|
|
44
|
-
disableLogsforBLE?: boolean
|
|
45
|
-
disableLogsforOpenAPI?: boolean
|
|
46
|
-
hostname?: string
|
|
47
|
-
webhookURL?: string
|
|
48
|
-
maxRetries?: number
|
|
49
|
-
delayBetweenRetries?: number
|
|
50
|
-
refreshRate?: number
|
|
51
|
-
updateRate?: number
|
|
52
|
-
pushRate?: number
|
|
53
|
-
logging?: string
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type devicesConfig = botConfig | relaySwitch1Config | relaySwitch1PMConfig | meterConfig | meterProConfig | indoorOutdoorSensorConfig | humidifierConfig | curtainConfig | blindTiltConfig | contactConfig | motionConfig | waterDetectorConfig | plugConfig | colorBulbConfig | stripLightConfig | ceilingLightConfig | lockConfig | hubConfig
|
|
57
|
-
|
|
58
|
-
export interface BaseDeviceConfig extends device {
|
|
59
|
-
bleMac?: string
|
|
60
|
-
model: SwitchBotModel
|
|
61
|
-
bleModel: SwitchBotBLEModel
|
|
62
|
-
bleModelName: SwitchBotBLEModelName
|
|
63
|
-
bleModelFriednlyName: SwitchBotBLEModelFriendlyName
|
|
64
|
-
configDeviceType: string
|
|
65
|
-
configDeviceName?: string
|
|
66
|
-
deviceId: string
|
|
67
|
-
external?: boolean
|
|
68
|
-
refreshRate?: number
|
|
69
|
-
updateRate?: number
|
|
70
|
-
pushRate?: number
|
|
71
|
-
firmware?: string
|
|
72
|
-
logging?: string
|
|
73
|
-
connectionType?: string
|
|
74
|
-
customBLEaddress?: string
|
|
75
|
-
scanDuration?: number
|
|
76
|
-
hide_device?: boolean
|
|
77
|
-
offline?: boolean
|
|
78
|
-
maxRetry?: number
|
|
79
|
-
maxRetries?: number
|
|
80
|
-
delayBetweenRetries?: number
|
|
81
|
-
disableCaching?: boolean
|
|
82
|
-
disablePlatformBLE?: boolean
|
|
83
|
-
mqttURL?: string
|
|
84
|
-
mqttOptions?: IClientOptions
|
|
85
|
-
mqttPubOptions?: IClientOptions
|
|
86
|
-
history?: boolean
|
|
87
|
-
webhook?: boolean
|
|
4
|
+
export interface SwitchBotPluginConfig {
|
|
5
|
+
openApiToken?: string
|
|
6
|
+
openApiSecret?: string
|
|
7
|
+
preferMatter?: boolean
|
|
8
|
+
enableMatter?: boolean
|
|
9
|
+
// other plugin-specific configuration
|
|
10
|
+
[key: string]: any
|
|
88
11
|
}
|
|
89
12
|
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
type: string
|
|
94
|
-
doublePress?: number
|
|
95
|
-
pushRatePress?: number
|
|
96
|
-
allowPush?: boolean
|
|
97
|
-
multiPress?: boolean
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export interface relaySwitch1Config extends BaseDeviceConfig {
|
|
101
|
-
configDeviceType: 'Relay Switch 1'
|
|
102
|
-
type: string
|
|
103
|
-
allowPush?: boolean
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export interface relaySwitch1PMConfig extends BaseDeviceConfig {
|
|
107
|
-
configDeviceType: 'Relay Switch 1PM'
|
|
108
|
-
type: string
|
|
109
|
-
allowPush?: boolean
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export interface meterConfig extends BaseDeviceConfig {
|
|
113
|
-
configDeviceType: 'Meter' | 'MeterPlus'
|
|
114
|
-
hide_temperature?: boolean
|
|
115
|
-
convertUnitTo?: string
|
|
116
|
-
hide_humidity?: boolean
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export interface meterProConfig extends BaseDeviceConfig {
|
|
120
|
-
configDeviceType: 'Meter Pro' | 'MeterPro(CO2)'
|
|
121
|
-
hide_temperature?: boolean
|
|
122
|
-
convertUnitTo?: string
|
|
123
|
-
hide_humidity?: boolean
|
|
124
|
-
hide_co2?: boolean
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export interface indoorOutdoorSensorConfig extends BaseDeviceConfig {
|
|
128
|
-
configDeviceType: 'WoIOSensor'
|
|
129
|
-
hide_temperature?: boolean
|
|
130
|
-
convertUnitTo?: string
|
|
131
|
-
hide_humidity?: boolean
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export interface humidifierConfig extends BaseDeviceConfig {
|
|
135
|
-
configDeviceType: 'Humidifier' | 'Humidifier2'
|
|
136
|
-
hide_temperature?: boolean
|
|
137
|
-
convertUnitTo?: string
|
|
138
|
-
set_minStep?: number
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export interface curtainConfig extends BaseDeviceConfig {
|
|
142
|
-
configDeviceType: 'Curtain' | 'Curtain3' | 'WoRollerShade' | 'Roller Shade'
|
|
143
|
-
disable_group?: boolean
|
|
144
|
-
hide_lightsensor?: boolean
|
|
145
|
-
set_minLux?: number
|
|
146
|
-
set_maxLux?: number
|
|
147
|
-
set_max?: number
|
|
148
|
-
set_min?: number
|
|
149
|
-
set_minStep?: number
|
|
150
|
-
setCloseMode?: string
|
|
151
|
-
setOpenMode?: string
|
|
152
|
-
silentModeSwitch?: boolean
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export interface blindTiltConfig extends BaseDeviceConfig {
|
|
156
|
-
configDeviceType: 'Blind Tilt'
|
|
157
|
-
disable_group?: boolean
|
|
158
|
-
mapping?: string
|
|
159
|
-
hide_lightsensor?: boolean
|
|
160
|
-
set_minLux?: number
|
|
161
|
-
set_maxLux?: number
|
|
162
|
-
set_max?: number
|
|
163
|
-
set_min?: number
|
|
164
|
-
set_minStep?: number
|
|
165
|
-
setCloseMode?: string
|
|
166
|
-
setOpenMode?: string
|
|
167
|
-
silentModeSwitch?: boolean
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export interface contactConfig extends BaseDeviceConfig {
|
|
171
|
-
configDeviceType: 'Contact Sensor'
|
|
172
|
-
hide_lightsensor?: boolean
|
|
173
|
-
set_minLux?: number
|
|
174
|
-
set_maxLux?: number
|
|
175
|
-
hide_motionsensor?: boolean
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
export interface motionConfig extends BaseDeviceConfig {
|
|
179
|
-
configDeviceType: 'Motion Sensor'
|
|
180
|
-
hide_lightsensor?: boolean
|
|
181
|
-
set_minLux?: number
|
|
182
|
-
set_maxLux?: number
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export interface waterDetectorConfig extends BaseDeviceConfig {
|
|
186
|
-
configDeviceType: 'Water Detector'
|
|
187
|
-
hide_leak?: boolean
|
|
188
|
-
dry?: boolean
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export interface plugConfig extends BaseDeviceConfig {
|
|
192
|
-
configDeviceType: 'Plug' | 'Plug Mini (US)' | 'Plug Mini (JP)'
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export interface colorBulbConfig extends BaseDeviceConfig {
|
|
196
|
-
configDeviceType: 'Color Bulb'
|
|
197
|
-
set_minStep?: number
|
|
198
|
-
adaptiveLightingShift?: number
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
export interface stripLightConfig extends BaseDeviceConfig {
|
|
202
|
-
configDeviceType: 'Strip Light'
|
|
203
|
-
set_minStep?: number
|
|
204
|
-
adaptiveLightingShift?: number
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
export interface ceilingLightConfig extends BaseDeviceConfig {
|
|
208
|
-
configDeviceType: 'Ceiling Light' | 'Ceiling Light Pro'
|
|
209
|
-
set_minStep?: number
|
|
210
|
-
adaptiveLightingShift?: number
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export interface lockConfig extends BaseDeviceConfig {
|
|
214
|
-
configDeviceType: 'Smart Lock' | 'Smart Lock Pro'
|
|
215
|
-
hide_contactsensor?: boolean
|
|
216
|
-
activate_latchbutton?: boolean
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
export interface hubConfig extends BaseDeviceConfig {
|
|
220
|
-
configDeviceType: 'Hub 2'
|
|
221
|
-
hide_temperature?: boolean
|
|
222
|
-
convertUnitTo?: string
|
|
223
|
-
hide_humidity?: boolean
|
|
224
|
-
hide_lightsensor?: boolean
|
|
225
|
-
set_minLux?: number
|
|
226
|
-
set_maxLux?: number
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export type irDevicesConfig = irFanConfig | irLightConfig | irAirConfig | irOtherConfig
|
|
230
|
-
|
|
231
|
-
export interface irBaseDeviceConfig extends irdevice {
|
|
232
|
-
configDeviceName?: string
|
|
233
|
-
configRemoteType?: string
|
|
234
|
-
connectionType?: string
|
|
235
|
-
hide_device?: boolean
|
|
236
|
-
external?: boolean
|
|
237
|
-
refreshRate?: number
|
|
238
|
-
updateRate?: number
|
|
239
|
-
pushRate?: number
|
|
240
|
-
maxRetries?: number
|
|
241
|
-
delayBetweenRetries?: number
|
|
242
|
-
firmware?: string
|
|
243
|
-
deviceId: string
|
|
244
|
-
logging?: string
|
|
245
|
-
customOn?: string
|
|
246
|
-
customOff?: string
|
|
247
|
-
customize?: boolean
|
|
248
|
-
commandType?: string
|
|
249
|
-
disablePushOn?: boolean
|
|
250
|
-
disablePushOff?: boolean
|
|
251
|
-
disablePushDetail?: boolean
|
|
13
|
+
export const DEFAULT_CONFIG: Partial<SwitchBotPluginConfig> = {
|
|
14
|
+
preferMatter: true,
|
|
15
|
+
enableMatter: true,
|
|
252
16
|
}
|
|
253
17
|
|
|
254
|
-
export
|
|
255
|
-
configRemoteType?: 'Fan' | 'DIY Fan'
|
|
256
|
-
swing_mode?: boolean
|
|
257
|
-
rotation_speed?: boolean
|
|
258
|
-
set_minStep?: number
|
|
259
|
-
set_max?: number
|
|
260
|
-
set_min?: number
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
export interface irLightConfig extends irBaseDeviceConfig {
|
|
264
|
-
configRemoteType?: 'Light' | 'DIY Light'
|
|
265
|
-
stateless?: boolean
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export interface irAirConfig extends irBaseDeviceConfig {
|
|
269
|
-
configRemoteType?: 'Air Conditioner' | 'DIY Air Conditioner'
|
|
270
|
-
hide_automode?: boolean
|
|
271
|
-
set_max_heat?: number
|
|
272
|
-
set_min_heat?: number
|
|
273
|
-
set_max_cool?: number
|
|
274
|
-
set_min_cool?: number
|
|
275
|
-
meterType?: string
|
|
276
|
-
meterId?: string
|
|
277
|
-
meterUuid?: string
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
export interface irOtherConfig extends irBaseDeviceConfig {
|
|
281
|
-
configRemoteType?: 'Others'
|
|
282
|
-
type?: string
|
|
283
|
-
};
|
|
18
|
+
export type DeviceType = string
|