@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,249 +1,633 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<title>SwitchBot Plugin UI</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@media (prefers-color-scheme: light) {
|
|
13
|
+
body {
|
|
14
|
+
background: #f5f5f5;
|
|
15
|
+
color: #1a1a1a;
|
|
16
|
+
}
|
|
17
|
+
input {
|
|
18
|
+
background: #fff;
|
|
19
|
+
border-color: #ddd;
|
|
20
|
+
color: #1a1a1a;
|
|
21
|
+
}
|
|
22
|
+
input:focus {
|
|
23
|
+
border-color: #6366f1;
|
|
24
|
+
}
|
|
25
|
+
.card {
|
|
26
|
+
background: #fff;
|
|
27
|
+
border: 1px solid #ddd;
|
|
28
|
+
}
|
|
29
|
+
code {
|
|
30
|
+
background: #f0f0f0;
|
|
31
|
+
color: #1a1a1a;
|
|
32
|
+
}
|
|
33
|
+
h2 {
|
|
34
|
+
border-bottom-color: #ddd;
|
|
35
|
+
}
|
|
36
|
+
.status {
|
|
37
|
+
color: #666;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@media (prefers-color-scheme: dark) {
|
|
42
|
+
body {
|
|
43
|
+
background: #1a1a1a;
|
|
44
|
+
color: #fff;
|
|
45
|
+
}
|
|
46
|
+
input {
|
|
47
|
+
background: #2a2a2a;
|
|
48
|
+
border-color: #444;
|
|
49
|
+
color: #fff;
|
|
50
|
+
}
|
|
51
|
+
.card {
|
|
52
|
+
background: #2a2a2a;
|
|
53
|
+
}
|
|
54
|
+
code {
|
|
55
|
+
background: #333;
|
|
56
|
+
color: #fff;
|
|
57
|
+
}
|
|
58
|
+
h2 {
|
|
59
|
+
border-bottom-color: #444;
|
|
60
|
+
}
|
|
61
|
+
.status {
|
|
62
|
+
color: #888;
|
|
63
|
+
}
|
|
64
|
+
.device-item {
|
|
65
|
+
background: #333;
|
|
66
|
+
border: 1px solid #444;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@media (prefers-color-scheme: light) {
|
|
71
|
+
.device-item {
|
|
72
|
+
background: #f9f9f9;
|
|
73
|
+
border: 1px solid #e0e0e0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
body { font-family: system-ui, -apple-system, Arial; padding: 16px }
|
|
78
|
+
h1 { font-size: 24px; margin-top:0 }
|
|
79
|
+
h2 { font-size: 16px; margin-top: 24px; margin-bottom: 12px; border-bottom: 1px solid; padding-bottom:8px }
|
|
80
|
+
ul { padding-left: 0; list-style: none }
|
|
81
|
+
li { margin: 8px 0; display:flex; gap:8px; align-items:center }
|
|
82
|
+
button { padding: 8px 16px; background:#6366f1; color:#fff; border:none; border-radius:4px; cursor:pointer }
|
|
83
|
+
button:hover { background:#4f46e5 }
|
|
84
|
+
button.success { background:#10b981 }
|
|
85
|
+
code { padding:4px 6px; border-radius:4px; font-family: monospace }
|
|
86
|
+
.form-group { margin-bottom:16px }
|
|
87
|
+
label { display:block; margin-bottom:6px; font-weight:500 }
|
|
88
|
+
input { width:100%; max-width:400px; padding:8px; border: 1px solid; border-radius:4px; font-family:monospace }
|
|
89
|
+
input:focus { outline:none }
|
|
90
|
+
.status { font-size:14px; margin-top:4px }
|
|
91
|
+
.status.ok { color:#10b981 }
|
|
92
|
+
.error { color:#ef4444 }
|
|
93
|
+
.success-msg { color:#10b981; margin-top:8px }
|
|
94
|
+
.card { padding:16px; border-radius:8px; margin-bottom:16px }
|
|
95
|
+
.device-item { padding:8px; border-radius:4px; margin-bottom:8px; display:flex; gap:8px; align-items:center; justify-content:space-between }
|
|
96
|
+
</style>
|
|
97
|
+
</head>
|
|
98
|
+
<body>
|
|
99
|
+
<h1>🤖 SwitchBot Configuration</h1>
|
|
100
|
+
|
|
101
|
+
<div class="card">
|
|
102
|
+
<h2>API Credentials</h2>
|
|
103
|
+
<p>Configure your SwitchBot API token and secret to enable device discovery and control.</p>
|
|
104
|
+
|
|
105
|
+
<div class="form-group">
|
|
106
|
+
<label for="token">API Token:</label>
|
|
107
|
+
<input type="password" id="token" placeholder="Enter your SwitchBot API token" />
|
|
108
|
+
<div class="status" id="tokenStatus"></div>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
40
111
|
<div class="form-group">
|
|
41
|
-
<
|
|
112
|
+
<label for="secret">API Secret:</label>
|
|
113
|
+
<input type="password" id="secret" placeholder="Enter your SwitchBot API secret" />
|
|
114
|
+
<div class="status" id="secretStatus"></div>
|
|
42
115
|
</div>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<
|
|
52
|
-
<
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
</
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
116
|
+
|
|
117
|
+
<button id="saveBtn" onclick="saveCredentials()">Save Credentials</button>
|
|
118
|
+
<div id="saveStatus"></div>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div class="card">
|
|
122
|
+
<h2>Discover Devices</h2>
|
|
123
|
+
<p>Click "Discover" to find all devices available in your SwitchBot account and add them to your configuration.</p>
|
|
124
|
+
<div style="margin-bottom: 16px">
|
|
125
|
+
<label style="display: flex; align-items: center; gap: 8px; cursor: pointer">
|
|
126
|
+
<input type="checkbox" id="autoAddAllCheckbox" style="width: auto; margin: 0">
|
|
127
|
+
<span>Auto-add all discovered devices</span>
|
|
128
|
+
</label>
|
|
129
|
+
</div>
|
|
130
|
+
<button id="discoverBtn" onclick="discoverDevices()" style="margin-bottom: 16px">🔍 Discover Devices</button>
|
|
131
|
+
<div id="discoverStatus" style="margin-bottom: 16px"></div>
|
|
132
|
+
<div id="discoveredList" style="display: none">
|
|
133
|
+
<h3 style="margin-top: 0">Available Devices</h3>
|
|
134
|
+
<ul id="discoveredDevices" style="max-height: 300px; overflow-y: auto"></ul>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<div class="card">
|
|
139
|
+
<h2>Configured Devices</h2>
|
|
140
|
+
<p>This page lists devices found in your Homebridge config for the SwitchBot platform. Use the copy button to insert device IDs into the plugin configuration. Connection preference (BLE/OpenAPI) is shown when available.</p>
|
|
141
|
+
<div id="status">Loading…</div>
|
|
142
|
+
<ul id="devices"></ul>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
<script>
|
|
146
|
+
async function loadCredentialStatus() {
|
|
147
|
+
try {
|
|
148
|
+
const resp = await homebridge.request('/credentials', {})
|
|
149
|
+
console.log('Load credentials response:', resp)
|
|
150
|
+
|
|
151
|
+
if (!resp || resp.success === false) {
|
|
152
|
+
console.error('Failed to load credentials:', resp)
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const creds = resp.data || {}
|
|
157
|
+
const tokenStatus = document.getElementById('tokenStatus')
|
|
158
|
+
const secretStatus = document.getElementById('secretStatus')
|
|
159
|
+
|
|
160
|
+
if (creds.hasToken) {
|
|
161
|
+
tokenStatus.textContent = `✓ Configured (${creds.tokenLength} characters)`
|
|
162
|
+
tokenStatus.classList.add('ok')
|
|
163
|
+
} else {
|
|
164
|
+
tokenStatus.textContent = 'Not configured'
|
|
165
|
+
tokenStatus.classList.remove('ok')
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (creds.hasSecret) {
|
|
169
|
+
secretStatus.textContent = `✓ Configured (${creds.secretLength} characters)`
|
|
170
|
+
secretStatus.classList.add('ok')
|
|
171
|
+
} else {
|
|
172
|
+
secretStatus.textContent = 'Not configured'
|
|
173
|
+
secretStatus.classList.remove('ok')
|
|
174
|
+
}
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.error('Error loading credentials:', e)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function saveCredentials() {
|
|
181
|
+
const token = document.getElementById('token').value
|
|
182
|
+
const secret = document.getElementById('secret').value
|
|
183
|
+
const saveStatus = document.getElementById('saveStatus')
|
|
184
|
+
const saveBtn = document.getElementById('saveBtn')
|
|
185
|
+
|
|
186
|
+
if (!token || !secret) {
|
|
187
|
+
saveStatus.textContent = 'Please enter both token and secret'
|
|
188
|
+
saveStatus.classList.add('error')
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
saveBtn.disabled = true
|
|
194
|
+
saveBtn.textContent = 'Saving...'
|
|
195
|
+
|
|
196
|
+
console.log('Saving credentials...')
|
|
197
|
+
const resp = await homebridge.request('/credentials', { token, secret })
|
|
198
|
+
console.log('Save response:', resp)
|
|
199
|
+
|
|
200
|
+
if (!resp || resp.success === false) {
|
|
201
|
+
throw new Error(resp?.message || 'Save failed')
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const result = resp.data || resp
|
|
205
|
+
saveStatus.textContent = '✓ ' + (result.message || 'Credentials saved successfully')
|
|
206
|
+
saveStatus.classList.remove('error')
|
|
207
|
+
saveStatus.classList.add('success-msg')
|
|
208
|
+
|
|
209
|
+
// Clear inputs after successful save
|
|
210
|
+
document.getElementById('token').value = ''
|
|
211
|
+
document.getElementById('secret').value = ''
|
|
212
|
+
|
|
213
|
+
// Reload status to verify save
|
|
214
|
+
setTimeout(() => loadCredentialStatus(), 500)
|
|
215
|
+
|
|
216
|
+
// Clear status message
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
saveStatus.textContent = ''
|
|
219
|
+
saveStatus.classList.remove('success-msg')
|
|
220
|
+
}, 3000)
|
|
221
|
+
} catch (e) {
|
|
222
|
+
console.error('Save error:', e)
|
|
223
|
+
saveStatus.textContent = 'Error: ' + (e?.message || 'Failed to save')
|
|
224
|
+
saveStatus.classList.add('error')
|
|
225
|
+
} finally {
|
|
226
|
+
saveBtn.disabled = false
|
|
227
|
+
saveBtn.textContent = 'Save Credentials'
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function fetchDevices() {
|
|
232
|
+
try {
|
|
233
|
+
const resp = await homebridge.request('/devices', {})
|
|
234
|
+
if (!resp || resp.success === false) throw new Error(resp?.data?.message || 'request failed')
|
|
235
|
+
return resp.data || []
|
|
236
|
+
} catch (e) {
|
|
237
|
+
console.error(e)
|
|
238
|
+
return []
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function discoverDevices() {
|
|
243
|
+
const btn = document.getElementById('discoverBtn')
|
|
244
|
+
const status = document.getElementById('discoverStatus')
|
|
245
|
+
const list = document.getElementById('discoveredList')
|
|
246
|
+
const ul = document.getElementById('discoveredDevices')
|
|
247
|
+
const autoAddAll = document.getElementById('autoAddAllCheckbox').checked
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
btn.disabled = true
|
|
251
|
+
btn.textContent = '🔍 Discovering...'
|
|
252
|
+
status.textContent = 'Searching SwitchBot account...'
|
|
253
|
+
status.classList.remove('error')
|
|
254
|
+
|
|
255
|
+
const resp = await homebridge.request('/discover', {})
|
|
256
|
+
console.log('Discover response:', resp)
|
|
257
|
+
|
|
258
|
+
if (!resp || resp.success === false) {
|
|
259
|
+
throw new Error(resp?.data?.message || 'Discovery failed')
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const devicesRaw = resp.data || []
|
|
263
|
+
const devices = devicesRaw.filter((d, index, arr) =>
|
|
264
|
+
!!d?.id && arr.findIndex((x) => x?.id === d.id) === index,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
if (!devices.length) {
|
|
268
|
+
status.textContent = 'No devices found in your SwitchBot account'
|
|
269
|
+
list.style.display = 'none'
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// If auto-add is enabled, add all devices immediately
|
|
274
|
+
if (autoAddAll) {
|
|
275
|
+
status.textContent = `Auto-adding ${devices.length} device(s)...`
|
|
276
|
+
let addedCount = 0
|
|
277
|
+
let skippedCount = 0
|
|
278
|
+
|
|
279
|
+
for (const d of devices) {
|
|
280
|
+
try {
|
|
281
|
+
const result = await addDeviceToConfig(d, { refresh: false, showStatus: false })
|
|
282
|
+
if (result?.added) {
|
|
283
|
+
addedCount++
|
|
284
|
+
} else {
|
|
285
|
+
skippedCount++
|
|
286
|
+
}
|
|
287
|
+
} catch (e) {
|
|
288
|
+
console.warn(`Failed to add device ${d.id}:`, e)
|
|
289
|
+
skippedCount++
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
status.textContent = `✓ Added ${addedCount} device(s)` + (skippedCount > 0 ? ` (${skippedCount} skipped)` : '')
|
|
294
|
+
status.classList.remove('error')
|
|
295
|
+
list.style.display = 'none'
|
|
296
|
+
|
|
297
|
+
// Refresh the configured devices list
|
|
298
|
+
await loadConfiguredDevices()
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
status.textContent = `Found ${devices.length} device(s)`
|
|
303
|
+
ul.innerHTML = ''
|
|
304
|
+
|
|
305
|
+
for (const d of devices) {
|
|
306
|
+
const li = document.createElement('li')
|
|
307
|
+
li.className = 'device-item'
|
|
308
|
+
|
|
309
|
+
const info = document.createElement('div')
|
|
310
|
+
info.style.flex = '1'
|
|
311
|
+
const name = document.createElement('div')
|
|
312
|
+
name.style.fontWeight = '500'
|
|
313
|
+
name.textContent = d.name || d.id
|
|
314
|
+
const details = document.createElement('div')
|
|
315
|
+
details.style.fontSize = '12px'
|
|
316
|
+
details.style.opacity = '0.75'
|
|
317
|
+
details.textContent = `ID: ${d.id} | Type: ${d.type} | Model: ${d.model || 'N/A'}`
|
|
318
|
+
info.appendChild(name)
|
|
319
|
+
info.appendChild(details)
|
|
320
|
+
|
|
321
|
+
const addBtn = document.createElement('button')
|
|
322
|
+
addBtn.textContent = '+ Add'
|
|
323
|
+
addBtn.style.marginLeft = '8px'
|
|
324
|
+
addBtn.onclick = async () => {
|
|
325
|
+
await addDeviceToConfig(d)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
li.appendChild(info)
|
|
329
|
+
li.appendChild(addBtn)
|
|
330
|
+
ul.appendChild(li)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
list.style.display = 'block'
|
|
334
|
+
} catch (e) {
|
|
335
|
+
console.error('Discovery error:', e)
|
|
336
|
+
status.textContent = 'Error: ' + (e?.message || 'Discovery failed')
|
|
337
|
+
status.classList.add('error')
|
|
338
|
+
list.style.display = 'none'
|
|
339
|
+
} finally {
|
|
340
|
+
btn.disabled = false
|
|
341
|
+
btn.textContent = '🔍 Discover Devices'
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function addDeviceToConfig(device, options = {}) {
|
|
346
|
+
const { refresh = true, showStatus = true } = options
|
|
347
|
+
try {
|
|
348
|
+
console.log('Adding device to config:', device)
|
|
349
|
+
|
|
350
|
+
const resp = await homebridge.request('/add-device', {
|
|
351
|
+
deviceId: device.id,
|
|
352
|
+
name: device.name,
|
|
353
|
+
type: device.type,
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
console.log('Add device response:', resp)
|
|
357
|
+
|
|
358
|
+
if (!resp || resp.success === false) {
|
|
359
|
+
throw new Error(resp?.data?.message || 'Failed to add device')
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const alreadyExists = !!resp.data?.alreadyExists
|
|
363
|
+
const message = resp.data?.message || (alreadyExists
|
|
364
|
+
? `Device "${device.name}" already in config`
|
|
365
|
+
: `Device "${device.name}" added successfully!`)
|
|
366
|
+
|
|
367
|
+
if (showStatus) {
|
|
368
|
+
const status = document.getElementById('discoverStatus')
|
|
369
|
+
status.textContent = (alreadyExists ? '• ' : '✓ ') + message
|
|
370
|
+
status.classList.remove('error')
|
|
371
|
+
status.classList.add('success-msg')
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (refresh) {
|
|
375
|
+
await loadConfiguredDevices()
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return { added: !alreadyExists }
|
|
379
|
+
} catch (e) {
|
|
380
|
+
console.error('Add device error:', e)
|
|
381
|
+
const status = document.getElementById('discoverStatus')
|
|
382
|
+
status.textContent = '✗ Error: ' + (e?.message || 'Failed to add device')
|
|
383
|
+
status.classList.add('error')
|
|
384
|
+
return { added: false }
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async function loadConfiguredDevices() {
|
|
389
|
+
const list = await fetchDevices()
|
|
390
|
+
render(list)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
async function deleteDevice(deviceId, deviceName) {
|
|
394
|
+
if (!confirm(`Are you sure you want to remove "${deviceName || deviceId}"?`)) {
|
|
395
|
+
return
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
try {
|
|
399
|
+
const resp = await homebridge.request('/delete-device', { deviceId })
|
|
400
|
+
|
|
401
|
+
if (!resp || resp.success === false) {
|
|
402
|
+
throw new Error(resp?.data?.message || 'Failed to delete device')
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Refresh device list
|
|
406
|
+
const list = await fetchDevices()
|
|
407
|
+
render(list)
|
|
408
|
+
} catch (e) {
|
|
409
|
+
console.error('Delete error:', e)
|
|
410
|
+
alert('Error: ' + (e?.message || 'Failed to delete device'))
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const DEVICE_TYPES = [
|
|
415
|
+
'bot', 'curtain', 'fan', 'light', 'lightstrip', 'motion', 'contact',
|
|
416
|
+
'vacuum', 'lock', 'humidifier', 'temperature', 'relay', 'plug',
|
|
417
|
+
'wosweeper', 'blindtilt', 'curtain3', 'rollershade', 'meter',
|
|
418
|
+
'waterdetector', 'walletfinder', 'unknown'
|
|
419
|
+
]
|
|
420
|
+
|
|
421
|
+
async function editDevice(device) {
|
|
422
|
+
// Create modal dialog for editing
|
|
423
|
+
const div = document.createElement('div')
|
|
424
|
+
div.style.position = 'fixed'
|
|
425
|
+
div.style.top = '0'
|
|
426
|
+
div.style.left = '0'
|
|
427
|
+
div.style.width = '100%'
|
|
428
|
+
div.style.height = '100%'
|
|
429
|
+
div.style.background = 'rgba(0,0,0,0.7)'
|
|
430
|
+
div.style.display = 'flex'
|
|
431
|
+
div.style.alignItems = 'center'
|
|
432
|
+
div.style.justifyContent = 'center'
|
|
433
|
+
div.style.zIndex = '9999'
|
|
434
|
+
|
|
435
|
+
const modal = document.createElement('div')
|
|
436
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor
|
|
437
|
+
modal.style.color = getComputedStyle(document.body).color
|
|
438
|
+
modal.style.padding = '24px'
|
|
439
|
+
modal.style.borderRadius = '8px'
|
|
440
|
+
modal.style.minWidth = '400px'
|
|
441
|
+
modal.style.boxShadow = '0 10px 40px rgba(0,0,0,0.3)'
|
|
442
|
+
|
|
443
|
+
const title = document.createElement('h3')
|
|
444
|
+
title.textContent = 'Edit Device'
|
|
445
|
+
title.style.marginTop = '0'
|
|
446
|
+
|
|
447
|
+
const nameLabel = document.createElement('label')
|
|
448
|
+
nameLabel.textContent = 'Device Name'
|
|
449
|
+
nameLabel.style.display = 'block'
|
|
450
|
+
nameLabel.style.marginBottom = '8px'
|
|
451
|
+
nameLabel.style.fontWeight = '500'
|
|
452
|
+
|
|
453
|
+
const nameInput = document.createElement('input')
|
|
454
|
+
nameInput.type = 'text'
|
|
455
|
+
nameInput.value = device.name || device.id
|
|
456
|
+
nameInput.style.width = '100%'
|
|
457
|
+
nameInput.style.marginBottom = '16px'
|
|
458
|
+
|
|
459
|
+
const typeLabel = document.createElement('label')
|
|
460
|
+
typeLabel.textContent = 'Device Type'
|
|
461
|
+
typeLabel.style.display = 'block'
|
|
462
|
+
typeLabel.style.marginBottom = '8px'
|
|
463
|
+
typeLabel.style.fontWeight = '500'
|
|
464
|
+
|
|
465
|
+
const typeSelect = document.createElement('select')
|
|
466
|
+
typeSelect.style.width = '100%'
|
|
467
|
+
typeSelect.style.padding = '8px'
|
|
468
|
+
typeSelect.style.marginBottom = '16px'
|
|
469
|
+
typeSelect.style.borderRadius = '4px'
|
|
470
|
+
typeSelect.style.background = getComputedStyle(nameInput).background
|
|
471
|
+
typeSelect.style.color = getComputedStyle(nameInput).color
|
|
472
|
+
typeSelect.style.border = getComputedStyle(nameInput).border
|
|
473
|
+
|
|
474
|
+
DEVICE_TYPES.forEach(t => {
|
|
475
|
+
const opt = document.createElement('option')
|
|
476
|
+
opt.value = t
|
|
477
|
+
opt.text = t
|
|
478
|
+
opt.selected = (device.type || 'unknown') === t
|
|
479
|
+
typeSelect.appendChild(opt)
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
const buttons = document.createElement('div')
|
|
483
|
+
buttons.style.display = 'flex'
|
|
484
|
+
buttons.style.gap = '8px'
|
|
485
|
+
buttons.style.justifyContent = 'flex-end'
|
|
486
|
+
|
|
487
|
+
const cancelBtn = document.createElement('button')
|
|
488
|
+
cancelBtn.textContent = 'Cancel'
|
|
489
|
+
cancelBtn.style.background = '#666'
|
|
490
|
+
cancelBtn.onclick = () => div.remove()
|
|
491
|
+
|
|
492
|
+
const saveBtn = document.createElement('button')
|
|
493
|
+
saveBtn.textContent = 'Save'
|
|
494
|
+
saveBtn.onclick = async () => {
|
|
495
|
+
try {
|
|
496
|
+
const params = {
|
|
497
|
+
deviceId: device.id,
|
|
498
|
+
configDeviceName: nameInput.value || undefined,
|
|
499
|
+
configDeviceType: typeSelect.value,
|
|
500
|
+
}
|
|
501
|
+
console.log('[Edit Device] Sending update request with params:', params)
|
|
502
|
+
|
|
503
|
+
const resp = await homebridge.request('/update-device', params)
|
|
504
|
+
|
|
505
|
+
console.log('[Edit Device] Update response:', resp)
|
|
506
|
+
|
|
507
|
+
if (!resp || resp.success === false) {
|
|
508
|
+
throw new Error(resp?.data?.message || 'Failed to update device')
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Refresh device list
|
|
512
|
+
console.log('[Edit Device] Refreshing device list after update')
|
|
513
|
+
const list = await fetchDevices()
|
|
514
|
+
render(list)
|
|
515
|
+
div.remove()
|
|
516
|
+
} catch (e) {
|
|
517
|
+
console.error('Update error:', e)
|
|
518
|
+
alert('Error: ' + (e?.message || 'Failed to update device'))
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
buttons.appendChild(cancelBtn)
|
|
523
|
+
buttons.appendChild(saveBtn)
|
|
524
|
+
|
|
525
|
+
modal.appendChild(title)
|
|
526
|
+
modal.appendChild(nameLabel)
|
|
527
|
+
modal.appendChild(nameInput)
|
|
528
|
+
modal.appendChild(typeLabel)
|
|
529
|
+
modal.appendChild(typeSelect)
|
|
530
|
+
modal.appendChild(buttons)
|
|
531
|
+
|
|
532
|
+
div.appendChild(modal)
|
|
533
|
+
document.body.appendChild(div)
|
|
534
|
+
nameInput.focus()
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function render(list) {
|
|
538
|
+
const ul = document.getElementById('devices')
|
|
539
|
+
const status = document.getElementById('status')
|
|
540
|
+
if (!list.length) {
|
|
541
|
+
status.textContent = 'No devices found in config.'
|
|
542
|
+
ul.innerHTML = ''
|
|
543
|
+
return
|
|
544
|
+
}
|
|
545
|
+
status.textContent = `Found ${list.length} device(s)`
|
|
546
|
+
ul.innerHTML = ''
|
|
547
|
+
for (const d of list) {
|
|
548
|
+
const li = document.createElement('li')
|
|
549
|
+
li.className = 'device-item'
|
|
550
|
+
|
|
551
|
+
const info = document.createElement('div')
|
|
552
|
+
info.style.flex = '1'
|
|
553
|
+
|
|
554
|
+
const name = document.createElement('div')
|
|
555
|
+
name.style.fontWeight = '500'
|
|
556
|
+
name.textContent = d.name || d.id
|
|
557
|
+
|
|
558
|
+
const code = document.createElement('code')
|
|
559
|
+
code.textContent = d.id
|
|
560
|
+
code.style.fontSize = '12px'
|
|
561
|
+
code.style.opacity = '0.75'
|
|
562
|
+
code.style.marginLeft = '8px'
|
|
563
|
+
|
|
564
|
+
const meta = document.createElement('div')
|
|
565
|
+
meta.style.opacity = '0.75'
|
|
566
|
+
meta.style.marginTop = '4px'
|
|
567
|
+
meta.style.fontSize = '12px'
|
|
568
|
+
const typeText = d.type ? `type: ${d.type}` : ''
|
|
569
|
+
const connText = d.connectionPreference ? `conn: ${d.connectionPreference}` : ''
|
|
570
|
+
const roomText = d.room ? `room: ${d.room}` : ''
|
|
571
|
+
meta.textContent = [typeText, connText, roomText].filter(Boolean).join(' | ')
|
|
572
|
+
|
|
573
|
+
info.appendChild(name)
|
|
574
|
+
info.appendChild(code)
|
|
575
|
+
info.appendChild(meta)
|
|
576
|
+
|
|
577
|
+
const buttons = document.createElement('div')
|
|
578
|
+
buttons.style.display = 'flex'
|
|
579
|
+
buttons.style.gap = '8px'
|
|
580
|
+
|
|
581
|
+
const editBtn = document.createElement('button')
|
|
582
|
+
editBtn.textContent = '✏️ Edit'
|
|
583
|
+
editBtn.style.padding = '6px 12px'
|
|
584
|
+
editBtn.style.fontSize = '12px'
|
|
585
|
+
editBtn.onclick = async () => {
|
|
586
|
+
await editDevice(d)
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const copyBtn = document.createElement('button')
|
|
590
|
+
copyBtn.textContent = 'Copy ID'
|
|
591
|
+
copyBtn.style.padding = '6px 12px'
|
|
592
|
+
copyBtn.style.fontSize = '12px'
|
|
593
|
+
copyBtn.addEventListener('click', async () => {
|
|
594
|
+
try {
|
|
595
|
+
await navigator.clipboard.writeText(d.id)
|
|
596
|
+
copyBtn.textContent = 'Copied'
|
|
597
|
+
copyBtn.classList.add('success')
|
|
598
|
+
setTimeout(() => {
|
|
599
|
+
copyBtn.textContent = 'Copy ID'
|
|
600
|
+
copyBtn.classList.remove('success')
|
|
601
|
+
}, 1200)
|
|
602
|
+
} catch (e) {
|
|
603
|
+
alert('Failed to copy')
|
|
604
|
+
}
|
|
605
|
+
})
|
|
606
|
+
|
|
607
|
+
const deleteBtn = document.createElement('button')
|
|
608
|
+
deleteBtn.textContent = '🗑️ Delete'
|
|
609
|
+
deleteBtn.style.padding = '6px 12px'
|
|
610
|
+
deleteBtn.style.fontSize = '12px'
|
|
611
|
+
deleteBtn.style.background = '#ef4444'
|
|
612
|
+
deleteBtn.onclick = async () => {
|
|
613
|
+
await deleteDevice(d.id, d.name || d.id)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
buttons.appendChild(editBtn)
|
|
617
|
+
buttons.appendChild(copyBtn)
|
|
618
|
+
buttons.appendChild(deleteBtn)
|
|
619
|
+
|
|
620
|
+
li.appendChild(info)
|
|
621
|
+
li.appendChild(buttons)
|
|
622
|
+
ul.appendChild(li)
|
|
623
|
+
}
|
|
242
624
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
</script>
|
|
625
|
+
|
|
626
|
+
(async () => {
|
|
627
|
+
await loadCredentialStatus()
|
|
628
|
+
const list = await fetchDevices()
|
|
629
|
+
render(list)
|
|
630
|
+
})()
|
|
631
|
+
</script>
|
|
632
|
+
</body>
|
|
633
|
+
</html>
|