@switchbot/homebridge-switchbot 5.0.0-beta.9 → 5.0.0-beta.90
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 +32 -0
- package/.github/workflows/manual-e2e.yml +115 -0
- package/.github/workflows/release.yml +0 -4
- 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 +91 -14787
- 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 +630 -246
- 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 +367 -36
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -32
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +35 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +514 -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 +194 -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/eslint.config.js +2 -8
- package/package.json +21 -28
- 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 +630 -246
- package/src/homebridge-ui/server.ts +434 -41
- package/src/index.ts +4 -33
- package/src/platform.ts +515 -0
- package/src/settings.ts +12 -277
- package/src/switchbotClient.ts +203 -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 -120
- package/dist/platform-matter.d.ts.map +0 -1
- package/dist/platform-matter.js +0 -966
- 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 -1092
- package/src/verifyconfig.test.ts +0 -197
|
@@ -1,48 +1,441 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { HomebridgePluginUiServer, RequestError } from '@homebridge/plugin-ui-utils'
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
|
|
5
|
+
const server = new HomebridgePluginUiServer()
|
|
6
|
+
|
|
7
|
+
function getDevicesRef(platform: any): any[] {
|
|
8
|
+
if (!platform || typeof platform !== 'object') {
|
|
9
|
+
return []
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Array.isArray(platform.devices)) {
|
|
13
|
+
return platform.devices
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
platform.devices = []
|
|
17
|
+
return platform.devices
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getDeviceArrays(platform: any): any[][] {
|
|
21
|
+
const rootDevices = getDevicesRef(platform)
|
|
22
|
+
return [rootDevices]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getAllDevices(platform: any): any[] {
|
|
26
|
+
const all = getDevicesRef(platform)
|
|
27
|
+
const seen = new Set<string>()
|
|
28
|
+
|
|
29
|
+
return all.filter((d: any) => {
|
|
30
|
+
const id = String(d?.deviceId ?? d?.id ?? '').trim().toLowerCase()
|
|
31
|
+
if (!id || seen.has(id)) {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
seen.add(id)
|
|
35
|
+
return true
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getCredential(platform: any, key: 'openApiToken' | 'openApiSecret') {
|
|
40
|
+
return platform?.[key]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function setCredential(platform: any, key: 'openApiToken' | 'openApiSecret', value: string) {
|
|
44
|
+
if (!platform || typeof platform !== 'object') {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
platform[key] = value
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Helper function to find the SwitchBot platform config
|
|
52
|
+
async function getSwitchBotPlatformConfig() {
|
|
53
|
+
const cfgPath = server.homebridgeConfigPath
|
|
54
|
+
if (!cfgPath) {
|
|
55
|
+
throw new Error('HOMEBRIDGE_CONFIG_PATH not set')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const raw = await fs.readFile(cfgPath, 'utf8')
|
|
59
|
+
const cfg = JSON.parse(raw)
|
|
60
|
+
const platforms = Array.isArray(cfg.platforms) ? cfg.platforms : []
|
|
61
|
+
|
|
62
|
+
const candidates = platforms.filter((p: any) => {
|
|
63
|
+
const platformName = p.platform || p.name || ''
|
|
64
|
+
return !!platformName && /switchbot/i.test(String(platformName))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const platform = candidates.find((p: any) => String(p.platform || '').toLowerCase() === 'switchbot')
|
|
68
|
+
?? candidates[0]
|
|
69
|
+
|
|
70
|
+
if (platform) {
|
|
71
|
+
return { config: cfg, platform, cfgPath }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error('SwitchBot platform not found in config')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
server.onRequest('/devices', async () => {
|
|
78
|
+
try {
|
|
79
|
+
const cfgPath = server.homebridgeConfigPath
|
|
80
|
+
if (!cfgPath) {
|
|
81
|
+
throw new Error('HOMEBRIDGE_CONFIG_PATH not set')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const raw = await fs.readFile(cfgPath, 'utf8')
|
|
85
|
+
const cfg = JSON.parse(raw)
|
|
86
|
+
const found: Array<{ id: string, name?: string, type?: string, connectionPreference?: string, room?: string }> = []
|
|
87
|
+
|
|
88
|
+
const platforms = Array.isArray(cfg.platforms) ? cfg.platforms : []
|
|
89
|
+
for (const p of platforms) {
|
|
13
90
|
try {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
91
|
+
const platformName = p.platform || p.name || ''
|
|
92
|
+
// Match known SwitchBot platform identifiers
|
|
93
|
+
if (!platformName || !/switchbot/i.test(String(platformName))) {
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const devices = getAllDevices(p)
|
|
98
|
+
for (const d of devices) {
|
|
99
|
+
const id = d.deviceId ?? d.id
|
|
100
|
+
if (!id) {
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
found.push({
|
|
105
|
+
id,
|
|
106
|
+
name: d.configDeviceName ?? d.name ?? d.deviceName,
|
|
107
|
+
type: d.configDeviceType ?? d.type ?? d.deviceType,
|
|
108
|
+
connectionPreference: d.connectionPreference ?? d.connection ?? 'auto',
|
|
109
|
+
room: d.room || d.location || undefined,
|
|
31
110
|
})
|
|
32
111
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} catch {
|
|
36
|
-
// Just return an empty accessory list in case of any errors
|
|
37
|
-
return []
|
|
112
|
+
} catch (e) {
|
|
113
|
+
// ignore malformed platform entries
|
|
38
114
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log('[SwitchBot UI] GET /devices - Found', found.length, 'devices in', cfgPath)
|
|
118
|
+
return { success: true, data: found }
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error('[SwitchBot UI] Error in /devices:', e)
|
|
121
|
+
throw new RequestError('Failed to read Homebridge config', e)
|
|
41
122
|
}
|
|
42
|
-
}
|
|
123
|
+
})
|
|
43
124
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
125
|
+
server.onRequest('/discover', async () => {
|
|
126
|
+
try {
|
|
127
|
+
const { platform } = await getSwitchBotPlatformConfig()
|
|
128
|
+
|
|
129
|
+
console.log('[SwitchBot UI] GET /discover - Platform config:', Object.keys(platform))
|
|
130
|
+
|
|
131
|
+
const token = getCredential(platform, 'openApiToken') || platform.token
|
|
132
|
+
if (!token) {
|
|
133
|
+
console.error('[SwitchBot UI] No API token found in platform config')
|
|
134
|
+
throw new Error('OpenAPI token not configured. Please save your credentials first.')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
console.log('[SwitchBot UI] GET /discover - Fetching devices from SwitchBot API')
|
|
138
|
+
|
|
139
|
+
const url = 'https://api.switch-bot.com/v1.0/devices'
|
|
140
|
+
const opts = {
|
|
141
|
+
headers: {
|
|
142
|
+
Authorization: token,
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('[SwitchBot UI] GET /discover - Making request to', url)
|
|
147
|
+
const resp = await fetch(url, opts)
|
|
148
|
+
|
|
149
|
+
console.log('[SwitchBot UI] GET /discover - API response status:', resp.status)
|
|
150
|
+
|
|
151
|
+
if (!resp.ok) {
|
|
152
|
+
const errorText = await resp.text()
|
|
153
|
+
console.error('[SwitchBot UI] API error response:', errorText)
|
|
154
|
+
throw new Error(`SwitchBot API returned ${resp.status}: ${errorText}`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const data = await resp.json()
|
|
158
|
+
console.log('[SwitchBot UI] GET /discover - Full API response:', JSON.stringify(data, null, 2))
|
|
159
|
+
|
|
160
|
+
// Handle different response formats
|
|
161
|
+
let devices: any[] = []
|
|
162
|
+
if (Array.isArray(data)) {
|
|
163
|
+
devices = data
|
|
164
|
+
} else if (Array.isArray(data.body)) {
|
|
165
|
+
devices = data.body
|
|
166
|
+
} else if (Array.isArray(data.devices)) {
|
|
167
|
+
devices = data.devices
|
|
168
|
+
} else if (data.body && typeof data.body === 'object') {
|
|
169
|
+
// Sometimes the response has devices listed within body
|
|
170
|
+
const bodyKeys = Object.keys(data.body)
|
|
171
|
+
if (bodyKeys.includes('deviceList')) {
|
|
172
|
+
devices = Array.isArray(data.body.deviceList) ? data.body.deviceList : []
|
|
173
|
+
} else if (bodyKeys.includes('devices')) {
|
|
174
|
+
devices = Array.isArray(data.body.devices) ? data.body.devices : []
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!Array.isArray(devices)) {
|
|
179
|
+
console.warn('[SwitchBot UI] Could not find devices array in API response. Response keys:', Object.keys(data), 'Body keys:', data.body ? Object.keys(data.body) : 'N/A')
|
|
180
|
+
devices = []
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const discovered = devices.map((d: any) => ({
|
|
184
|
+
id: d.deviceId || d.id,
|
|
185
|
+
name: d.deviceName || d.name,
|
|
186
|
+
type: d.deviceType || d.type || 'unknown',
|
|
187
|
+
model: d.deviceModel || d.model,
|
|
188
|
+
enabled: d.enableCloudService !== false,
|
|
189
|
+
}))
|
|
190
|
+
|
|
191
|
+
console.log('[SwitchBot UI] GET /discover - Found', discovered.length, 'devices from API')
|
|
192
|
+
return { success: true, data: discovered }
|
|
193
|
+
} catch (e) {
|
|
194
|
+
console.error('[SwitchBot UI] Error in /discover:', e instanceof Error ? e.message : String(e))
|
|
195
|
+
throw new RequestError(`Failed to discover devices: ${e instanceof Error ? e.message : String(e)}`, e)
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
server.onRequest('/add-device', async (body: any) => {
|
|
200
|
+
try {
|
|
201
|
+
const { deviceId, name, type } = body
|
|
202
|
+
|
|
203
|
+
if (!deviceId) {
|
|
204
|
+
throw new Error('Device ID is required')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const { config, platform, cfgPath } = await getSwitchBotPlatformConfig()
|
|
208
|
+
|
|
209
|
+
console.log('[SwitchBot UI] POST /add-device - Adding device:', deviceId)
|
|
210
|
+
const deviceArrays = getDeviceArrays(platform)
|
|
211
|
+
const allDevices = getAllDevices(platform)
|
|
212
|
+
|
|
213
|
+
// Check if already exists
|
|
214
|
+
const normalizedDeviceId = String(deviceId).trim().toLowerCase()
|
|
215
|
+
const exists = allDevices.some((d: any) => String(d.deviceId ?? d.id ?? '').trim().toLowerCase() === normalizedDeviceId)
|
|
216
|
+
if (exists) {
|
|
217
|
+
return {
|
|
218
|
+
success: true,
|
|
219
|
+
data: {
|
|
220
|
+
message: 'Device already in config',
|
|
221
|
+
alreadyExists: true,
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Add device
|
|
227
|
+
for (const ref of deviceArrays) {
|
|
228
|
+
const refHasDevice = ref.some((d: any) => String(d.deviceId ?? d.id ?? '').trim().toLowerCase() === normalizedDeviceId)
|
|
229
|
+
if (!refHasDevice) {
|
|
230
|
+
ref.push({
|
|
231
|
+
deviceId,
|
|
232
|
+
configDeviceName: name,
|
|
233
|
+
configDeviceType: type,
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Save config
|
|
239
|
+
await fs.writeFile(cfgPath, JSON.stringify(config, null, 2), 'utf8')
|
|
240
|
+
|
|
241
|
+
console.log('[SwitchBot UI] Device added successfully:', deviceId, 'saved to', cfgPath)
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
success: true,
|
|
245
|
+
data: {
|
|
246
|
+
message: `Device "${name}" added successfully`,
|
|
247
|
+
alreadyExists: false,
|
|
248
|
+
},
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
console.error('[SwitchBot UI] Error in /add-device:', e)
|
|
252
|
+
throw new RequestError('Failed to add device', e)
|
|
253
|
+
}
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
server.onRequest('/update-device', async (body: any) => {
|
|
257
|
+
try {
|
|
258
|
+
const { deviceId, configDeviceName, configDeviceType, connectionPreference, room } = body
|
|
259
|
+
|
|
260
|
+
console.log('[SwitchBot UI] POST /update-device - Full request body:', JSON.stringify(body, null, 2))
|
|
261
|
+
|
|
262
|
+
if (!deviceId) {
|
|
263
|
+
throw new Error('Device ID is required')
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const { config, platform, cfgPath } = await getSwitchBotPlatformConfig()
|
|
267
|
+
|
|
268
|
+
console.log('[SwitchBot UI] POST /update-device - Updating device:', deviceId)
|
|
269
|
+
console.log('[SwitchBot UI] Parameters - name:', configDeviceName, 'type:', configDeviceType, 'pref:', connectionPreference, 'room:', room)
|
|
270
|
+
|
|
271
|
+
const deviceArrays = getDeviceArrays(platform)
|
|
272
|
+
const devices = getAllDevices(platform)
|
|
273
|
+
const normalizedDeviceId = String(deviceId).trim().toLowerCase()
|
|
274
|
+
const device = devices.find((d: any) => String(d.deviceId ?? d.id ?? '').trim().toLowerCase() === normalizedDeviceId)
|
|
275
|
+
if (!device) {
|
|
276
|
+
console.error('[SwitchBot UI] Device not found. Available devices:', devices.map((d: any) => d.deviceId ?? d.id))
|
|
277
|
+
throw new Error('Device not found in config')
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
console.log('[SwitchBot UI] Found device before update:', JSON.stringify(device, null, 2))
|
|
281
|
+
|
|
282
|
+
// Update properties in all config branches
|
|
283
|
+
for (const ref of deviceArrays) {
|
|
284
|
+
for (const entry of ref) {
|
|
285
|
+
const entryId = String(entry.deviceId ?? entry.id ?? '').trim().toLowerCase()
|
|
286
|
+
if (entryId !== normalizedDeviceId) {
|
|
287
|
+
continue
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (configDeviceName !== undefined && configDeviceName !== null && String(configDeviceName).trim() !== '') {
|
|
291
|
+
entry.configDeviceName = configDeviceName
|
|
292
|
+
}
|
|
293
|
+
if (configDeviceType !== undefined && configDeviceType !== null && String(configDeviceType).trim() !== '') {
|
|
294
|
+
entry.configDeviceType = configDeviceType
|
|
295
|
+
}
|
|
296
|
+
if (connectionPreference !== undefined) {
|
|
297
|
+
entry.connectionPreference = connectionPreference
|
|
298
|
+
}
|
|
299
|
+
if (room !== undefined) {
|
|
300
|
+
entry.room = room || undefined
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (configDeviceName !== undefined && configDeviceName !== null && String(configDeviceName).trim() !== '') {
|
|
306
|
+
console.log('[SwitchBot UI] ✓ Updated configDeviceName to:', configDeviceName)
|
|
307
|
+
}
|
|
308
|
+
if (configDeviceType !== undefined && configDeviceType !== null && String(configDeviceType).trim() !== '') {
|
|
309
|
+
console.log('[SwitchBot UI] ✓ Updated configDeviceType to:', configDeviceType)
|
|
310
|
+
}
|
|
311
|
+
if (connectionPreference !== undefined) {
|
|
312
|
+
console.log('[SwitchBot UI] ✓ Updated connectionPreference to:', connectionPreference)
|
|
313
|
+
}
|
|
314
|
+
if (room !== undefined) {
|
|
315
|
+
console.log('[SwitchBot UI] ✓ Updated room to:', room)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
console.log('[SwitchBot UI] Device after updates:', JSON.stringify(device, null, 2))
|
|
319
|
+
|
|
320
|
+
// Save config
|
|
321
|
+
await fs.writeFile(cfgPath, JSON.stringify(config, null, 2), 'utf8')
|
|
322
|
+
console.log('[SwitchBot UI] ✓ Config file saved successfully:', cfgPath)
|
|
323
|
+
|
|
324
|
+
console.log('[SwitchBot UI] Device updated successfully:', deviceId)
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
success: true,
|
|
328
|
+
data: { message: `Device updated successfully - type: ${configDeviceType || device.configDeviceType}` },
|
|
329
|
+
}
|
|
330
|
+
} catch (e) {
|
|
331
|
+
console.error('[SwitchBot UI] Error in /update-device:', e instanceof Error ? e.message : String(e), e)
|
|
332
|
+
throw new RequestError(`Failed to update device: ${e instanceof Error ? e.message : String(e)}`, e)
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
server.onRequest('/delete-device', async (body: any) => {
|
|
337
|
+
try {
|
|
338
|
+
const { deviceId } = body
|
|
339
|
+
|
|
340
|
+
if (!deviceId) {
|
|
341
|
+
throw new Error('Device ID is required')
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const { config, platform, cfgPath } = await getSwitchBotPlatformConfig()
|
|
345
|
+
|
|
346
|
+
console.log('[SwitchBot UI] POST /delete-device - Deleting:', deviceId)
|
|
347
|
+
|
|
348
|
+
const deviceArrays = getDeviceArrays(platform)
|
|
349
|
+
const normalizedDeviceId = String(deviceId).trim().toLowerCase()
|
|
350
|
+
const allDevices = getAllDevices(platform)
|
|
351
|
+
const existing = allDevices.find((d: any) => String(d.deviceId ?? d.id ?? '').trim().toLowerCase() === normalizedDeviceId)
|
|
352
|
+
if (!existing) {
|
|
353
|
+
throw new Error('Device not found in config')
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const deviceName = existing.configDeviceName || deviceId
|
|
357
|
+
let removedCount = 0
|
|
358
|
+
for (const ref of deviceArrays) {
|
|
359
|
+
for (let i = ref.length - 1; i >= 0; i--) {
|
|
360
|
+
const id = String(ref[i]?.deviceId ?? ref[i]?.id ?? '').trim().toLowerCase()
|
|
361
|
+
if (id === normalizedDeviceId) {
|
|
362
|
+
ref.splice(i, 1)
|
|
363
|
+
removedCount++
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (!removedCount) {
|
|
369
|
+
throw new Error('Device not found in config')
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Save config
|
|
373
|
+
await fs.writeFile(cfgPath, JSON.stringify(config, null, 2), 'utf8')
|
|
374
|
+
|
|
375
|
+
console.log('[SwitchBot UI] Device deleted successfully:', deviceId, 'saved to', cfgPath)
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
success: true,
|
|
379
|
+
data: { message: `Device "${deviceName}" removed from config` },
|
|
380
|
+
}
|
|
381
|
+
} catch (e) {
|
|
382
|
+
console.error('[SwitchBot UI] Error in /delete-device:', e)
|
|
383
|
+
throw new RequestError('Failed to delete device', e)
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
server.onRequest('/credentials', async (body: any) => {
|
|
388
|
+
try {
|
|
389
|
+
// Handle both GET and POST requests
|
|
390
|
+
if (!body || Object.keys(body).length === 0) {
|
|
391
|
+
// GET request - return current status
|
|
392
|
+
const { platform } = await getSwitchBotPlatformConfig()
|
|
393
|
+
|
|
394
|
+
const token = getCredential(platform, 'openApiToken')
|
|
395
|
+
const secret = getCredential(platform, 'openApiSecret')
|
|
396
|
+
const status = {
|
|
397
|
+
hasToken: !!token,
|
|
398
|
+
hasSecret: !!secret,
|
|
399
|
+
tokenLength: token ? String(token).length : 0,
|
|
400
|
+
secretLength: secret ? String(secret).length : 0,
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
console.log('[SwitchBot UI] GET /credentials - Status:', status)
|
|
404
|
+
return { success: true, data: status }
|
|
405
|
+
} else {
|
|
406
|
+
// POST request - save credentials
|
|
407
|
+
const { token, secret } = body
|
|
408
|
+
|
|
409
|
+
if (!token || !secret) {
|
|
410
|
+
throw new Error('Token and secret are required')
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const { config, platform, cfgPath } = await getSwitchBotPlatformConfig()
|
|
414
|
+
|
|
415
|
+
console.log('[SwitchBot UI] POST /credentials - Saving to platform:', platform.platform || platform.name)
|
|
416
|
+
console.log('[SwitchBot UI] Config path:', cfgPath)
|
|
417
|
+
console.log('[SwitchBot UI] Token length:', token.length, 'Secret length:', secret.length)
|
|
418
|
+
|
|
419
|
+
// Save token and secret on the same config branch used by this platform
|
|
420
|
+
setCredential(platform, 'openApiToken', token)
|
|
421
|
+
setCredential(platform, 'openApiSecret', secret)
|
|
422
|
+
|
|
423
|
+
// Write back to config file
|
|
424
|
+
await fs.writeFile(cfgPath, JSON.stringify(config, null, 2), 'utf8')
|
|
425
|
+
|
|
426
|
+
console.log('[SwitchBot UI] Credentials saved successfully')
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
success: true,
|
|
430
|
+
data: { message: 'Credentials saved successfully' },
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
} catch (e) {
|
|
434
|
+
console.error('[SwitchBot UI] Error in /credentials:', e)
|
|
435
|
+
throw new RequestError('Failed to handle credentials request', e)
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
server.ready()
|
|
47
440
|
|
|
48
|
-
|
|
441
|
+
export default server
|
package/src/index.ts
CHANGED
|
@@ -4,41 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { API } from 'homebridge'
|
|
6
6
|
|
|
7
|
-
import { SwitchBotHAPPlatform } from './platform
|
|
8
|
-
import { SwitchBotMatterPlatform } from './platform-matter.js'
|
|
7
|
+
import { SwitchBotHAPPlatform, SwitchBotMatterPlatform } from './platform.js'
|
|
9
8
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
9
|
+
import { createPlatformProxy } from './utils.js'
|
|
10
10
|
|
|
11
11
|
// Register our platform with homebridge.
|
|
12
12
|
export default (api: API): void => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const isMatter = (() => {
|
|
16
|
-
try {
|
|
17
|
-
const maybeFnOrProp = (api as any).isMatterEnabled
|
|
18
|
-
if (typeof maybeFnOrProp === 'function') {
|
|
19
|
-
return Boolean(maybeFnOrProp.call(api))
|
|
20
|
-
}
|
|
21
|
-
if (typeof maybeFnOrProp !== 'undefined') {
|
|
22
|
-
return Boolean(maybeFnOrProp)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Some Homebridge beta versions expose Matter info on an internal server object
|
|
26
|
-
const server = (api as any).server ?? (api as any).homebridgeServer ?? (api as any).homebridge_server
|
|
27
|
-
const serverFn = server?.isMatterEnabled
|
|
28
|
-
if (typeof serverFn === 'function') {
|
|
29
|
-
return Boolean(serverFn.call(server))
|
|
30
|
-
}
|
|
31
|
-
if (typeof server?.isMatterEnabled !== 'undefined') {
|
|
32
|
-
return Boolean(server.isMatterEnabled)
|
|
33
|
-
}
|
|
34
|
-
} catch (e) {
|
|
35
|
-
// ignore and fall through to false
|
|
36
|
-
}
|
|
37
|
-
return false
|
|
38
|
-
})()
|
|
39
|
-
|
|
40
|
-
const log = (api as any).logger ?? (api as any).log ?? console
|
|
41
|
-
log.info?.(`Homebridge SwitchBot Plugin initializing in ${isMatter ? 'Matter' : 'HAP'} mode.`)
|
|
42
|
-
// If Matter is enabled register the Matter platform, otherwise use HAP platform.
|
|
43
|
-
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, isMatter ? SwitchBotMatterPlatform : SwitchBotHAPPlatform)
|
|
13
|
+
const ProxyCtor = createPlatformProxy(SwitchBotHAPPlatform, SwitchBotMatterPlatform)
|
|
14
|
+
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, ProxyCtor as any)
|
|
44
15
|
}
|