@switchbot/homebridge-switchbot 5.0.0-beta.11 → 5.0.0-beta.111
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/copilot-instructions.md +39 -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 +170 -14787
- package/dist/device-types.d.ts +31 -0
- package/dist/device-types.d.ts.map +1 -0
- package/dist/device-types.js +216 -0
- package/dist/device-types.js.map +1 -0
- package/dist/deviceFactory.d.ts +13 -0
- package/dist/deviceFactory.d.ts.map +1 -0
- package/dist/deviceFactory.js +120 -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 +298 -0
- package/dist/devices/genericDevice.d.ts.map +1 -0
- package/dist/devices/genericDevice.js +1067 -0
- package/dist/devices/genericDevice.js.map +1 -0
- package/dist/homebridge-ui/endpoints/config.d.ts +3 -0
- package/dist/homebridge-ui/endpoints/config.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/config.js +104 -0
- package/dist/homebridge-ui/endpoints/config.js.map +1 -0
- package/dist/homebridge-ui/endpoints/credentials.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/credentials.js +65 -0
- package/dist/homebridge-ui/endpoints/credentials.js.map +1 -0
- package/dist/homebridge-ui/endpoints/devices.d.ts +6 -0
- package/dist/homebridge-ui/endpoints/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/devices.js +351 -0
- package/dist/homebridge-ui/endpoints/devices.js.map +1 -0
- package/dist/homebridge-ui/endpoints/discovery.d.ts +7 -0
- package/dist/homebridge-ui/endpoints/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/endpoints/discovery.js +171 -0
- package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/css/styles.css +254 -0
- package/dist/homebridge-ui/public/index.html +112 -247
- package/dist/homebridge-ui/public/js/api.d.ts +23 -0
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/api.js +188 -0
- package/dist/homebridge-ui/public/js/api.js.map +1 -0
- package/dist/homebridge-ui/public/js/api.ts +215 -0
- package/dist/homebridge-ui/public/js/app.d.ts +2 -0
- package/dist/homebridge-ui/public/js/app.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/app.js +1815 -0
- package/dist/homebridge-ui/public/js/app.js.map +7 -0
- package/dist/homebridge-ui/public/js/app.ts +22 -0
- package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
- package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/constants.js +2 -0
- package/dist/homebridge-ui/public/js/constants.js.map +1 -0
- package/dist/homebridge-ui/public/js/constants.ts +1 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.js +96 -0
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.ts +100 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts +3 -0
- package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.js +206 -0
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.ts +236 -0
- package/dist/homebridge-ui/public/js/devices.d.ts +9 -0
- package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/devices.js +90 -0
- package/dist/homebridge-ui/public/js/devices.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices.ts +98 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts +3 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.js +244 -0
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.ts +290 -0
- package/dist/homebridge-ui/public/js/logger.d.ts +6 -0
- package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/logger.js +12 -0
- package/dist/homebridge-ui/public/js/logger.js.map +1 -0
- package/dist/homebridge-ui/public/js/logger.ts +11 -0
- package/dist/homebridge-ui/public/js/modal.d.ts +5 -0
- package/dist/homebridge-ui/public/js/modal.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modal.js +26 -0
- package/dist/homebridge-ui/public/js/modal.js.map +1 -0
- package/dist/homebridge-ui/public/js/modal.ts +28 -0
- package/dist/homebridge-ui/public/js/modals.d.ts +7 -0
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modals.js +323 -0
- package/dist/homebridge-ui/public/js/modals.js.map +1 -0
- package/dist/homebridge-ui/public/js/modals.ts +367 -0
- package/dist/homebridge-ui/public/js/render.d.ts +65 -0
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/render.js +499 -0
- package/dist/homebridge-ui/public/js/render.js.map +1 -0
- package/dist/homebridge-ui/public/js/render.ts +579 -0
- package/dist/homebridge-ui/public/js/toast.d.ts +6 -0
- package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/toast.js +29 -0
- package/dist/homebridge-ui/public/js/toast.js.map +1 -0
- package/dist/homebridge-ui/public/js/toast.ts +37 -0
- package/dist/homebridge-ui/public/js/types.d.ts +23 -0
- package/dist/homebridge-ui/public/js/types.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/types.js +2 -0
- package/dist/homebridge-ui/public/js/types.js.map +1 -0
- package/dist/homebridge-ui/public/js/types.ts +26 -0
- package/dist/homebridge-ui/server.js +11 -41
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/homebridge-ui/utils/config-parser.d.ts +35 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.js +87 -0
- package/dist/homebridge-ui/utils/config-parser.js.map +1 -0
- package/dist/homebridge-ui/utils/device-migration.d.ts +35 -0
- package/dist/homebridge-ui/utils/device-migration.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/device-migration.js +111 -0
- package/dist/homebridge-ui/utils/device-migration.js.map +1 -0
- package/dist/homebridge-ui/utils/logger.d.ts +7 -0
- package/dist/homebridge-ui/utils/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/logger.js +17 -0
- package/dist/homebridge-ui/utils/logger.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -65
- 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 +1527 -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 +207 -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 +40 -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 +7 -8
- package/nodemon.json +2 -2
- package/package.json +35 -32
- package/scripts/build-ui.js +36 -0
- 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/free-dev-ports.mjs +105 -0
- package/scripts/generate-matter-maps.js +60 -0
- package/scripts/run-e2e-local.sh +14 -0
- package/scripts/sync-device-types.mjs +28 -0
- package/src/device-types.ts +230 -0
- package/src/deviceFactory.ts +163 -0
- package/src/devices/deviceBase.ts +141 -0
- package/src/devices/genericDevice.ts +998 -0
- package/src/homebridge-ui/endpoints/config.ts +123 -0
- package/src/homebridge-ui/endpoints/credentials.ts +74 -0
- package/src/homebridge-ui/endpoints/devices.ts +383 -0
- package/src/homebridge-ui/endpoints/discovery.ts +191 -0
- package/src/homebridge-ui/public/css/styles.css +254 -0
- package/src/homebridge-ui/public/index.html +112 -247
- package/src/homebridge-ui/public/js/api.ts +215 -0
- package/src/homebridge-ui/public/js/app.ts +22 -0
- package/src/homebridge-ui/public/js/constants.ts +1 -0
- package/src/homebridge-ui/public/js/credentials.ts +100 -0
- package/src/homebridge-ui/public/js/devices-delete.ts +236 -0
- package/src/homebridge-ui/public/js/devices.ts +98 -0
- package/src/homebridge-ui/public/js/discovery.ts +290 -0
- package/src/homebridge-ui/public/js/logger.ts +11 -0
- package/src/homebridge-ui/public/js/modal.ts +28 -0
- package/src/homebridge-ui/public/js/modals.ts +367 -0
- package/src/homebridge-ui/public/js/render.ts +579 -0
- package/src/homebridge-ui/public/js/toast.ts +37 -0
- package/src/homebridge-ui/public/js/types.ts +26 -0
- package/src/homebridge-ui/server.ts +11 -43
- package/src/homebridge-ui/utils/config-parser.ts +108 -0
- package/src/homebridge-ui/utils/device-migration.ts +144 -0
- package/src/homebridge-ui/utils/logger.ts +17 -0
- package/src/index.ts +4 -66
- package/src/platform.ts +1539 -0
- package/src/settings.ts +12 -277
- package/src/switchbotClient.ts +216 -0
- package/src/utils.ts +46 -713
- package/switchbot-homebridge-switchbot-5.0.0.tgz +0 -0
- 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 +59 -0
- package/test/matter-descriptors.spec.ts +97 -0
- package/test/matter-device-state.spec.ts +101 -0
- package/test/matter-integration.spec.ts +111 -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 +36 -0
- package/todo/COMPLETED.md +229 -0
- package/todo/README.md +59 -0
- package/todo/TODO.md +176 -0
- package/todo/mockups/filtering-sorting.svg +112 -0
- package/todo/mockups/modal-switchbot-theme.svg +66 -0
- package/todo/mockups/signal-strength-visualization.svg +94 -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 -19
- 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 -984
- 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 -24
- 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 -1110
- package/src/verifyconfig.test.ts +0 -197
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addDevicesInBulk,
|
|
3
|
+
discoverDevices as apiDiscoverDevices,
|
|
4
|
+
fetchDevices,
|
|
5
|
+
syncParentPluginConfigFromDisk,
|
|
6
|
+
} from './api.js'
|
|
7
|
+
import { loadConfiguredDevices } from './devices.js'
|
|
8
|
+
import { uiLog } from './logger.js'
|
|
9
|
+
import { hideBusyUi, showBusyUi } from './modal.js'
|
|
10
|
+
import { renderDiscoveredDevices, filterDevices, sortDevices, getDiscoveryPreferences, setDiscoveryPreferences } from './render.js'
|
|
11
|
+
import { toastError, toastInfo, toastSuccess, toastWarning } from './toast.js'
|
|
12
|
+
|
|
13
|
+
function normalizeId(value: any): string {
|
|
14
|
+
return String(value ?? '').trim().toLowerCase()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function discoverDevices(): Promise<void> {
|
|
18
|
+
const btn = document.getElementById('discoverBtn') as HTMLButtonElement
|
|
19
|
+
const status = document.getElementById('discoverStatus')
|
|
20
|
+
const list = document.getElementById('discoveredList')
|
|
21
|
+
const autoAddAll = (document.getElementById('autoAddAllCheckbox') as HTMLInputElement)?.checked
|
|
22
|
+
|
|
23
|
+
if (!btn || !status || !list) { return }
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
showBusyUi()
|
|
27
|
+
btn.disabled = true
|
|
28
|
+
btn.textContent = '🔍 Discovering...'
|
|
29
|
+
status.textContent = 'Searching SwitchBot account...'
|
|
30
|
+
status.classList.remove('error')
|
|
31
|
+
|
|
32
|
+
const devicesRaw = await apiDiscoverDevices()
|
|
33
|
+
uiLog.info('Discover response:', devicesRaw)
|
|
34
|
+
|
|
35
|
+
// Deduplicate by device ID
|
|
36
|
+
const devices = devicesRaw.filter((d, index, arr) => !!d?.id && arr.findIndex(x => x?.id === d.id) === index)
|
|
37
|
+
|
|
38
|
+
if (!devices.length) {
|
|
39
|
+
status.textContent = 'No devices found in your SwitchBot account'
|
|
40
|
+
toastInfo('No devices found in your SwitchBot account')
|
|
41
|
+
list.style.display = 'none'
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If auto-add is enabled, add all devices immediately using bulk endpoint
|
|
46
|
+
if (autoAddAll) {
|
|
47
|
+
status.textContent = `Auto-adding ${devices.length} device(s)...`
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const bulkResult = await addDevicesInBulk(
|
|
51
|
+
devices.map(d => ({
|
|
52
|
+
deviceId: d.id,
|
|
53
|
+
name: d.name,
|
|
54
|
+
type: d.type,
|
|
55
|
+
rssi: d.rssi,
|
|
56
|
+
address: d.address,
|
|
57
|
+
model: d.model,
|
|
58
|
+
})),
|
|
59
|
+
)
|
|
60
|
+
uiLog.info('Bulk add response:', bulkResult)
|
|
61
|
+
|
|
62
|
+
if (!bulkResult || bulkResult.success === false) {
|
|
63
|
+
throw new Error(bulkResult?.data?.message || 'Bulk add failed')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const addedCount
|
|
67
|
+
= bulkResult?.addedCount
|
|
68
|
+
?? bulkResult?.data?.addedCount
|
|
69
|
+
?? 0
|
|
70
|
+
const skippedCount
|
|
71
|
+
= bulkResult?.skippedCount
|
|
72
|
+
?? bulkResult?.data?.skippedCount
|
|
73
|
+
?? 0
|
|
74
|
+
status.textContent = `✓ Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ''}`
|
|
75
|
+
if (addedCount > 0) {
|
|
76
|
+
toastSuccess(`Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ''}`)
|
|
77
|
+
} else if (skippedCount > 0) {
|
|
78
|
+
toastWarning(`No new devices were added (${skippedCount} skipped)`)
|
|
79
|
+
}
|
|
80
|
+
status.classList.remove('error')
|
|
81
|
+
list.style.display = 'none'
|
|
82
|
+
|
|
83
|
+
// Sync parent Homebridge form cache and auto-save to prevent cache overwrite
|
|
84
|
+
// Run sync when discovery returned devices (even if backend response shape changes)
|
|
85
|
+
if (devices.length > 0) {
|
|
86
|
+
const synced = await syncParentPluginConfigFromDisk(true)
|
|
87
|
+
status.textContent += synced
|
|
88
|
+
? ' - Config saved automatically.'
|
|
89
|
+
: ' - Warning: config may not persist until you close/reopen settings.'
|
|
90
|
+
|
|
91
|
+
if (synced) {
|
|
92
|
+
toastSuccess('Configuration synced and saved automatically')
|
|
93
|
+
} else {
|
|
94
|
+
toastWarning('Configuration sync failed; close and reopen settings before Save')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
uiLog.error('Bulk add error:', e)
|
|
99
|
+
status.textContent = `✗ Error: ${e instanceof Error ? e.message : 'Failed to add devices'}`
|
|
100
|
+
status.classList.add('error')
|
|
101
|
+
toastError(e instanceof Error ? e.message : 'Failed to add devices')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Refresh the configured devices list
|
|
105
|
+
await loadConfiguredDevices()
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
status.textContent = `Found ${devices.length} device(s)`
|
|
110
|
+
|
|
111
|
+
// Create filter/sort controls
|
|
112
|
+
const controlsDiv = document.createElement('div')
|
|
113
|
+
controlsDiv.style.cssText = 'margin-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center;'
|
|
114
|
+
|
|
115
|
+
// Load saved preferences
|
|
116
|
+
const preferences = getDiscoveryPreferences()
|
|
117
|
+
|
|
118
|
+
// Filter buttons
|
|
119
|
+
const filterLabel = document.createElement('label')
|
|
120
|
+
filterLabel.style.fontSize = '12px'
|
|
121
|
+
filterLabel.style.fontWeight = '500'
|
|
122
|
+
filterLabel.textContent = 'Filter:'
|
|
123
|
+
|
|
124
|
+
const filterGroup = document.createElement('div')
|
|
125
|
+
filterGroup.style.display = 'flex'
|
|
126
|
+
filterGroup.style.gap = '4px'
|
|
127
|
+
|
|
128
|
+
const filterOptions: Array<{ label: string, value: 'all' | 'ble' | 'api' | 'both' | 'ir' }> = [
|
|
129
|
+
{ label: 'All', value: 'all' },
|
|
130
|
+
{ label: 'BLE', value: 'ble' },
|
|
131
|
+
{ label: 'API', value: 'api' },
|
|
132
|
+
{ label: 'Both', value: 'both' },
|
|
133
|
+
{ label: 'IR', value: 'ir' },
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
for (const option of filterOptions) {
|
|
137
|
+
const btn = document.createElement('button')
|
|
138
|
+
btn.textContent = option.label
|
|
139
|
+
btn.style.padding = '4px 8px'
|
|
140
|
+
btn.style.fontSize = '11px'
|
|
141
|
+
btn.style.borderRadius = '3px'
|
|
142
|
+
btn.style.cursor = 'pointer'
|
|
143
|
+
btn.style.border = preferences.connectionType === option.value ? '2px solid #007AFF' : '1px solid #ccc'
|
|
144
|
+
btn.style.backgroundColor = preferences.connectionType === option.value ? '#f0f7ff' : '#fff'
|
|
145
|
+
btn.style.color = preferences.connectionType === option.value ? '#1d4ed8' : '#374151'
|
|
146
|
+
|
|
147
|
+
btn.onclick = () => {
|
|
148
|
+
preferences.connectionType = option.value
|
|
149
|
+
setDiscoveryPreferences(preferences)
|
|
150
|
+
updateDiscoveryView(devices, preferences)
|
|
151
|
+
// Update button styles
|
|
152
|
+
for (const b of Array.from(filterGroup.querySelectorAll('button'))) {
|
|
153
|
+
;(b as HTMLButtonElement).style.border = '1px solid #ccc'
|
|
154
|
+
;(b as HTMLButtonElement).style.backgroundColor = '#fff'
|
|
155
|
+
;(b as HTMLButtonElement).style.color = '#374151'
|
|
156
|
+
}
|
|
157
|
+
btn.style.border = '2px solid #007AFF'
|
|
158
|
+
btn.style.backgroundColor = '#f0f7ff'
|
|
159
|
+
btn.style.color = '#1d4ed8'
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
filterGroup.appendChild(btn)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Sort dropdown
|
|
166
|
+
const sortLabel = document.createElement('label')
|
|
167
|
+
sortLabel.style.fontSize = '12px'
|
|
168
|
+
sortLabel.style.fontWeight = '500'
|
|
169
|
+
sortLabel.style.marginLeft = '8px'
|
|
170
|
+
sortLabel.textContent = 'Sort:'
|
|
171
|
+
|
|
172
|
+
const sortSelect = document.createElement('select')
|
|
173
|
+
sortSelect.style.fontSize = '11px'
|
|
174
|
+
sortSelect.style.padding = '4px 8px'
|
|
175
|
+
sortSelect.style.borderRadius = '3px'
|
|
176
|
+
sortSelect.value = preferences.sortBy
|
|
177
|
+
|
|
178
|
+
const sortOptions = [
|
|
179
|
+
{ label: 'Name', value: 'name' },
|
|
180
|
+
{ label: 'Signal Strength', value: 'signal' },
|
|
181
|
+
{ label: 'Type', value: 'type' },
|
|
182
|
+
{ label: 'Connection', value: 'connection' },
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
for (const opt of sortOptions) {
|
|
186
|
+
const option = document.createElement('option')
|
|
187
|
+
option.value = opt.value
|
|
188
|
+
option.textContent = opt.label
|
|
189
|
+
sortSelect.appendChild(option)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
sortSelect.onchange = () => {
|
|
193
|
+
preferences.sortBy = sortSelect.value as any
|
|
194
|
+
setDiscoveryPreferences(preferences)
|
|
195
|
+
updateDiscoveryView(devices, preferences)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Search box
|
|
199
|
+
const searchInput = document.createElement('input')
|
|
200
|
+
searchInput.type = 'text'
|
|
201
|
+
searchInput.placeholder = 'Search by name, ID, or type...'
|
|
202
|
+
searchInput.style.fontSize = '11px'
|
|
203
|
+
searchInput.style.padding = '4px 8px'
|
|
204
|
+
searchInput.style.borderRadius = '3px'
|
|
205
|
+
searchInput.style.border = '1px solid #ccc'
|
|
206
|
+
searchInput.style.flex = '1'
|
|
207
|
+
searchInput.style.minWidth = '200px'
|
|
208
|
+
searchInput.style.maxWidth = '300px'
|
|
209
|
+
searchInput.value = preferences.searchQuery
|
|
210
|
+
|
|
211
|
+
let searchTimeout: NodeJS.Timeout
|
|
212
|
+
searchInput.oninput = () => {
|
|
213
|
+
clearTimeout(searchTimeout)
|
|
214
|
+
searchTimeout = setTimeout(() => {
|
|
215
|
+
preferences.searchQuery = searchInput.value
|
|
216
|
+
setDiscoveryPreferences(preferences)
|
|
217
|
+
updateDiscoveryView(devices, preferences)
|
|
218
|
+
}, 300) // Debounce search
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Assemble controls
|
|
222
|
+
controlsDiv.appendChild(filterLabel)
|
|
223
|
+
controlsDiv.appendChild(filterGroup)
|
|
224
|
+
controlsDiv.appendChild(sortLabel)
|
|
225
|
+
controlsDiv.appendChild(sortSelect)
|
|
226
|
+
controlsDiv.appendChild(searchInput)
|
|
227
|
+
|
|
228
|
+
// Clear list and add controls
|
|
229
|
+
list.innerHTML = ''
|
|
230
|
+
list.appendChild(controlsDiv)
|
|
231
|
+
|
|
232
|
+
// Display discovery list
|
|
233
|
+
list.style.display = 'block'
|
|
234
|
+
|
|
235
|
+
// Initial render with saved preferences
|
|
236
|
+
await updateDiscoveryView(devices, preferences)
|
|
237
|
+
} catch (e) {
|
|
238
|
+
uiLog.error('Discovery error:', e)
|
|
239
|
+
status.textContent = `Error: ${e instanceof Error ? e.message : 'Discovery failed'}`
|
|
240
|
+
status.classList.add('error')
|
|
241
|
+
toastError(e instanceof Error ? e.message : 'Discovery failed')
|
|
242
|
+
list.style.display = 'none'
|
|
243
|
+
} finally {
|
|
244
|
+
hideBusyUi()
|
|
245
|
+
btn.disabled = false
|
|
246
|
+
btn.textContent = '🔍 Discover Devices'
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Update discovery list with filtered and sorted devices
|
|
252
|
+
*/
|
|
253
|
+
async function updateDiscoveryView(
|
|
254
|
+
allDevices: any[],
|
|
255
|
+
preferences: {
|
|
256
|
+
connectionType: 'all' | 'ble' | 'api' | 'both' | 'ir'
|
|
257
|
+
sortBy: 'name' | 'signal' | 'type' | 'connection'
|
|
258
|
+
searchQuery: string
|
|
259
|
+
},
|
|
260
|
+
): Promise<void> {
|
|
261
|
+
// Apply filters and sort
|
|
262
|
+
const filtered = filterDevices(allDevices, preferences.connectionType, preferences.searchQuery)
|
|
263
|
+
const sorted = sortDevices(filtered, preferences.sortBy)
|
|
264
|
+
|
|
265
|
+
// Build configured device lookup for duplicate detection
|
|
266
|
+
const configured = await fetchDevices()
|
|
267
|
+
const configuredIds = new Set((configured || []).map(d => normalizeId(d?.id || d?.deviceId)))
|
|
268
|
+
|
|
269
|
+
// Render updated list
|
|
270
|
+
const ul = await renderDiscoveredDevices(sorted, {
|
|
271
|
+
configuredIds,
|
|
272
|
+
})
|
|
273
|
+
document.getElementById('discoveredDevices')?.replaceWith(ul)
|
|
274
|
+
ul.id = 'discoveredDevices'
|
|
275
|
+
|
|
276
|
+
// Update status with count
|
|
277
|
+
const status = document.getElementById('discoverStatus')
|
|
278
|
+
if (status) {
|
|
279
|
+
const totalCount = allDevices.length
|
|
280
|
+
const filteredCount = sorted.length
|
|
281
|
+
status.textContent = filteredCount === totalCount
|
|
282
|
+
? `Found ${totalCount} device(s)`
|
|
283
|
+
: `Showing ${filteredCount} of ${totalCount} device(s)`
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export async function addDeviceToConfig(device: any): Promise<void> {
|
|
288
|
+
const { addDeviceToConfig: addDevice } = await import('./devices.js')
|
|
289
|
+
await addDevice(device)
|
|
290
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const uiLog = {
|
|
2
|
+
info: (message: string, ...parameters: any[]): void => {
|
|
3
|
+
console.warn('[SwitchBot UI]', message, ...parameters)
|
|
4
|
+
},
|
|
5
|
+
warn: (message: string, ...parameters: any[]): void => {
|
|
6
|
+
console.warn('[SwitchBot UI]', message, ...parameters)
|
|
7
|
+
},
|
|
8
|
+
error: (message: string, ...parameters: any[]): void => {
|
|
9
|
+
console.error('[SwitchBot UI]', message, ...parameters)
|
|
10
|
+
},
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import './types.js'
|
|
2
|
+
import { uiLog } from './logger.js'
|
|
3
|
+
|
|
4
|
+
function callUiMethod(name: keyof HomebridgePluginUiAPI): void {
|
|
5
|
+
try {
|
|
6
|
+
const value = homebridge?.[name]
|
|
7
|
+
if (typeof value === 'function') {
|
|
8
|
+
const fn = value as () => void
|
|
9
|
+
fn()
|
|
10
|
+
}
|
|
11
|
+
} catch (e) {
|
|
12
|
+
uiLog.warn(`Homebridge UI method ${String(name)} failed:`, e)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function showBusyUi(): void {
|
|
17
|
+
callUiMethod('disableSaveButton')
|
|
18
|
+
callUiMethod('showSpinner')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function hideBusyUi(): void {
|
|
22
|
+
callUiMethod('hideSpinner')
|
|
23
|
+
callUiMethod('enableSaveButton')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function closeSettingsModal(): void {
|
|
27
|
+
callUiMethod('closeSettings')
|
|
28
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { DEVICE_TYPES } from './constants.js'
|
|
2
|
+
import { uiLog } from './logger.js'
|
|
3
|
+
|
|
4
|
+
export async function importDiscoveredDevice(device: any): Promise<{ configDeviceName: string, configDeviceType: string, address?: string } | null> {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const div = document.createElement('div')
|
|
7
|
+
div.style.position = 'fixed'
|
|
8
|
+
div.style.top = '0'
|
|
9
|
+
div.style.left = '0'
|
|
10
|
+
div.style.width = '100%'
|
|
11
|
+
div.style.height = '100%'
|
|
12
|
+
div.style.background = 'rgba(0,0,0,0.7)'
|
|
13
|
+
div.style.display = 'flex'
|
|
14
|
+
div.style.alignItems = 'center'
|
|
15
|
+
div.style.justifyContent = 'center'
|
|
16
|
+
div.style.zIndex = '9999'
|
|
17
|
+
|
|
18
|
+
const modal = document.createElement('div')
|
|
19
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor
|
|
20
|
+
modal.style.color = getComputedStyle(document.body).color
|
|
21
|
+
modal.style.padding = '0'
|
|
22
|
+
modal.style.borderRadius = '10px'
|
|
23
|
+
modal.style.minWidth = '440px'
|
|
24
|
+
modal.style.maxWidth = '90vw'
|
|
25
|
+
modal.style.boxShadow = '0 8px 32px rgba(0,0,0,0.35)'
|
|
26
|
+
modal.style.overflow = 'hidden'
|
|
27
|
+
modal.style.borderTop = '3px solid var(--switchbot-red, #ef4444)'
|
|
28
|
+
|
|
29
|
+
const title = document.createElement('h3')
|
|
30
|
+
title.textContent = 'Import Discovered Device'
|
|
31
|
+
title.style.marginTop = '0'
|
|
32
|
+
title.style.marginBottom = '16px'
|
|
33
|
+
title.style.padding = '20px 20px 0'
|
|
34
|
+
title.style.fontSize = '18px'
|
|
35
|
+
title.style.fontWeight = '600'
|
|
36
|
+
title.style.color = 'var(--switchbot-red, #ef4444)'
|
|
37
|
+
title.style.letterSpacing = '-0.02em'
|
|
38
|
+
|
|
39
|
+
const contentDiv = document.createElement('div')
|
|
40
|
+
contentDiv.style.padding = '0 20px 20px'
|
|
41
|
+
|
|
42
|
+
const nameLabel = document.createElement('label')
|
|
43
|
+
nameLabel.textContent = 'Device Name'
|
|
44
|
+
nameLabel.style.display = 'block'
|
|
45
|
+
nameLabel.style.marginBottom = '6px'
|
|
46
|
+
nameLabel.style.fontWeight = '500'
|
|
47
|
+
nameLabel.style.fontSize = '12px'
|
|
48
|
+
nameLabel.style.color = '#6b7280'
|
|
49
|
+
|
|
50
|
+
const nameInput = document.createElement('input')
|
|
51
|
+
nameInput.type = 'text'
|
|
52
|
+
nameInput.value = device.name || device.id || ''
|
|
53
|
+
nameInput.style.width = '100%'
|
|
54
|
+
nameInput.style.marginBottom = '12px'
|
|
55
|
+
nameInput.style.padding = '8px 10px'
|
|
56
|
+
nameInput.style.borderRadius = '6px'
|
|
57
|
+
nameInput.style.fontSize = '14px'
|
|
58
|
+
nameInput.style.boxSizing = 'border-box'
|
|
59
|
+
|
|
60
|
+
const typeLabel = document.createElement('label')
|
|
61
|
+
typeLabel.textContent = 'Config Device Type'
|
|
62
|
+
typeLabel.style.display = 'block'
|
|
63
|
+
typeLabel.style.marginBottom = '6px'
|
|
64
|
+
typeLabel.style.fontWeight = '500'
|
|
65
|
+
typeLabel.style.fontSize = '12px'
|
|
66
|
+
typeLabel.style.color = '#6b7280'
|
|
67
|
+
|
|
68
|
+
const typeSelect = document.createElement('select')
|
|
69
|
+
typeSelect.style.width = '100%'
|
|
70
|
+
typeSelect.style.padding = '8px 10px'
|
|
71
|
+
typeSelect.style.marginBottom = '12px'
|
|
72
|
+
typeSelect.style.borderRadius = '6px'
|
|
73
|
+
typeSelect.style.fontSize = '14px'
|
|
74
|
+
typeSelect.style.background = getComputedStyle(nameInput).background
|
|
75
|
+
typeSelect.style.color = getComputedStyle(nameInput).color
|
|
76
|
+
typeSelect.style.border = getComputedStyle(nameInput).border
|
|
77
|
+
typeSelect.style.boxSizing = 'border-box'
|
|
78
|
+
|
|
79
|
+
Object.keys(DEVICE_TYPES).forEach((categoryName) => {
|
|
80
|
+
const optgroup = document.createElement('optgroup')
|
|
81
|
+
optgroup.label = categoryName
|
|
82
|
+
|
|
83
|
+
DEVICE_TYPES[categoryName as keyof typeof DEVICE_TYPES].forEach((deviceType) => {
|
|
84
|
+
const opt = document.createElement('option')
|
|
85
|
+
opt.value = deviceType
|
|
86
|
+
opt.text = deviceType
|
|
87
|
+
const detectedType = (device.type || '').toLowerCase()
|
|
88
|
+
opt.selected = deviceType.toLowerCase() === detectedType
|
|
89
|
+
optgroup.appendChild(opt)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
typeSelect.appendChild(optgroup)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
const macLabel = document.createElement('label')
|
|
96
|
+
macLabel.textContent = 'BLE MAC Address (optional)'
|
|
97
|
+
macLabel.style.display = 'block'
|
|
98
|
+
macLabel.style.marginBottom = '6px'
|
|
99
|
+
macLabel.style.fontWeight = '500'
|
|
100
|
+
macLabel.style.fontSize = '12px'
|
|
101
|
+
macLabel.style.color = '#6b7280'
|
|
102
|
+
|
|
103
|
+
const macInput = document.createElement('input')
|
|
104
|
+
macInput.type = 'text'
|
|
105
|
+
macInput.value = device.address || ''
|
|
106
|
+
macInput.placeholder = 'AA:BB:CC:DD:EE:FF'
|
|
107
|
+
macInput.style.width = '100%'
|
|
108
|
+
macInput.style.marginBottom = '12px'
|
|
109
|
+
macInput.style.padding = '8px 10px'
|
|
110
|
+
macInput.style.borderRadius = '6px'
|
|
111
|
+
macInput.style.fontSize = '14px'
|
|
112
|
+
macInput.style.boxSizing = 'border-box'
|
|
113
|
+
|
|
114
|
+
const buttons = document.createElement('div')
|
|
115
|
+
buttons.style.display = 'flex'
|
|
116
|
+
buttons.style.gap = '10px'
|
|
117
|
+
buttons.style.justifyContent = 'flex-end'
|
|
118
|
+
buttons.style.marginTop = '18px'
|
|
119
|
+
buttons.style.paddingTop = '18px'
|
|
120
|
+
buttons.style.borderTop = '1px solid rgba(0, 0, 0, 0.08)'
|
|
121
|
+
|
|
122
|
+
const cancelBtn = document.createElement('button')
|
|
123
|
+
cancelBtn.textContent = 'Cancel'
|
|
124
|
+
cancelBtn.className = 'secondary'
|
|
125
|
+
cancelBtn.style.background = '#6b7280'
|
|
126
|
+
cancelBtn.style.padding = '8px 16px'
|
|
127
|
+
cancelBtn.style.fontSize = '13px'
|
|
128
|
+
|
|
129
|
+
const importBtn = document.createElement('button')
|
|
130
|
+
importBtn.textContent = 'Add to Config'
|
|
131
|
+
importBtn.style.background = 'var(--switchbot-red, #ef4444)'
|
|
132
|
+
importBtn.style.padding = '8px 20px'
|
|
133
|
+
importBtn.style.fontSize = '13px'
|
|
134
|
+
|
|
135
|
+
const cleanup = (result: { configDeviceName: string, configDeviceType: string, address?: string } | null) => {
|
|
136
|
+
div.remove()
|
|
137
|
+
resolve(result)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
cancelBtn.onclick = () => cleanup(null)
|
|
141
|
+
importBtn.onclick = () => cleanup({
|
|
142
|
+
configDeviceName: nameInput.value || device.name || device.id,
|
|
143
|
+
configDeviceType: typeSelect.value || device.type,
|
|
144
|
+
address: macInput.value || undefined,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
div.addEventListener('click', (event) => {
|
|
148
|
+
if (event.target === div) {
|
|
149
|
+
cleanup(null)
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
buttons.appendChild(cancelBtn)
|
|
154
|
+
buttons.appendChild(importBtn)
|
|
155
|
+
contentDiv.appendChild(nameLabel)
|
|
156
|
+
contentDiv.appendChild(nameInput)
|
|
157
|
+
contentDiv.appendChild(typeLabel)
|
|
158
|
+
contentDiv.appendChild(typeSelect)
|
|
159
|
+
contentDiv.appendChild(macLabel)
|
|
160
|
+
contentDiv.appendChild(macInput)
|
|
161
|
+
contentDiv.appendChild(buttons)
|
|
162
|
+
|
|
163
|
+
modal.appendChild(title)
|
|
164
|
+
modal.appendChild(contentDiv)
|
|
165
|
+
div.appendChild(modal)
|
|
166
|
+
document.body.appendChild(div)
|
|
167
|
+
nameInput.focus()
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function editDevice(device: any): Promise<void> {
|
|
172
|
+
// Create modal dialog for editing
|
|
173
|
+
const div = document.createElement('div')
|
|
174
|
+
div.style.position = 'fixed'
|
|
175
|
+
div.style.top = '0'
|
|
176
|
+
div.style.left = '0'
|
|
177
|
+
div.style.width = '100%'
|
|
178
|
+
div.style.height = '100%'
|
|
179
|
+
div.style.background = 'rgba(0,0,0,0.7)'
|
|
180
|
+
div.style.display = 'flex'
|
|
181
|
+
div.style.alignItems = 'center'
|
|
182
|
+
div.style.justifyContent = 'center'
|
|
183
|
+
div.style.zIndex = '9999'
|
|
184
|
+
|
|
185
|
+
const modal = document.createElement('div')
|
|
186
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor
|
|
187
|
+
modal.style.color = getComputedStyle(document.body).color
|
|
188
|
+
modal.style.padding = '0'
|
|
189
|
+
modal.style.borderRadius = '10px'
|
|
190
|
+
modal.style.minWidth = '440px'
|
|
191
|
+
modal.style.maxWidth = '90vw'
|
|
192
|
+
modal.style.boxShadow = '0 8px 32px rgba(0,0,0,0.35)'
|
|
193
|
+
modal.style.overflow = 'hidden'
|
|
194
|
+
modal.style.borderTop = '3px solid var(--switchbot-red, #ef4444)'
|
|
195
|
+
|
|
196
|
+
const title = document.createElement('h3')
|
|
197
|
+
title.textContent = 'Edit Device'
|
|
198
|
+
title.style.marginTop = '0'
|
|
199
|
+
title.style.marginBottom = '16px'
|
|
200
|
+
title.style.padding = '20px 20px 0'
|
|
201
|
+
title.style.fontSize = '18px'
|
|
202
|
+
title.style.fontWeight = '600'
|
|
203
|
+
title.style.color = 'var(--switchbot-red, #ef4444)'
|
|
204
|
+
title.style.letterSpacing = '-0.02em'
|
|
205
|
+
|
|
206
|
+
const contentDiv = document.createElement('div')
|
|
207
|
+
contentDiv.style.padding = '0 20px 20px'
|
|
208
|
+
|
|
209
|
+
const nameLabel = document.createElement('label')
|
|
210
|
+
nameLabel.textContent = 'Device Name'
|
|
211
|
+
nameLabel.style.display = 'block'
|
|
212
|
+
nameLabel.style.marginBottom = '6px'
|
|
213
|
+
nameLabel.style.fontWeight = '500'
|
|
214
|
+
nameLabel.style.fontSize = '12px'
|
|
215
|
+
nameLabel.style.color = '#6b7280'
|
|
216
|
+
|
|
217
|
+
const nameInput = document.createElement('input')
|
|
218
|
+
nameInput.type = 'text'
|
|
219
|
+
nameInput.value = device.name || device.id
|
|
220
|
+
nameInput.style.width = '100%'
|
|
221
|
+
nameInput.style.marginBottom = '12px'
|
|
222
|
+
nameInput.style.padding = '8px 10px'
|
|
223
|
+
nameInput.style.borderRadius = '6px'
|
|
224
|
+
nameInput.style.fontSize = '14px'
|
|
225
|
+
nameInput.style.boxSizing = 'border-box'
|
|
226
|
+
nameInput.style.transition = 'border-color 0.2s ease'
|
|
227
|
+
|
|
228
|
+
// Read-only API device type field
|
|
229
|
+
const apiTypeLabel = document.createElement('label')
|
|
230
|
+
apiTypeLabel.textContent = 'Device Type (API - Read Only)'
|
|
231
|
+
apiTypeLabel.style.display = 'block'
|
|
232
|
+
apiTypeLabel.style.marginBottom = '6px'
|
|
233
|
+
apiTypeLabel.style.fontWeight = '500'
|
|
234
|
+
apiTypeLabel.style.fontSize = '12px'
|
|
235
|
+
apiTypeLabel.style.color = '#6b7280'
|
|
236
|
+
|
|
237
|
+
const apiTypeInput = document.createElement('input')
|
|
238
|
+
apiTypeInput.type = 'text'
|
|
239
|
+
apiTypeInput.value = device.deviceType || device.type || 'Unknown'
|
|
240
|
+
apiTypeInput.readOnly = true
|
|
241
|
+
apiTypeInput.style.width = '100%'
|
|
242
|
+
apiTypeInput.style.marginBottom = '12px'
|
|
243
|
+
apiTypeInput.style.padding = '8px 10px'
|
|
244
|
+
apiTypeInput.style.borderRadius = '6px'
|
|
245
|
+
apiTypeInput.style.fontSize = '13px'
|
|
246
|
+
apiTypeInput.style.opacity = '0.6'
|
|
247
|
+
apiTypeInput.style.cursor = 'not-allowed'
|
|
248
|
+
apiTypeInput.style.boxSizing = 'border-box'
|
|
249
|
+
apiTypeInput.style.backgroundColor = '#f9fafb'
|
|
250
|
+
|
|
251
|
+
// Editable config device type dropdown
|
|
252
|
+
const typeLabel = document.createElement('label')
|
|
253
|
+
typeLabel.textContent = 'Config Device Type (Override)'
|
|
254
|
+
typeLabel.style.display = 'block'
|
|
255
|
+
typeLabel.style.marginBottom = '6px'
|
|
256
|
+
typeLabel.style.fontWeight = '500'
|
|
257
|
+
typeLabel.style.fontSize = '12px'
|
|
258
|
+
typeLabel.style.color = '#6b7280'
|
|
259
|
+
|
|
260
|
+
const typeSelect = document.createElement('select')
|
|
261
|
+
typeSelect.style.width = '100%'
|
|
262
|
+
typeSelect.style.padding = '8px 10px'
|
|
263
|
+
typeSelect.style.marginBottom = '12px'
|
|
264
|
+
typeSelect.style.borderRadius = '6px'
|
|
265
|
+
typeSelect.style.fontSize = '14px'
|
|
266
|
+
typeSelect.style.background = getComputedStyle(nameInput).background
|
|
267
|
+
typeSelect.style.color = getComputedStyle(nameInput).color
|
|
268
|
+
typeSelect.style.border = getComputedStyle(nameInput).border
|
|
269
|
+
typeSelect.style.boxSizing = 'border-box'
|
|
270
|
+
typeSelect.style.cursor = 'pointer'
|
|
271
|
+
typeSelect.style.transition = 'border-color 0.2s ease'
|
|
272
|
+
|
|
273
|
+
// Add option groups with all API device types
|
|
274
|
+
Object.keys(DEVICE_TYPES).forEach((categoryName) => {
|
|
275
|
+
const optgroup = document.createElement('optgroup')
|
|
276
|
+
optgroup.label = categoryName
|
|
277
|
+
|
|
278
|
+
DEVICE_TYPES[categoryName as keyof typeof DEVICE_TYPES].forEach((deviceType) => {
|
|
279
|
+
const opt = document.createElement('option')
|
|
280
|
+
opt.value = deviceType
|
|
281
|
+
opt.text = deviceType
|
|
282
|
+
|
|
283
|
+
// Select current configDeviceType if set, otherwise match API deviceType
|
|
284
|
+
const currentType = device.configDeviceType || device.deviceType || device.type || ''
|
|
285
|
+
opt.selected = currentType === deviceType
|
|
286
|
+
optgroup.appendChild(opt)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
typeSelect.appendChild(optgroup)
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const errorMessage = document.createElement('div')
|
|
293
|
+
errorMessage.style.color = 'var(--switchbot-red, #ef4444)'
|
|
294
|
+
errorMessage.style.marginBottom = '12px'
|
|
295
|
+
errorMessage.style.fontSize = '12px'
|
|
296
|
+
errorMessage.style.display = 'none'
|
|
297
|
+
errorMessage.style.padding = '8px 10px'
|
|
298
|
+
errorMessage.style.background = 'var(--switchbot-red-light, #fee2e2)'
|
|
299
|
+
errorMessage.style.borderRadius = '6px'
|
|
300
|
+
errorMessage.style.fontWeight = '500'
|
|
301
|
+
|
|
302
|
+
const buttons = document.createElement('div')
|
|
303
|
+
buttons.style.display = 'flex'
|
|
304
|
+
buttons.style.gap = '10px'
|
|
305
|
+
buttons.style.justifyContent = 'flex-end'
|
|
306
|
+
buttons.style.marginTop = '18px'
|
|
307
|
+
buttons.style.paddingTop = '18px'
|
|
308
|
+
buttons.style.borderTop = '1px solid rgba(0, 0, 0, 0.08)'
|
|
309
|
+
|
|
310
|
+
const cancelBtn = document.createElement('button')
|
|
311
|
+
cancelBtn.textContent = 'Cancel'
|
|
312
|
+
cancelBtn.className = 'secondary'
|
|
313
|
+
cancelBtn.style.background = '#6b7280'
|
|
314
|
+
cancelBtn.style.padding = '8px 16px'
|
|
315
|
+
cancelBtn.style.fontSize = '13px'
|
|
316
|
+
cancelBtn.onclick = () => div.remove()
|
|
317
|
+
|
|
318
|
+
const saveBtn = document.createElement('button')
|
|
319
|
+
saveBtn.textContent = 'Save'
|
|
320
|
+
saveBtn.style.background = 'var(--switchbot-red, #ef4444)'
|
|
321
|
+
saveBtn.style.padding = '8px 20px'
|
|
322
|
+
saveBtn.style.fontSize = '13px'
|
|
323
|
+
saveBtn.onclick = async () => {
|
|
324
|
+
try {
|
|
325
|
+
const { updateDevice, syncParentPluginConfigFromDisk, fetchDevices } = await import('./api.js')
|
|
326
|
+
const { renderDeviceList } = await import('./render.js')
|
|
327
|
+
|
|
328
|
+
const params = {
|
|
329
|
+
deviceId: device.id,
|
|
330
|
+
configDeviceName: nameInput.value || undefined,
|
|
331
|
+
configDeviceType: typeSelect.value,
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
await updateDevice(params.deviceId, params.configDeviceName, params.configDeviceType)
|
|
335
|
+
await syncParentPluginConfigFromDisk()
|
|
336
|
+
|
|
337
|
+
// Refresh device list
|
|
338
|
+
uiLog.info('[Edit Device] Refreshing device list after update')
|
|
339
|
+
const list = await fetchDevices()
|
|
340
|
+
renderDeviceList(list)
|
|
341
|
+
div.remove()
|
|
342
|
+
} catch (e) {
|
|
343
|
+
uiLog.error('Update error:', e)
|
|
344
|
+
errorMessage.textContent = `Error: ${e instanceof Error ? e.message : 'Failed to update device'}`
|
|
345
|
+
errorMessage.style.display = 'block'
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
buttons.appendChild(cancelBtn)
|
|
350
|
+
buttons.appendChild(saveBtn)
|
|
351
|
+
|
|
352
|
+
contentDiv.appendChild(nameLabel)
|
|
353
|
+
contentDiv.appendChild(nameInput)
|
|
354
|
+
contentDiv.appendChild(apiTypeLabel)
|
|
355
|
+
contentDiv.appendChild(apiTypeInput)
|
|
356
|
+
contentDiv.appendChild(typeLabel)
|
|
357
|
+
contentDiv.appendChild(typeSelect)
|
|
358
|
+
contentDiv.appendChild(errorMessage)
|
|
359
|
+
contentDiv.appendChild(buttons)
|
|
360
|
+
|
|
361
|
+
modal.appendChild(title)
|
|
362
|
+
modal.appendChild(contentDiv)
|
|
363
|
+
|
|
364
|
+
div.appendChild(modal)
|
|
365
|
+
document.body.appendChild(div)
|
|
366
|
+
nameInput.focus()
|
|
367
|
+
}
|