@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,1815 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/homebridge-ui/public/js/types.ts
|
|
12
|
+
var init_types = __esm({
|
|
13
|
+
"src/homebridge-ui/public/js/types.ts"() {
|
|
14
|
+
"use strict";
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// src/homebridge-ui/public/js/logger.ts
|
|
19
|
+
var uiLog;
|
|
20
|
+
var init_logger = __esm({
|
|
21
|
+
"src/homebridge-ui/public/js/logger.ts"() {
|
|
22
|
+
"use strict";
|
|
23
|
+
uiLog = {
|
|
24
|
+
info: (message, ...parameters) => {
|
|
25
|
+
console.warn("[SwitchBot UI]", message, ...parameters);
|
|
26
|
+
},
|
|
27
|
+
warn: (message, ...parameters) => {
|
|
28
|
+
console.warn("[SwitchBot UI]", message, ...parameters);
|
|
29
|
+
},
|
|
30
|
+
error: (message, ...parameters) => {
|
|
31
|
+
console.error("[SwitchBot UI]", message, ...parameters);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/homebridge-ui/public/js/api.ts
|
|
38
|
+
var api_exports = {};
|
|
39
|
+
__export(api_exports, {
|
|
40
|
+
addDevice: () => addDevice,
|
|
41
|
+
addDevicesInBulk: () => addDevicesInBulk,
|
|
42
|
+
deleteAllDevices: () => deleteAllDevices,
|
|
43
|
+
deleteDevice: () => deleteDevice,
|
|
44
|
+
discoverDevices: () => discoverDevices,
|
|
45
|
+
fetchCredentialStatus: () => fetchCredentialStatus,
|
|
46
|
+
fetchDevices: () => fetchDevices,
|
|
47
|
+
saveCredentials: () => saveCredentials,
|
|
48
|
+
syncParentPluginConfigFromDisk: () => syncParentPluginConfigFromDisk,
|
|
49
|
+
updateDevice: () => updateDevice
|
|
50
|
+
});
|
|
51
|
+
function isSwitchBotPlatformConfig(block) {
|
|
52
|
+
const platformName = String(block?.platform || block?.name || "").toLowerCase();
|
|
53
|
+
return platformName === "switchbot" || platformName === "@switchbot/homebridge-switchbot" || platformName.includes("switchbot");
|
|
54
|
+
}
|
|
55
|
+
async function syncParentPluginConfigFromDisk(autoSave = false) {
|
|
56
|
+
try {
|
|
57
|
+
if (typeof homebridge.getPluginConfig !== "function" || typeof homebridge.updatePluginConfig !== "function") {
|
|
58
|
+
uiLog.warn("Parent config sync API not available");
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const diskResp = await homebridge.request("/platform-config", {});
|
|
62
|
+
if (!diskResp || diskResp.success === false || !diskResp.data) {
|
|
63
|
+
uiLog.warn("Failed to fetch fresh platform config from disk");
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const pluginConfigBlocks = await homebridge.getPluginConfig();
|
|
67
|
+
if (!Array.isArray(pluginConfigBlocks) || !pluginConfigBlocks.length) {
|
|
68
|
+
uiLog.warn("No plugin config blocks returned from Homebridge");
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const index = pluginConfigBlocks.findIndex((block) => isSwitchBotPlatformConfig(block));
|
|
72
|
+
if (index < 0) {
|
|
73
|
+
uiLog.warn("SwitchBot platform block not found in Homebridge plugin config");
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
pluginConfigBlocks[index] = diskResp.data;
|
|
77
|
+
await homebridge.updatePluginConfig(pluginConfigBlocks);
|
|
78
|
+
if (autoSave && typeof homebridge.savePluginConfig === "function") {
|
|
79
|
+
uiLog.info("Auto-saving config to disk...");
|
|
80
|
+
await homebridge.savePluginConfig();
|
|
81
|
+
uiLog.info("Config saved successfully");
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
uiLog.warn("Failed to sync parent plugin config cache:", e);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function fetchCredentialStatus() {
|
|
90
|
+
try {
|
|
91
|
+
const resp = await homebridge.request("/credentials", {});
|
|
92
|
+
uiLog.info("Load credentials response:", resp);
|
|
93
|
+
if (!resp || resp.success === false) {
|
|
94
|
+
uiLog.error("Failed to load credentials:", resp);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return resp.data || {};
|
|
98
|
+
} catch (e) {
|
|
99
|
+
uiLog.error("Error loading credentials:", e);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function saveCredentials(token, secret) {
|
|
104
|
+
try {
|
|
105
|
+
uiLog.info("Saving credentials...");
|
|
106
|
+
const resp = await homebridge.request("/credentials", { token, secret });
|
|
107
|
+
uiLog.info("Save response:", resp);
|
|
108
|
+
if (!resp || resp.success === false) {
|
|
109
|
+
throw new Error(resp?.message || "Save failed");
|
|
110
|
+
}
|
|
111
|
+
return resp.data || resp;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function fetchDevices() {
|
|
117
|
+
try {
|
|
118
|
+
const resp = await homebridge.request("/devices", {});
|
|
119
|
+
if (!resp || resp.success === false) {
|
|
120
|
+
throw new Error(resp?.data?.message || "request failed");
|
|
121
|
+
}
|
|
122
|
+
return resp.data || [];
|
|
123
|
+
} catch (e) {
|
|
124
|
+
uiLog.error("Error fetching devices:", e);
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function discoverDevices() {
|
|
129
|
+
try {
|
|
130
|
+
const resp = await homebridge.request("/discover", {});
|
|
131
|
+
uiLog.info("Discover response:", resp);
|
|
132
|
+
if (!resp || resp.success === false) {
|
|
133
|
+
throw new Error(resp?.data?.message || "Discovery failed");
|
|
134
|
+
}
|
|
135
|
+
return resp.data || [];
|
|
136
|
+
} catch (e) {
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function addDevice(deviceId, name, type, options) {
|
|
141
|
+
try {
|
|
142
|
+
const payload = { deviceId, name, type };
|
|
143
|
+
if (options?.address) {
|
|
144
|
+
payload.address = options.address;
|
|
145
|
+
}
|
|
146
|
+
if (options?.model) {
|
|
147
|
+
payload.model = options.model;
|
|
148
|
+
}
|
|
149
|
+
if (options?.rssi !== void 0 && options?.rssi !== null && options?.rssi !== 0) {
|
|
150
|
+
payload.rssi = options.rssi;
|
|
151
|
+
}
|
|
152
|
+
uiLog.info("Adding device to config:", payload);
|
|
153
|
+
const resp = await homebridge.request("/add-device", payload);
|
|
154
|
+
uiLog.info("Add device response:", resp);
|
|
155
|
+
if (!resp || resp.success === false) {
|
|
156
|
+
throw new Error(resp?.data?.message || "Failed to add device");
|
|
157
|
+
}
|
|
158
|
+
return resp.data || resp;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function addDevicesInBulk(devices) {
|
|
164
|
+
try {
|
|
165
|
+
const resp = await homebridge.request("/add-devices", { devices });
|
|
166
|
+
uiLog.info("Bulk add response:", resp);
|
|
167
|
+
if (!resp || resp.success === false) {
|
|
168
|
+
throw new Error(resp?.data?.message || "Bulk add failed");
|
|
169
|
+
}
|
|
170
|
+
return resp.data || resp;
|
|
171
|
+
} catch (e) {
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async function updateDevice(deviceId, configDeviceName, configDeviceType) {
|
|
176
|
+
try {
|
|
177
|
+
const params = { deviceId };
|
|
178
|
+
if (configDeviceName) {
|
|
179
|
+
params.configDeviceName = configDeviceName;
|
|
180
|
+
}
|
|
181
|
+
if (configDeviceType) {
|
|
182
|
+
params.configDeviceType = configDeviceType;
|
|
183
|
+
}
|
|
184
|
+
uiLog.info("[Update Device] Sending update request with params:", params);
|
|
185
|
+
const resp = await homebridge.request("/update-device", params);
|
|
186
|
+
uiLog.info("[Update Device] Update response:", resp);
|
|
187
|
+
if (!resp || resp.success === false) {
|
|
188
|
+
throw new Error(resp?.data?.message || "Failed to update device");
|
|
189
|
+
}
|
|
190
|
+
return resp.data || resp;
|
|
191
|
+
} catch (e) {
|
|
192
|
+
throw e;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function deleteDevice(deviceId) {
|
|
196
|
+
try {
|
|
197
|
+
uiLog.info("Sending delete request for deviceId:", deviceId);
|
|
198
|
+
const resp = await homebridge.request("/delete-device", { deviceId });
|
|
199
|
+
uiLog.info("Delete response:", resp);
|
|
200
|
+
if (!resp || resp.success === false) {
|
|
201
|
+
throw new Error(resp?.data?.message || "Failed to delete device");
|
|
202
|
+
}
|
|
203
|
+
return resp.data || resp;
|
|
204
|
+
} catch (e) {
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function deleteAllDevices() {
|
|
209
|
+
try {
|
|
210
|
+
uiLog.info("Sending delete all devices request");
|
|
211
|
+
const resp = await homebridge.request("/delete-all-devices", {});
|
|
212
|
+
uiLog.info("Delete all response:", resp);
|
|
213
|
+
if (!resp || resp.success === false) {
|
|
214
|
+
throw new Error(resp?.data?.message || "Failed to delete all devices");
|
|
215
|
+
}
|
|
216
|
+
return resp.data || resp;
|
|
217
|
+
} catch (e) {
|
|
218
|
+
throw e;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
var init_api = __esm({
|
|
222
|
+
"src/homebridge-ui/public/js/api.ts"() {
|
|
223
|
+
"use strict";
|
|
224
|
+
init_types();
|
|
225
|
+
init_logger();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// src/homebridge-ui/public/js/modal.ts
|
|
230
|
+
function callUiMethod(name) {
|
|
231
|
+
try {
|
|
232
|
+
const value = homebridge?.[name];
|
|
233
|
+
if (typeof value === "function") {
|
|
234
|
+
const fn = value;
|
|
235
|
+
fn();
|
|
236
|
+
}
|
|
237
|
+
} catch (e) {
|
|
238
|
+
uiLog.warn(`Homebridge UI method ${String(name)} failed:`, e);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function showBusyUi() {
|
|
242
|
+
callUiMethod("disableSaveButton");
|
|
243
|
+
callUiMethod("showSpinner");
|
|
244
|
+
}
|
|
245
|
+
function hideBusyUi() {
|
|
246
|
+
callUiMethod("hideSpinner");
|
|
247
|
+
callUiMethod("enableSaveButton");
|
|
248
|
+
}
|
|
249
|
+
var init_modal = __esm({
|
|
250
|
+
"src/homebridge-ui/public/js/modal.ts"() {
|
|
251
|
+
"use strict";
|
|
252
|
+
init_types();
|
|
253
|
+
init_logger();
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// src/homebridge-ui/public/js/toast.ts
|
|
258
|
+
function showToast(method, message, title = "SwitchBot") {
|
|
259
|
+
try {
|
|
260
|
+
const toast = homebridge?.toast;
|
|
261
|
+
const fn = toast?.[method];
|
|
262
|
+
if (typeof fn === "function") {
|
|
263
|
+
fn(message, title);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
uiLog.info(`[Toast:${method}] ${title} - ${message}`);
|
|
267
|
+
} catch (e) {
|
|
268
|
+
uiLog.warn(`Toast ${method} failed:`, e);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function toastSuccess(message, title) {
|
|
272
|
+
showToast("success", message, title);
|
|
273
|
+
}
|
|
274
|
+
function toastError(message, title) {
|
|
275
|
+
showToast("error", message, title);
|
|
276
|
+
}
|
|
277
|
+
function toastWarning(message, title) {
|
|
278
|
+
showToast("warning", message, title);
|
|
279
|
+
}
|
|
280
|
+
function toastInfo(message, title) {
|
|
281
|
+
showToast("info", message, title);
|
|
282
|
+
}
|
|
283
|
+
var init_toast = __esm({
|
|
284
|
+
"src/homebridge-ui/public/js/toast.ts"() {
|
|
285
|
+
"use strict";
|
|
286
|
+
init_types();
|
|
287
|
+
init_logger();
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// src/homebridge-ui/public/js/discovery.ts
|
|
292
|
+
var discovery_exports = {};
|
|
293
|
+
__export(discovery_exports, {
|
|
294
|
+
addDeviceToConfig: () => addDeviceToConfig,
|
|
295
|
+
discoverDevices: () => discoverDevices2
|
|
296
|
+
});
|
|
297
|
+
function normalizeId(value) {
|
|
298
|
+
return String(value ?? "").trim().toLowerCase();
|
|
299
|
+
}
|
|
300
|
+
async function discoverDevices2() {
|
|
301
|
+
const btn = document.getElementById("discoverBtn");
|
|
302
|
+
const status = document.getElementById("discoverStatus");
|
|
303
|
+
const list = document.getElementById("discoveredList");
|
|
304
|
+
const autoAddAll = document.getElementById("autoAddAllCheckbox")?.checked;
|
|
305
|
+
if (!btn || !status || !list) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
showBusyUi();
|
|
310
|
+
btn.disabled = true;
|
|
311
|
+
btn.textContent = "\u{1F50D} Discovering...";
|
|
312
|
+
status.textContent = "Searching SwitchBot account...";
|
|
313
|
+
status.classList.remove("error");
|
|
314
|
+
const devicesRaw = await discoverDevices();
|
|
315
|
+
uiLog.info("Discover response:", devicesRaw);
|
|
316
|
+
const devices = devicesRaw.filter((d, index, arr) => !!d?.id && arr.findIndex((x) => x?.id === d.id) === index);
|
|
317
|
+
if (!devices.length) {
|
|
318
|
+
status.textContent = "No devices found in your SwitchBot account";
|
|
319
|
+
toastInfo("No devices found in your SwitchBot account");
|
|
320
|
+
list.style.display = "none";
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (autoAddAll) {
|
|
324
|
+
status.textContent = `Auto-adding ${devices.length} device(s)...`;
|
|
325
|
+
try {
|
|
326
|
+
const bulkResult = await addDevicesInBulk(
|
|
327
|
+
devices.map((d) => ({
|
|
328
|
+
deviceId: d.id,
|
|
329
|
+
name: d.name,
|
|
330
|
+
type: d.type,
|
|
331
|
+
rssi: d.rssi,
|
|
332
|
+
address: d.address,
|
|
333
|
+
model: d.model
|
|
334
|
+
}))
|
|
335
|
+
);
|
|
336
|
+
uiLog.info("Bulk add response:", bulkResult);
|
|
337
|
+
if (!bulkResult || bulkResult.success === false) {
|
|
338
|
+
throw new Error(bulkResult?.data?.message || "Bulk add failed");
|
|
339
|
+
}
|
|
340
|
+
const addedCount = bulkResult?.addedCount ?? bulkResult?.data?.addedCount ?? 0;
|
|
341
|
+
const skippedCount = bulkResult?.skippedCount ?? bulkResult?.data?.skippedCount ?? 0;
|
|
342
|
+
status.textContent = `\u2713 Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ""}`;
|
|
343
|
+
if (addedCount > 0) {
|
|
344
|
+
toastSuccess(`Added ${addedCount} device(s)${skippedCount > 0 ? ` (${skippedCount} skipped)` : ""}`);
|
|
345
|
+
} else if (skippedCount > 0) {
|
|
346
|
+
toastWarning(`No new devices were added (${skippedCount} skipped)`);
|
|
347
|
+
}
|
|
348
|
+
status.classList.remove("error");
|
|
349
|
+
list.style.display = "none";
|
|
350
|
+
if (devices.length > 0) {
|
|
351
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
352
|
+
status.textContent += synced ? " - Config saved automatically." : " - Warning: config may not persist until you close/reopen settings.";
|
|
353
|
+
if (synced) {
|
|
354
|
+
toastSuccess("Configuration synced and saved automatically");
|
|
355
|
+
} else {
|
|
356
|
+
toastWarning("Configuration sync failed; close and reopen settings before Save");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
} catch (e) {
|
|
360
|
+
uiLog.error("Bulk add error:", e);
|
|
361
|
+
status.textContent = `\u2717 Error: ${e instanceof Error ? e.message : "Failed to add devices"}`;
|
|
362
|
+
status.classList.add("error");
|
|
363
|
+
toastError(e instanceof Error ? e.message : "Failed to add devices");
|
|
364
|
+
}
|
|
365
|
+
await loadConfiguredDevices();
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
status.textContent = `Found ${devices.length} device(s)`;
|
|
369
|
+
const controlsDiv = document.createElement("div");
|
|
370
|
+
controlsDiv.style.cssText = "margin-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center;";
|
|
371
|
+
const preferences = getDiscoveryPreferences();
|
|
372
|
+
const filterLabel = document.createElement("label");
|
|
373
|
+
filterLabel.style.fontSize = "12px";
|
|
374
|
+
filterLabel.style.fontWeight = "500";
|
|
375
|
+
filterLabel.textContent = "Filter:";
|
|
376
|
+
const filterGroup = document.createElement("div");
|
|
377
|
+
filterGroup.style.display = "flex";
|
|
378
|
+
filterGroup.style.gap = "4px";
|
|
379
|
+
const filterOptions = [
|
|
380
|
+
{ label: "All", value: "all" },
|
|
381
|
+
{ label: "BLE", value: "ble" },
|
|
382
|
+
{ label: "API", value: "api" },
|
|
383
|
+
{ label: "Both", value: "both" },
|
|
384
|
+
{ label: "IR", value: "ir" }
|
|
385
|
+
];
|
|
386
|
+
for (const option of filterOptions) {
|
|
387
|
+
const btn2 = document.createElement("button");
|
|
388
|
+
btn2.textContent = option.label;
|
|
389
|
+
btn2.style.padding = "4px 8px";
|
|
390
|
+
btn2.style.fontSize = "11px";
|
|
391
|
+
btn2.style.borderRadius = "3px";
|
|
392
|
+
btn2.style.cursor = "pointer";
|
|
393
|
+
btn2.style.border = preferences.connectionType === option.value ? "2px solid #007AFF" : "1px solid #ccc";
|
|
394
|
+
btn2.style.backgroundColor = preferences.connectionType === option.value ? "#f0f7ff" : "#fff";
|
|
395
|
+
btn2.style.color = preferences.connectionType === option.value ? "#1d4ed8" : "#374151";
|
|
396
|
+
btn2.onclick = () => {
|
|
397
|
+
preferences.connectionType = option.value;
|
|
398
|
+
setDiscoveryPreferences(preferences);
|
|
399
|
+
updateDiscoveryView(devices, preferences);
|
|
400
|
+
for (const b of Array.from(filterGroup.querySelectorAll("button"))) {
|
|
401
|
+
;
|
|
402
|
+
b.style.border = "1px solid #ccc";
|
|
403
|
+
b.style.backgroundColor = "#fff";
|
|
404
|
+
b.style.color = "#374151";
|
|
405
|
+
}
|
|
406
|
+
btn2.style.border = "2px solid #007AFF";
|
|
407
|
+
btn2.style.backgroundColor = "#f0f7ff";
|
|
408
|
+
btn2.style.color = "#1d4ed8";
|
|
409
|
+
};
|
|
410
|
+
filterGroup.appendChild(btn2);
|
|
411
|
+
}
|
|
412
|
+
const sortLabel = document.createElement("label");
|
|
413
|
+
sortLabel.style.fontSize = "12px";
|
|
414
|
+
sortLabel.style.fontWeight = "500";
|
|
415
|
+
sortLabel.style.marginLeft = "8px";
|
|
416
|
+
sortLabel.textContent = "Sort:";
|
|
417
|
+
const sortSelect = document.createElement("select");
|
|
418
|
+
sortSelect.style.fontSize = "11px";
|
|
419
|
+
sortSelect.style.padding = "4px 8px";
|
|
420
|
+
sortSelect.style.borderRadius = "3px";
|
|
421
|
+
sortSelect.value = preferences.sortBy;
|
|
422
|
+
const sortOptions = [
|
|
423
|
+
{ label: "Name", value: "name" },
|
|
424
|
+
{ label: "Signal Strength", value: "signal" },
|
|
425
|
+
{ label: "Type", value: "type" },
|
|
426
|
+
{ label: "Connection", value: "connection" }
|
|
427
|
+
];
|
|
428
|
+
for (const opt of sortOptions) {
|
|
429
|
+
const option = document.createElement("option");
|
|
430
|
+
option.value = opt.value;
|
|
431
|
+
option.textContent = opt.label;
|
|
432
|
+
sortSelect.appendChild(option);
|
|
433
|
+
}
|
|
434
|
+
sortSelect.onchange = () => {
|
|
435
|
+
preferences.sortBy = sortSelect.value;
|
|
436
|
+
setDiscoveryPreferences(preferences);
|
|
437
|
+
updateDiscoveryView(devices, preferences);
|
|
438
|
+
};
|
|
439
|
+
const searchInput = document.createElement("input");
|
|
440
|
+
searchInput.type = "text";
|
|
441
|
+
searchInput.placeholder = "Search by name, ID, or type...";
|
|
442
|
+
searchInput.style.fontSize = "11px";
|
|
443
|
+
searchInput.style.padding = "4px 8px";
|
|
444
|
+
searchInput.style.borderRadius = "3px";
|
|
445
|
+
searchInput.style.border = "1px solid #ccc";
|
|
446
|
+
searchInput.style.flex = "1";
|
|
447
|
+
searchInput.style.minWidth = "200px";
|
|
448
|
+
searchInput.style.maxWidth = "300px";
|
|
449
|
+
searchInput.value = preferences.searchQuery;
|
|
450
|
+
let searchTimeout;
|
|
451
|
+
searchInput.oninput = () => {
|
|
452
|
+
clearTimeout(searchTimeout);
|
|
453
|
+
searchTimeout = setTimeout(() => {
|
|
454
|
+
preferences.searchQuery = searchInput.value;
|
|
455
|
+
setDiscoveryPreferences(preferences);
|
|
456
|
+
updateDiscoveryView(devices, preferences);
|
|
457
|
+
}, 300);
|
|
458
|
+
};
|
|
459
|
+
controlsDiv.appendChild(filterLabel);
|
|
460
|
+
controlsDiv.appendChild(filterGroup);
|
|
461
|
+
controlsDiv.appendChild(sortLabel);
|
|
462
|
+
controlsDiv.appendChild(sortSelect);
|
|
463
|
+
controlsDiv.appendChild(searchInput);
|
|
464
|
+
list.innerHTML = "";
|
|
465
|
+
list.appendChild(controlsDiv);
|
|
466
|
+
list.style.display = "block";
|
|
467
|
+
await updateDiscoveryView(devices, preferences);
|
|
468
|
+
} catch (e) {
|
|
469
|
+
uiLog.error("Discovery error:", e);
|
|
470
|
+
status.textContent = `Error: ${e instanceof Error ? e.message : "Discovery failed"}`;
|
|
471
|
+
status.classList.add("error");
|
|
472
|
+
toastError(e instanceof Error ? e.message : "Discovery failed");
|
|
473
|
+
list.style.display = "none";
|
|
474
|
+
} finally {
|
|
475
|
+
hideBusyUi();
|
|
476
|
+
btn.disabled = false;
|
|
477
|
+
btn.textContent = "\u{1F50D} Discover Devices";
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
async function updateDiscoveryView(allDevices, preferences) {
|
|
481
|
+
const filtered = filterDevices(allDevices, preferences.connectionType, preferences.searchQuery);
|
|
482
|
+
const sorted = sortDevices(filtered, preferences.sortBy);
|
|
483
|
+
const configured = await fetchDevices();
|
|
484
|
+
const configuredIds = new Set((configured || []).map((d) => normalizeId(d?.id || d?.deviceId)));
|
|
485
|
+
const ul = await renderDiscoveredDevices(sorted, {
|
|
486
|
+
configuredIds
|
|
487
|
+
});
|
|
488
|
+
document.getElementById("discoveredDevices")?.replaceWith(ul);
|
|
489
|
+
ul.id = "discoveredDevices";
|
|
490
|
+
const status = document.getElementById("discoverStatus");
|
|
491
|
+
if (status) {
|
|
492
|
+
const totalCount = allDevices.length;
|
|
493
|
+
const filteredCount = sorted.length;
|
|
494
|
+
status.textContent = filteredCount === totalCount ? `Found ${totalCount} device(s)` : `Showing ${filteredCount} of ${totalCount} device(s)`;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
async function addDeviceToConfig(device) {
|
|
498
|
+
const { addDeviceToConfig: addDevice2 } = await Promise.resolve().then(() => (init_devices(), devices_exports));
|
|
499
|
+
await addDevice2(device);
|
|
500
|
+
}
|
|
501
|
+
var init_discovery = __esm({
|
|
502
|
+
"src/homebridge-ui/public/js/discovery.ts"() {
|
|
503
|
+
"use strict";
|
|
504
|
+
init_api();
|
|
505
|
+
init_devices();
|
|
506
|
+
init_logger();
|
|
507
|
+
init_modal();
|
|
508
|
+
init_render();
|
|
509
|
+
init_toast();
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// src/device-types.ts
|
|
514
|
+
var DEVICE_TYPES;
|
|
515
|
+
var init_device_types = __esm({
|
|
516
|
+
"src/device-types.ts"() {
|
|
517
|
+
"use strict";
|
|
518
|
+
DEVICE_TYPES = {
|
|
519
|
+
"Window Coverings": ["Blind Tilt", "Curtain", "Curtain3", "Roller Shade"],
|
|
520
|
+
"Locks & Access": [
|
|
521
|
+
"Keypad",
|
|
522
|
+
"Keypad Touch",
|
|
523
|
+
"Keypad Vision",
|
|
524
|
+
"Keypad Vision Pro",
|
|
525
|
+
"Lock Vision Pro",
|
|
526
|
+
"Lock Lite",
|
|
527
|
+
"Smart Lock",
|
|
528
|
+
"Smart Lock Pro",
|
|
529
|
+
"Smart Lock Ultra",
|
|
530
|
+
"Video Doorbell"
|
|
531
|
+
],
|
|
532
|
+
"Sensors": ["Contact Sensor", "Motion Sensor", "Presence Sensor", "Water Detector"],
|
|
533
|
+
"Lighting": [
|
|
534
|
+
"Candle Warmer Lamp",
|
|
535
|
+
"Ceiling Light",
|
|
536
|
+
"Ceiling Light Pro",
|
|
537
|
+
"Color Bulb",
|
|
538
|
+
"Floor Lamp",
|
|
539
|
+
"RGBIC Neon Rope Light",
|
|
540
|
+
"RGBIC Neon Wire Rope Light",
|
|
541
|
+
"RGBICWW Floor Lamp",
|
|
542
|
+
"RGBICWW Strip Light",
|
|
543
|
+
"Strip Light",
|
|
544
|
+
"Strip Light 3"
|
|
545
|
+
],
|
|
546
|
+
"Climate Control": [
|
|
547
|
+
"Air Purifier PM2.5",
|
|
548
|
+
"Air Purifier Table PM2.5",
|
|
549
|
+
"Air Purifier VOC",
|
|
550
|
+
"Air Purifier Table VOC",
|
|
551
|
+
"Battery Circulator Fan",
|
|
552
|
+
"Circulator Fan",
|
|
553
|
+
"Humidifier",
|
|
554
|
+
"Humidifier2",
|
|
555
|
+
"Meter",
|
|
556
|
+
"MeterPlus",
|
|
557
|
+
"Meter Plus",
|
|
558
|
+
"MeterPro",
|
|
559
|
+
"Meter Pro",
|
|
560
|
+
"MeterPro(CO2)",
|
|
561
|
+
"Meter Pro (CO2)",
|
|
562
|
+
"Smart Radiator Thermostat",
|
|
563
|
+
"Standing Circulator Fan",
|
|
564
|
+
"WoIOSensor"
|
|
565
|
+
],
|
|
566
|
+
"Plugs & Switches": [
|
|
567
|
+
"Garage Door Opener",
|
|
568
|
+
"Plug",
|
|
569
|
+
"Plug Mini (EU)",
|
|
570
|
+
"Plug Mini (JP)",
|
|
571
|
+
"Plug Mini (US)",
|
|
572
|
+
"Relay Switch 1",
|
|
573
|
+
"Relay Switch 1PM",
|
|
574
|
+
"Relay Switch 2PM"
|
|
575
|
+
],
|
|
576
|
+
"Robot Vacuums": [
|
|
577
|
+
"K10+",
|
|
578
|
+
"K10+ Pro",
|
|
579
|
+
"Robot Vacuum Cleaner K10+ Pro Combo",
|
|
580
|
+
"Robot Vacuum Cleaner K11+",
|
|
581
|
+
"Robot Vacuum Cleaner K20 Plus Pro",
|
|
582
|
+
"Robot Vacuum Cleaner S1",
|
|
583
|
+
"Robot Vacuum Cleaner S1 Plus",
|
|
584
|
+
"Robot Vacuum Cleaner S10",
|
|
585
|
+
"Robot Vacuum Cleaner S20"
|
|
586
|
+
],
|
|
587
|
+
"Hubs": ["AI Hub", "Hub", "Hub 2", "Hub 3", "Hub Mini", "Hub Plus"],
|
|
588
|
+
"Cameras": [
|
|
589
|
+
"Indoor Cam",
|
|
590
|
+
"Pan/Tilt Cam",
|
|
591
|
+
"Pan/Tilt Cam 2K",
|
|
592
|
+
"Pan/Tilt Cam Plus 2K",
|
|
593
|
+
"Pan/Tilt Cam Plus 3K"
|
|
594
|
+
],
|
|
595
|
+
"IR Devices": [
|
|
596
|
+
"Air Conditioner",
|
|
597
|
+
"Air Purifier",
|
|
598
|
+
"Camera",
|
|
599
|
+
"DVD",
|
|
600
|
+
"Fan",
|
|
601
|
+
"Light",
|
|
602
|
+
"Others",
|
|
603
|
+
"Projector",
|
|
604
|
+
"Set Top Box",
|
|
605
|
+
"Speaker",
|
|
606
|
+
"Streamer",
|
|
607
|
+
"TV",
|
|
608
|
+
"Vacuum Cleaner",
|
|
609
|
+
"Water Heater"
|
|
610
|
+
],
|
|
611
|
+
"Other Devices": ["AI Art Frame", "Bot", "Home Climate Panel", "Remote", "remote with screen"]
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// src/homebridge-ui/public/js/constants.ts
|
|
617
|
+
var init_constants = __esm({
|
|
618
|
+
"src/homebridge-ui/public/js/constants.ts"() {
|
|
619
|
+
"use strict";
|
|
620
|
+
init_device_types();
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// src/homebridge-ui/public/js/modals.ts
|
|
625
|
+
var modals_exports = {};
|
|
626
|
+
__export(modals_exports, {
|
|
627
|
+
editDevice: () => editDevice,
|
|
628
|
+
importDiscoveredDevice: () => importDiscoveredDevice
|
|
629
|
+
});
|
|
630
|
+
async function importDiscoveredDevice(device) {
|
|
631
|
+
return new Promise((resolve) => {
|
|
632
|
+
const div = document.createElement("div");
|
|
633
|
+
div.style.position = "fixed";
|
|
634
|
+
div.style.top = "0";
|
|
635
|
+
div.style.left = "0";
|
|
636
|
+
div.style.width = "100%";
|
|
637
|
+
div.style.height = "100%";
|
|
638
|
+
div.style.background = "rgba(0,0,0,0.7)";
|
|
639
|
+
div.style.display = "flex";
|
|
640
|
+
div.style.alignItems = "center";
|
|
641
|
+
div.style.justifyContent = "center";
|
|
642
|
+
div.style.zIndex = "9999";
|
|
643
|
+
const modal = document.createElement("div");
|
|
644
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor;
|
|
645
|
+
modal.style.color = getComputedStyle(document.body).color;
|
|
646
|
+
modal.style.padding = "0";
|
|
647
|
+
modal.style.borderRadius = "10px";
|
|
648
|
+
modal.style.minWidth = "440px";
|
|
649
|
+
modal.style.maxWidth = "90vw";
|
|
650
|
+
modal.style.boxShadow = "0 8px 32px rgba(0,0,0,0.35)";
|
|
651
|
+
modal.style.overflow = "hidden";
|
|
652
|
+
modal.style.borderTop = "3px solid var(--switchbot-red, #ef4444)";
|
|
653
|
+
const title = document.createElement("h3");
|
|
654
|
+
title.textContent = "Import Discovered Device";
|
|
655
|
+
title.style.marginTop = "0";
|
|
656
|
+
title.style.marginBottom = "16px";
|
|
657
|
+
title.style.padding = "20px 20px 0";
|
|
658
|
+
title.style.fontSize = "18px";
|
|
659
|
+
title.style.fontWeight = "600";
|
|
660
|
+
title.style.color = "var(--switchbot-red, #ef4444)";
|
|
661
|
+
title.style.letterSpacing = "-0.02em";
|
|
662
|
+
const contentDiv = document.createElement("div");
|
|
663
|
+
contentDiv.style.padding = "0 20px 20px";
|
|
664
|
+
const nameLabel = document.createElement("label");
|
|
665
|
+
nameLabel.textContent = "Device Name";
|
|
666
|
+
nameLabel.style.display = "block";
|
|
667
|
+
nameLabel.style.marginBottom = "6px";
|
|
668
|
+
nameLabel.style.fontWeight = "500";
|
|
669
|
+
nameLabel.style.fontSize = "12px";
|
|
670
|
+
nameLabel.style.color = "#6b7280";
|
|
671
|
+
const nameInput = document.createElement("input");
|
|
672
|
+
nameInput.type = "text";
|
|
673
|
+
nameInput.value = device.name || device.id || "";
|
|
674
|
+
nameInput.style.width = "100%";
|
|
675
|
+
nameInput.style.marginBottom = "12px";
|
|
676
|
+
nameInput.style.padding = "8px 10px";
|
|
677
|
+
nameInput.style.borderRadius = "6px";
|
|
678
|
+
nameInput.style.fontSize = "14px";
|
|
679
|
+
nameInput.style.boxSizing = "border-box";
|
|
680
|
+
const typeLabel = document.createElement("label");
|
|
681
|
+
typeLabel.textContent = "Config Device Type";
|
|
682
|
+
typeLabel.style.display = "block";
|
|
683
|
+
typeLabel.style.marginBottom = "6px";
|
|
684
|
+
typeLabel.style.fontWeight = "500";
|
|
685
|
+
typeLabel.style.fontSize = "12px";
|
|
686
|
+
typeLabel.style.color = "#6b7280";
|
|
687
|
+
const typeSelect = document.createElement("select");
|
|
688
|
+
typeSelect.style.width = "100%";
|
|
689
|
+
typeSelect.style.padding = "8px 10px";
|
|
690
|
+
typeSelect.style.marginBottom = "12px";
|
|
691
|
+
typeSelect.style.borderRadius = "6px";
|
|
692
|
+
typeSelect.style.fontSize = "14px";
|
|
693
|
+
typeSelect.style.background = getComputedStyle(nameInput).background;
|
|
694
|
+
typeSelect.style.color = getComputedStyle(nameInput).color;
|
|
695
|
+
typeSelect.style.border = getComputedStyle(nameInput).border;
|
|
696
|
+
typeSelect.style.boxSizing = "border-box";
|
|
697
|
+
Object.keys(DEVICE_TYPES).forEach((categoryName) => {
|
|
698
|
+
const optgroup = document.createElement("optgroup");
|
|
699
|
+
optgroup.label = categoryName;
|
|
700
|
+
DEVICE_TYPES[categoryName].forEach((deviceType) => {
|
|
701
|
+
const opt = document.createElement("option");
|
|
702
|
+
opt.value = deviceType;
|
|
703
|
+
opt.text = deviceType;
|
|
704
|
+
const detectedType = (device.type || "").toLowerCase();
|
|
705
|
+
opt.selected = deviceType.toLowerCase() === detectedType;
|
|
706
|
+
optgroup.appendChild(opt);
|
|
707
|
+
});
|
|
708
|
+
typeSelect.appendChild(optgroup);
|
|
709
|
+
});
|
|
710
|
+
const macLabel = document.createElement("label");
|
|
711
|
+
macLabel.textContent = "BLE MAC Address (optional)";
|
|
712
|
+
macLabel.style.display = "block";
|
|
713
|
+
macLabel.style.marginBottom = "6px";
|
|
714
|
+
macLabel.style.fontWeight = "500";
|
|
715
|
+
macLabel.style.fontSize = "12px";
|
|
716
|
+
macLabel.style.color = "#6b7280";
|
|
717
|
+
const macInput = document.createElement("input");
|
|
718
|
+
macInput.type = "text";
|
|
719
|
+
macInput.value = device.address || "";
|
|
720
|
+
macInput.placeholder = "AA:BB:CC:DD:EE:FF";
|
|
721
|
+
macInput.style.width = "100%";
|
|
722
|
+
macInput.style.marginBottom = "12px";
|
|
723
|
+
macInput.style.padding = "8px 10px";
|
|
724
|
+
macInput.style.borderRadius = "6px";
|
|
725
|
+
macInput.style.fontSize = "14px";
|
|
726
|
+
macInput.style.boxSizing = "border-box";
|
|
727
|
+
const buttons = document.createElement("div");
|
|
728
|
+
buttons.style.display = "flex";
|
|
729
|
+
buttons.style.gap = "10px";
|
|
730
|
+
buttons.style.justifyContent = "flex-end";
|
|
731
|
+
buttons.style.marginTop = "18px";
|
|
732
|
+
buttons.style.paddingTop = "18px";
|
|
733
|
+
buttons.style.borderTop = "1px solid rgba(0, 0, 0, 0.08)";
|
|
734
|
+
const cancelBtn = document.createElement("button");
|
|
735
|
+
cancelBtn.textContent = "Cancel";
|
|
736
|
+
cancelBtn.className = "secondary";
|
|
737
|
+
cancelBtn.style.background = "#6b7280";
|
|
738
|
+
cancelBtn.style.padding = "8px 16px";
|
|
739
|
+
cancelBtn.style.fontSize = "13px";
|
|
740
|
+
const importBtn = document.createElement("button");
|
|
741
|
+
importBtn.textContent = "Add to Config";
|
|
742
|
+
importBtn.style.background = "var(--switchbot-red, #ef4444)";
|
|
743
|
+
importBtn.style.padding = "8px 20px";
|
|
744
|
+
importBtn.style.fontSize = "13px";
|
|
745
|
+
const cleanup = (result) => {
|
|
746
|
+
div.remove();
|
|
747
|
+
resolve(result);
|
|
748
|
+
};
|
|
749
|
+
cancelBtn.onclick = () => cleanup(null);
|
|
750
|
+
importBtn.onclick = () => cleanup({
|
|
751
|
+
configDeviceName: nameInput.value || device.name || device.id,
|
|
752
|
+
configDeviceType: typeSelect.value || device.type,
|
|
753
|
+
address: macInput.value || void 0
|
|
754
|
+
});
|
|
755
|
+
div.addEventListener("click", (event) => {
|
|
756
|
+
if (event.target === div) {
|
|
757
|
+
cleanup(null);
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
buttons.appendChild(cancelBtn);
|
|
761
|
+
buttons.appendChild(importBtn);
|
|
762
|
+
contentDiv.appendChild(nameLabel);
|
|
763
|
+
contentDiv.appendChild(nameInput);
|
|
764
|
+
contentDiv.appendChild(typeLabel);
|
|
765
|
+
contentDiv.appendChild(typeSelect);
|
|
766
|
+
contentDiv.appendChild(macLabel);
|
|
767
|
+
contentDiv.appendChild(macInput);
|
|
768
|
+
contentDiv.appendChild(buttons);
|
|
769
|
+
modal.appendChild(title);
|
|
770
|
+
modal.appendChild(contentDiv);
|
|
771
|
+
div.appendChild(modal);
|
|
772
|
+
document.body.appendChild(div);
|
|
773
|
+
nameInput.focus();
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
async function editDevice(device) {
|
|
777
|
+
const div = document.createElement("div");
|
|
778
|
+
div.style.position = "fixed";
|
|
779
|
+
div.style.top = "0";
|
|
780
|
+
div.style.left = "0";
|
|
781
|
+
div.style.width = "100%";
|
|
782
|
+
div.style.height = "100%";
|
|
783
|
+
div.style.background = "rgba(0,0,0,0.7)";
|
|
784
|
+
div.style.display = "flex";
|
|
785
|
+
div.style.alignItems = "center";
|
|
786
|
+
div.style.justifyContent = "center";
|
|
787
|
+
div.style.zIndex = "9999";
|
|
788
|
+
const modal = document.createElement("div");
|
|
789
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor;
|
|
790
|
+
modal.style.color = getComputedStyle(document.body).color;
|
|
791
|
+
modal.style.padding = "0";
|
|
792
|
+
modal.style.borderRadius = "10px";
|
|
793
|
+
modal.style.minWidth = "440px";
|
|
794
|
+
modal.style.maxWidth = "90vw";
|
|
795
|
+
modal.style.boxShadow = "0 8px 32px rgba(0,0,0,0.35)";
|
|
796
|
+
modal.style.overflow = "hidden";
|
|
797
|
+
modal.style.borderTop = "3px solid var(--switchbot-red, #ef4444)";
|
|
798
|
+
const title = document.createElement("h3");
|
|
799
|
+
title.textContent = "Edit Device";
|
|
800
|
+
title.style.marginTop = "0";
|
|
801
|
+
title.style.marginBottom = "16px";
|
|
802
|
+
title.style.padding = "20px 20px 0";
|
|
803
|
+
title.style.fontSize = "18px";
|
|
804
|
+
title.style.fontWeight = "600";
|
|
805
|
+
title.style.color = "var(--switchbot-red, #ef4444)";
|
|
806
|
+
title.style.letterSpacing = "-0.02em";
|
|
807
|
+
const contentDiv = document.createElement("div");
|
|
808
|
+
contentDiv.style.padding = "0 20px 20px";
|
|
809
|
+
const nameLabel = document.createElement("label");
|
|
810
|
+
nameLabel.textContent = "Device Name";
|
|
811
|
+
nameLabel.style.display = "block";
|
|
812
|
+
nameLabel.style.marginBottom = "6px";
|
|
813
|
+
nameLabel.style.fontWeight = "500";
|
|
814
|
+
nameLabel.style.fontSize = "12px";
|
|
815
|
+
nameLabel.style.color = "#6b7280";
|
|
816
|
+
const nameInput = document.createElement("input");
|
|
817
|
+
nameInput.type = "text";
|
|
818
|
+
nameInput.value = device.name || device.id;
|
|
819
|
+
nameInput.style.width = "100%";
|
|
820
|
+
nameInput.style.marginBottom = "12px";
|
|
821
|
+
nameInput.style.padding = "8px 10px";
|
|
822
|
+
nameInput.style.borderRadius = "6px";
|
|
823
|
+
nameInput.style.fontSize = "14px";
|
|
824
|
+
nameInput.style.boxSizing = "border-box";
|
|
825
|
+
nameInput.style.transition = "border-color 0.2s ease";
|
|
826
|
+
const apiTypeLabel = document.createElement("label");
|
|
827
|
+
apiTypeLabel.textContent = "Device Type (API - Read Only)";
|
|
828
|
+
apiTypeLabel.style.display = "block";
|
|
829
|
+
apiTypeLabel.style.marginBottom = "6px";
|
|
830
|
+
apiTypeLabel.style.fontWeight = "500";
|
|
831
|
+
apiTypeLabel.style.fontSize = "12px";
|
|
832
|
+
apiTypeLabel.style.color = "#6b7280";
|
|
833
|
+
const apiTypeInput = document.createElement("input");
|
|
834
|
+
apiTypeInput.type = "text";
|
|
835
|
+
apiTypeInput.value = device.deviceType || device.type || "Unknown";
|
|
836
|
+
apiTypeInput.readOnly = true;
|
|
837
|
+
apiTypeInput.style.width = "100%";
|
|
838
|
+
apiTypeInput.style.marginBottom = "12px";
|
|
839
|
+
apiTypeInput.style.padding = "8px 10px";
|
|
840
|
+
apiTypeInput.style.borderRadius = "6px";
|
|
841
|
+
apiTypeInput.style.fontSize = "13px";
|
|
842
|
+
apiTypeInput.style.opacity = "0.6";
|
|
843
|
+
apiTypeInput.style.cursor = "not-allowed";
|
|
844
|
+
apiTypeInput.style.boxSizing = "border-box";
|
|
845
|
+
apiTypeInput.style.backgroundColor = "#f9fafb";
|
|
846
|
+
const typeLabel = document.createElement("label");
|
|
847
|
+
typeLabel.textContent = "Config Device Type (Override)";
|
|
848
|
+
typeLabel.style.display = "block";
|
|
849
|
+
typeLabel.style.marginBottom = "6px";
|
|
850
|
+
typeLabel.style.fontWeight = "500";
|
|
851
|
+
typeLabel.style.fontSize = "12px";
|
|
852
|
+
typeLabel.style.color = "#6b7280";
|
|
853
|
+
const typeSelect = document.createElement("select");
|
|
854
|
+
typeSelect.style.width = "100%";
|
|
855
|
+
typeSelect.style.padding = "8px 10px";
|
|
856
|
+
typeSelect.style.marginBottom = "12px";
|
|
857
|
+
typeSelect.style.borderRadius = "6px";
|
|
858
|
+
typeSelect.style.fontSize = "14px";
|
|
859
|
+
typeSelect.style.background = getComputedStyle(nameInput).background;
|
|
860
|
+
typeSelect.style.color = getComputedStyle(nameInput).color;
|
|
861
|
+
typeSelect.style.border = getComputedStyle(nameInput).border;
|
|
862
|
+
typeSelect.style.boxSizing = "border-box";
|
|
863
|
+
typeSelect.style.cursor = "pointer";
|
|
864
|
+
typeSelect.style.transition = "border-color 0.2s ease";
|
|
865
|
+
Object.keys(DEVICE_TYPES).forEach((categoryName) => {
|
|
866
|
+
const optgroup = document.createElement("optgroup");
|
|
867
|
+
optgroup.label = categoryName;
|
|
868
|
+
DEVICE_TYPES[categoryName].forEach((deviceType) => {
|
|
869
|
+
const opt = document.createElement("option");
|
|
870
|
+
opt.value = deviceType;
|
|
871
|
+
opt.text = deviceType;
|
|
872
|
+
const currentType = device.configDeviceType || device.deviceType || device.type || "";
|
|
873
|
+
opt.selected = currentType === deviceType;
|
|
874
|
+
optgroup.appendChild(opt);
|
|
875
|
+
});
|
|
876
|
+
typeSelect.appendChild(optgroup);
|
|
877
|
+
});
|
|
878
|
+
const errorMessage = document.createElement("div");
|
|
879
|
+
errorMessage.style.color = "var(--switchbot-red, #ef4444)";
|
|
880
|
+
errorMessage.style.marginBottom = "12px";
|
|
881
|
+
errorMessage.style.fontSize = "12px";
|
|
882
|
+
errorMessage.style.display = "none";
|
|
883
|
+
errorMessage.style.padding = "8px 10px";
|
|
884
|
+
errorMessage.style.background = "var(--switchbot-red-light, #fee2e2)";
|
|
885
|
+
errorMessage.style.borderRadius = "6px";
|
|
886
|
+
errorMessage.style.fontWeight = "500";
|
|
887
|
+
const buttons = document.createElement("div");
|
|
888
|
+
buttons.style.display = "flex";
|
|
889
|
+
buttons.style.gap = "10px";
|
|
890
|
+
buttons.style.justifyContent = "flex-end";
|
|
891
|
+
buttons.style.marginTop = "18px";
|
|
892
|
+
buttons.style.paddingTop = "18px";
|
|
893
|
+
buttons.style.borderTop = "1px solid rgba(0, 0, 0, 0.08)";
|
|
894
|
+
const cancelBtn = document.createElement("button");
|
|
895
|
+
cancelBtn.textContent = "Cancel";
|
|
896
|
+
cancelBtn.className = "secondary";
|
|
897
|
+
cancelBtn.style.background = "#6b7280";
|
|
898
|
+
cancelBtn.style.padding = "8px 16px";
|
|
899
|
+
cancelBtn.style.fontSize = "13px";
|
|
900
|
+
cancelBtn.onclick = () => div.remove();
|
|
901
|
+
const saveBtn = document.createElement("button");
|
|
902
|
+
saveBtn.textContent = "Save";
|
|
903
|
+
saveBtn.style.background = "var(--switchbot-red, #ef4444)";
|
|
904
|
+
saveBtn.style.padding = "8px 20px";
|
|
905
|
+
saveBtn.style.fontSize = "13px";
|
|
906
|
+
saveBtn.onclick = async () => {
|
|
907
|
+
try {
|
|
908
|
+
const { updateDevice: updateDevice2, syncParentPluginConfigFromDisk: syncParentPluginConfigFromDisk2, fetchDevices: fetchDevices2 } = await Promise.resolve().then(() => (init_api(), api_exports));
|
|
909
|
+
const { renderDeviceList: renderDeviceList2 } = await Promise.resolve().then(() => (init_render(), render_exports));
|
|
910
|
+
const params = {
|
|
911
|
+
deviceId: device.id,
|
|
912
|
+
configDeviceName: nameInput.value || void 0,
|
|
913
|
+
configDeviceType: typeSelect.value
|
|
914
|
+
};
|
|
915
|
+
await updateDevice2(params.deviceId, params.configDeviceName, params.configDeviceType);
|
|
916
|
+
await syncParentPluginConfigFromDisk2();
|
|
917
|
+
uiLog.info("[Edit Device] Refreshing device list after update");
|
|
918
|
+
const list = await fetchDevices2();
|
|
919
|
+
renderDeviceList2(list);
|
|
920
|
+
div.remove();
|
|
921
|
+
} catch (e) {
|
|
922
|
+
uiLog.error("Update error:", e);
|
|
923
|
+
errorMessage.textContent = `Error: ${e instanceof Error ? e.message : "Failed to update device"}`;
|
|
924
|
+
errorMessage.style.display = "block";
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
buttons.appendChild(cancelBtn);
|
|
928
|
+
buttons.appendChild(saveBtn);
|
|
929
|
+
contentDiv.appendChild(nameLabel);
|
|
930
|
+
contentDiv.appendChild(nameInput);
|
|
931
|
+
contentDiv.appendChild(apiTypeLabel);
|
|
932
|
+
contentDiv.appendChild(apiTypeInput);
|
|
933
|
+
contentDiv.appendChild(typeLabel);
|
|
934
|
+
contentDiv.appendChild(typeSelect);
|
|
935
|
+
contentDiv.appendChild(errorMessage);
|
|
936
|
+
contentDiv.appendChild(buttons);
|
|
937
|
+
modal.appendChild(title);
|
|
938
|
+
modal.appendChild(contentDiv);
|
|
939
|
+
div.appendChild(modal);
|
|
940
|
+
document.body.appendChild(div);
|
|
941
|
+
nameInput.focus();
|
|
942
|
+
}
|
|
943
|
+
var init_modals = __esm({
|
|
944
|
+
"src/homebridge-ui/public/js/modals.ts"() {
|
|
945
|
+
"use strict";
|
|
946
|
+
init_constants();
|
|
947
|
+
init_logger();
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
// src/homebridge-ui/public/js/devices-delete.ts
|
|
952
|
+
var devices_delete_exports = {};
|
|
953
|
+
__export(devices_delete_exports, {
|
|
954
|
+
deleteAllDevicesFromConfig: () => deleteAllDevicesFromConfig,
|
|
955
|
+
deleteDeviceFromConfig: () => deleteDeviceFromConfig
|
|
956
|
+
});
|
|
957
|
+
async function confirmDeleteDialog(deviceNameOrId) {
|
|
958
|
+
return new Promise((resolve) => {
|
|
959
|
+
const overlay = document.createElement("div");
|
|
960
|
+
overlay.style.position = "fixed";
|
|
961
|
+
overlay.style.top = "0";
|
|
962
|
+
overlay.style.left = "0";
|
|
963
|
+
overlay.style.width = "100%";
|
|
964
|
+
overlay.style.height = "100%";
|
|
965
|
+
overlay.style.background = "rgba(0,0,0,0.6)";
|
|
966
|
+
overlay.style.display = "flex";
|
|
967
|
+
overlay.style.alignItems = "center";
|
|
968
|
+
overlay.style.justifyContent = "center";
|
|
969
|
+
overlay.style.zIndex = "10000";
|
|
970
|
+
const modal = document.createElement("div");
|
|
971
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor;
|
|
972
|
+
modal.style.color = getComputedStyle(document.body).color;
|
|
973
|
+
modal.style.padding = "20px";
|
|
974
|
+
modal.style.borderRadius = "10px";
|
|
975
|
+
modal.style.minWidth = "340px";
|
|
976
|
+
modal.style.maxWidth = "90vw";
|
|
977
|
+
modal.style.boxShadow = "0 12px 40px rgba(0,0,0,0.35)";
|
|
978
|
+
const title = document.createElement("h3");
|
|
979
|
+
title.textContent = "Delete Device";
|
|
980
|
+
title.style.margin = "0 0 10px 0";
|
|
981
|
+
const message = document.createElement("p");
|
|
982
|
+
message.textContent = `Remove "${deviceNameOrId}" from configuration?`;
|
|
983
|
+
message.style.margin = "0 0 16px 0";
|
|
984
|
+
const actions = document.createElement("div");
|
|
985
|
+
actions.style.display = "flex";
|
|
986
|
+
actions.style.justifyContent = "flex-end";
|
|
987
|
+
actions.style.gap = "8px";
|
|
988
|
+
const cancelBtn = document.createElement("button");
|
|
989
|
+
cancelBtn.textContent = "Cancel";
|
|
990
|
+
cancelBtn.style.background = "#6b7280";
|
|
991
|
+
const deleteBtn = document.createElement("button");
|
|
992
|
+
deleteBtn.textContent = "Delete";
|
|
993
|
+
deleteBtn.style.background = "#ef4444";
|
|
994
|
+
const cleanup = (result) => {
|
|
995
|
+
overlay.remove();
|
|
996
|
+
resolve(result);
|
|
997
|
+
};
|
|
998
|
+
cancelBtn.onclick = () => cleanup(false);
|
|
999
|
+
deleteBtn.onclick = () => cleanup(true);
|
|
1000
|
+
overlay.addEventListener("click", (event) => {
|
|
1001
|
+
if (event.target === overlay) {
|
|
1002
|
+
cleanup(false);
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
actions.appendChild(cancelBtn);
|
|
1006
|
+
actions.appendChild(deleteBtn);
|
|
1007
|
+
modal.appendChild(title);
|
|
1008
|
+
modal.appendChild(message);
|
|
1009
|
+
modal.appendChild(actions);
|
|
1010
|
+
overlay.appendChild(modal);
|
|
1011
|
+
document.body.appendChild(overlay);
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
async function deleteDeviceFromConfig(deviceId, deviceName) {
|
|
1015
|
+
uiLog.info("Delete button clicked for device:", deviceId, deviceName);
|
|
1016
|
+
const confirmed = await confirmDeleteDialog(deviceName || deviceId);
|
|
1017
|
+
if (!confirmed) {
|
|
1018
|
+
uiLog.info("Delete cancelled by user");
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
try {
|
|
1022
|
+
showBusyUi();
|
|
1023
|
+
uiLog.info("Sending delete request for deviceId:", deviceId);
|
|
1024
|
+
const resp = await deleteDevice(deviceId);
|
|
1025
|
+
uiLog.info("Delete response:", resp);
|
|
1026
|
+
if (!resp || resp.success === false) {
|
|
1027
|
+
throw new Error(resp?.data?.message || "Failed to delete device");
|
|
1028
|
+
}
|
|
1029
|
+
uiLog.info("Syncing parent config from disk...");
|
|
1030
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
1031
|
+
if (!synced) {
|
|
1032
|
+
toastWarning("Device deleted, but configuration sync failed");
|
|
1033
|
+
}
|
|
1034
|
+
uiLog.info("Refreshing device list...");
|
|
1035
|
+
const list = await fetchDevices();
|
|
1036
|
+
uiLog.info("Rendering devices:", list.length);
|
|
1037
|
+
renderDeviceList(list);
|
|
1038
|
+
uiLog.info("\u2713 Device deleted successfully");
|
|
1039
|
+
toastSuccess(`Device "${deviceName || deviceId}" deleted successfully`);
|
|
1040
|
+
} catch (e) {
|
|
1041
|
+
uiLog.error("Delete error:", e);
|
|
1042
|
+
toastError(e instanceof Error ? e.message : "Failed to delete device");
|
|
1043
|
+
} finally {
|
|
1044
|
+
hideBusyUi();
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
async function confirmDeleteAllDialog(deviceCount) {
|
|
1048
|
+
return new Promise((resolve) => {
|
|
1049
|
+
const overlay = document.createElement("div");
|
|
1050
|
+
overlay.style.position = "fixed";
|
|
1051
|
+
overlay.style.top = "0";
|
|
1052
|
+
overlay.style.left = "0";
|
|
1053
|
+
overlay.style.width = "100%";
|
|
1054
|
+
overlay.style.height = "100%";
|
|
1055
|
+
overlay.style.background = "rgba(0,0,0,0.7)";
|
|
1056
|
+
overlay.style.display = "flex";
|
|
1057
|
+
overlay.style.alignItems = "center";
|
|
1058
|
+
overlay.style.justifyContent = "center";
|
|
1059
|
+
overlay.style.zIndex = "10000";
|
|
1060
|
+
const modal = document.createElement("div");
|
|
1061
|
+
modal.style.background = getComputedStyle(document.body).backgroundColor;
|
|
1062
|
+
modal.style.color = getComputedStyle(document.body).color;
|
|
1063
|
+
modal.style.padding = "20px";
|
|
1064
|
+
modal.style.borderRadius = "10px";
|
|
1065
|
+
modal.style.minWidth = "380px";
|
|
1066
|
+
modal.style.maxWidth = "90vw";
|
|
1067
|
+
modal.style.boxShadow = "0 12px 40px rgba(0,0,0,0.35)";
|
|
1068
|
+
modal.style.borderTop = "3px solid #ef4444";
|
|
1069
|
+
const title = document.createElement("h3");
|
|
1070
|
+
title.textContent = "\u26A0\uFE0F Remove All Devices";
|
|
1071
|
+
title.style.margin = "0 0 12px 0";
|
|
1072
|
+
title.style.color = "#ef4444";
|
|
1073
|
+
const message = document.createElement("p");
|
|
1074
|
+
message.innerHTML = `Are you sure you want to remove <strong>all ${deviceCount} device(s)</strong> from your configuration?<br><br>This action cannot be undone.`;
|
|
1075
|
+
message.style.margin = "0 0 18px 0";
|
|
1076
|
+
message.style.lineHeight = "1.5";
|
|
1077
|
+
const actions = document.createElement("div");
|
|
1078
|
+
actions.style.display = "flex";
|
|
1079
|
+
actions.style.justifyContent = "flex-end";
|
|
1080
|
+
actions.style.gap = "10px";
|
|
1081
|
+
const cancelBtn = document.createElement("button");
|
|
1082
|
+
cancelBtn.textContent = "Cancel";
|
|
1083
|
+
cancelBtn.style.background = "#6b7280";
|
|
1084
|
+
cancelBtn.style.padding = "8px 16px";
|
|
1085
|
+
cancelBtn.style.fontSize = "13px";
|
|
1086
|
+
cancelBtn.className = "secondary";
|
|
1087
|
+
const deleteBtn = document.createElement("button");
|
|
1088
|
+
deleteBtn.textContent = "Remove All";
|
|
1089
|
+
deleteBtn.style.background = "#ef4444";
|
|
1090
|
+
deleteBtn.style.padding = "8px 20px";
|
|
1091
|
+
deleteBtn.style.fontSize = "13px";
|
|
1092
|
+
const cleanup = (result) => {
|
|
1093
|
+
overlay.remove();
|
|
1094
|
+
resolve(result);
|
|
1095
|
+
};
|
|
1096
|
+
cancelBtn.onclick = () => cleanup(false);
|
|
1097
|
+
deleteBtn.onclick = () => cleanup(true);
|
|
1098
|
+
overlay.addEventListener("click", (event) => {
|
|
1099
|
+
if (event.target === overlay) {
|
|
1100
|
+
cleanup(false);
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
actions.appendChild(cancelBtn);
|
|
1104
|
+
actions.appendChild(deleteBtn);
|
|
1105
|
+
modal.appendChild(title);
|
|
1106
|
+
modal.appendChild(message);
|
|
1107
|
+
modal.appendChild(actions);
|
|
1108
|
+
overlay.appendChild(modal);
|
|
1109
|
+
document.body.appendChild(overlay);
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
async function deleteAllDevicesFromConfig() {
|
|
1113
|
+
uiLog.info("Remove All Devices button clicked");
|
|
1114
|
+
try {
|
|
1115
|
+
const list = await fetchDevices();
|
|
1116
|
+
if (!list || list.length === 0) {
|
|
1117
|
+
toastWarning("No devices to remove");
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const confirmed = await confirmDeleteAllDialog(list.length);
|
|
1121
|
+
if (!confirmed) {
|
|
1122
|
+
uiLog.info("Remove all cancelled by user");
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
showBusyUi();
|
|
1126
|
+
uiLog.info("Sending delete all devices request");
|
|
1127
|
+
const resp = await deleteAllDevices();
|
|
1128
|
+
uiLog.info("Delete all response:", resp);
|
|
1129
|
+
if (!resp || resp.success === false) {
|
|
1130
|
+
throw new Error(resp?.data?.message || "Failed to delete all devices");
|
|
1131
|
+
}
|
|
1132
|
+
uiLog.info("Syncing parent config from disk...");
|
|
1133
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
1134
|
+
if (!synced) {
|
|
1135
|
+
toastWarning("Devices deleted, but configuration sync failed");
|
|
1136
|
+
}
|
|
1137
|
+
uiLog.info("Refreshing device list...");
|
|
1138
|
+
const updatedList = await fetchDevices();
|
|
1139
|
+
uiLog.info("Rendering devices:", updatedList.length);
|
|
1140
|
+
renderDeviceList(updatedList);
|
|
1141
|
+
const deletedCount = resp?.deletedCount || list.length;
|
|
1142
|
+
uiLog.info(`\u2713 Removed ${deletedCount} device(s) successfully`);
|
|
1143
|
+
toastSuccess(`Removed ${deletedCount} device(s) successfully`);
|
|
1144
|
+
} catch (e) {
|
|
1145
|
+
uiLog.error("Delete all error:", e);
|
|
1146
|
+
toastError(e instanceof Error ? e.message : "Failed to delete all devices");
|
|
1147
|
+
} finally {
|
|
1148
|
+
hideBusyUi();
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
var init_devices_delete = __esm({
|
|
1152
|
+
"src/homebridge-ui/public/js/devices-delete.ts"() {
|
|
1153
|
+
"use strict";
|
|
1154
|
+
init_api();
|
|
1155
|
+
init_logger();
|
|
1156
|
+
init_modal();
|
|
1157
|
+
init_render();
|
|
1158
|
+
init_toast();
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1162
|
+
// src/homebridge-ui/public/js/render.ts
|
|
1163
|
+
var render_exports = {};
|
|
1164
|
+
__export(render_exports, {
|
|
1165
|
+
filterDevices: () => filterDevices,
|
|
1166
|
+
getDiscoveryPreferences: () => getDiscoveryPreferences,
|
|
1167
|
+
getRssiSignalQuality: () => getRssiSignalQuality,
|
|
1168
|
+
renderBadge: () => renderBadge,
|
|
1169
|
+
renderConnectionBadge: () => renderConnectionBadge,
|
|
1170
|
+
renderDeviceList: () => renderDeviceList,
|
|
1171
|
+
renderDiscoveredDevices: () => renderDiscoveredDevices,
|
|
1172
|
+
renderIRBadge: () => renderIRBadge,
|
|
1173
|
+
renderSignalBars: () => renderSignalBars,
|
|
1174
|
+
renderSignalQualityBadge: () => renderSignalQualityBadge,
|
|
1175
|
+
setDiscoveryPreferences: () => setDiscoveryPreferences,
|
|
1176
|
+
sortDevices: () => sortDevices
|
|
1177
|
+
});
|
|
1178
|
+
function getRssiSignalQuality(rssi) {
|
|
1179
|
+
if (!rssi || rssi === 0) {
|
|
1180
|
+
return {
|
|
1181
|
+
level: "unknown",
|
|
1182
|
+
color: "#999",
|
|
1183
|
+
bgColor: "#f5f5f5",
|
|
1184
|
+
description: "Signal strength unknown",
|
|
1185
|
+
bars: 0
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
const dbm = Math.floor(rssi);
|
|
1189
|
+
if (dbm > -60) {
|
|
1190
|
+
return {
|
|
1191
|
+
level: "excellent",
|
|
1192
|
+
color: "#34a853",
|
|
1193
|
+
bgColor: "#e8f5e9",
|
|
1194
|
+
description: `Excellent (${dbm} dBm)`,
|
|
1195
|
+
bars: 4
|
|
1196
|
+
};
|
|
1197
|
+
} else if (dbm > -75) {
|
|
1198
|
+
return {
|
|
1199
|
+
level: "good",
|
|
1200
|
+
color: "#fbbc04",
|
|
1201
|
+
bgColor: "#fffde7",
|
|
1202
|
+
description: `Good (${dbm} dBm)`,
|
|
1203
|
+
bars: 3
|
|
1204
|
+
};
|
|
1205
|
+
} else if (dbm > -85) {
|
|
1206
|
+
return {
|
|
1207
|
+
level: "fair",
|
|
1208
|
+
color: "#ff9800",
|
|
1209
|
+
bgColor: "#fff3e0",
|
|
1210
|
+
description: `Fair (${dbm} dBm)`,
|
|
1211
|
+
bars: 2
|
|
1212
|
+
};
|
|
1213
|
+
} else {
|
|
1214
|
+
return {
|
|
1215
|
+
level: "poor",
|
|
1216
|
+
color: "#ea4335",
|
|
1217
|
+
bgColor: "#ffebee",
|
|
1218
|
+
description: `Poor (${dbm} dBm) - unreliable`,
|
|
1219
|
+
bars: 1
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
function renderSignalBars(rssi) {
|
|
1224
|
+
const quality = getRssiSignalQuality(rssi);
|
|
1225
|
+
const container = document.createElement("span");
|
|
1226
|
+
container.style.display = "inline-flex";
|
|
1227
|
+
container.style.gap = "2px";
|
|
1228
|
+
container.style.alignItems = "center";
|
|
1229
|
+
container.style.marginLeft = "8px";
|
|
1230
|
+
container.style.fontSize = "12px";
|
|
1231
|
+
for (let i = 1; i <= 4; i++) {
|
|
1232
|
+
const bar = document.createElement("span");
|
|
1233
|
+
bar.style.height = `${i * 3}px`;
|
|
1234
|
+
bar.style.width = "3px";
|
|
1235
|
+
bar.style.borderRadius = "1px";
|
|
1236
|
+
bar.style.border = `1px solid ${quality.color}`;
|
|
1237
|
+
if (i <= quality.bars) {
|
|
1238
|
+
bar.style.backgroundColor = quality.color;
|
|
1239
|
+
} else {
|
|
1240
|
+
bar.style.backgroundColor = "transparent";
|
|
1241
|
+
}
|
|
1242
|
+
container.appendChild(bar);
|
|
1243
|
+
}
|
|
1244
|
+
container.title = quality.description;
|
|
1245
|
+
return container;
|
|
1246
|
+
}
|
|
1247
|
+
function renderSignalQualityBadge(rssi) {
|
|
1248
|
+
const quality = getRssiSignalQuality(rssi);
|
|
1249
|
+
const badge = document.createElement("span");
|
|
1250
|
+
badge.textContent = quality.level.charAt(0).toUpperCase() + quality.level.slice(1);
|
|
1251
|
+
badge.style.cssText = `
|
|
1252
|
+
background: ${quality.color};
|
|
1253
|
+
color: white;
|
|
1254
|
+
padding: 2px 6px;
|
|
1255
|
+
border-radius: 3px;
|
|
1256
|
+
font-size: 10px;
|
|
1257
|
+
font-weight: 600;
|
|
1258
|
+
margin-left: 8px;
|
|
1259
|
+
`;
|
|
1260
|
+
badge.title = quality.description;
|
|
1261
|
+
return badge;
|
|
1262
|
+
}
|
|
1263
|
+
function renderBadge(text, style) {
|
|
1264
|
+
const badge = document.createElement("span");
|
|
1265
|
+
badge.textContent = text;
|
|
1266
|
+
badge.style.cssText = style;
|
|
1267
|
+
return badge;
|
|
1268
|
+
}
|
|
1269
|
+
function renderConnectionBadge(connectionType) {
|
|
1270
|
+
if (!connectionType) {
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1273
|
+
const badge = renderBadge(connectionType, "");
|
|
1274
|
+
if (connectionType === "BLE") {
|
|
1275
|
+
badge.style.cssText = "background: #4285f4; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
|
|
1276
|
+
} else if (connectionType === "Both") {
|
|
1277
|
+
badge.style.cssText = "background: #34a853; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
|
|
1278
|
+
} else {
|
|
1279
|
+
badge.style.cssText = "background: #9e9e9e; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;";
|
|
1280
|
+
}
|
|
1281
|
+
return badge;
|
|
1282
|
+
}
|
|
1283
|
+
function renderIRBadge() {
|
|
1284
|
+
return renderBadge(
|
|
1285
|
+
"IR",
|
|
1286
|
+
"background: #ff6b35; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; margin-left: 8px;"
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
function normalizeId2(value) {
|
|
1290
|
+
return String(value ?? "").trim().toLowerCase();
|
|
1291
|
+
}
|
|
1292
|
+
function scrollToConfiguredDevice(deviceId) {
|
|
1293
|
+
const normalizedId = normalizeId2(deviceId);
|
|
1294
|
+
const target = document.querySelector(`[data-device-id="${normalizedId}"]`);
|
|
1295
|
+
if (!target) {
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
1299
|
+
const originalOutline = target.style.outline;
|
|
1300
|
+
const originalBackground = target.style.background;
|
|
1301
|
+
target.style.outline = "2px solid var(--switchbot-red, #ef4444)";
|
|
1302
|
+
target.style.background = "rgba(239, 68, 68, 0.08)";
|
|
1303
|
+
setTimeout(() => {
|
|
1304
|
+
target.style.outline = originalOutline;
|
|
1305
|
+
target.style.background = originalBackground;
|
|
1306
|
+
}, 1800);
|
|
1307
|
+
}
|
|
1308
|
+
async function renderDiscoveredDevices(devices, options = {}) {
|
|
1309
|
+
const ul = document.createElement("ul");
|
|
1310
|
+
ul.style.maxHeight = "400px";
|
|
1311
|
+
ul.style.overflowY = "auto";
|
|
1312
|
+
ul.style.marginTop = "12px";
|
|
1313
|
+
ul.style.padding = "0";
|
|
1314
|
+
ul.style.listStyle = "none";
|
|
1315
|
+
const { addDeviceToConfig: addDeviceToConfig3 } = await Promise.resolve().then(() => (init_discovery(), discovery_exports));
|
|
1316
|
+
const { loadConfiguredDevices: loadConfiguredDevices2 } = await Promise.resolve().then(() => (init_devices(), devices_exports));
|
|
1317
|
+
const configuredIds = options.configuredIds ?? /* @__PURE__ */ new Set();
|
|
1318
|
+
for (const d of devices) {
|
|
1319
|
+
const deviceId = normalizeId2(d.id);
|
|
1320
|
+
const alreadyAdded = configuredIds.has(deviceId);
|
|
1321
|
+
const li = document.createElement("li");
|
|
1322
|
+
li.className = "device-item";
|
|
1323
|
+
li.style.display = "flex";
|
|
1324
|
+
li.style.alignItems = "center";
|
|
1325
|
+
li.style.justifyContent = "space-between";
|
|
1326
|
+
li.style.padding = "10px 12px";
|
|
1327
|
+
li.style.marginBottom = "6px";
|
|
1328
|
+
li.style.borderRadius = "6px";
|
|
1329
|
+
li.style.transition = "all 0.2s ease";
|
|
1330
|
+
const info = document.createElement("div");
|
|
1331
|
+
info.style.flex = "1";
|
|
1332
|
+
const nameContainer = document.createElement("div");
|
|
1333
|
+
nameContainer.style.display = "flex";
|
|
1334
|
+
nameContainer.style.alignItems = "center";
|
|
1335
|
+
nameContainer.style.marginBottom = "4px";
|
|
1336
|
+
nameContainer.style.flexWrap = "wrap";
|
|
1337
|
+
nameContainer.style.gap = "6px";
|
|
1338
|
+
const name = document.createElement("div");
|
|
1339
|
+
name.style.fontWeight = "500";
|
|
1340
|
+
name.style.fontSize = "14px";
|
|
1341
|
+
name.textContent = d.name || d.id;
|
|
1342
|
+
nameContainer.appendChild(name);
|
|
1343
|
+
const duplicateBadge = document.createElement("span");
|
|
1344
|
+
duplicateBadge.textContent = alreadyAdded ? "\u2713 Already Added" : "\u2795 New Device";
|
|
1345
|
+
duplicateBadge.style.cssText = alreadyAdded ? "background: #16a34a; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600;" : "background: #2563eb; color: white; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600;";
|
|
1346
|
+
nameContainer.appendChild(duplicateBadge);
|
|
1347
|
+
if (d.connectionType) {
|
|
1348
|
+
const badge = renderConnectionBadge(d.connectionType);
|
|
1349
|
+
if (badge) {
|
|
1350
|
+
nameContainer.appendChild(badge);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
if (d.isIR) {
|
|
1354
|
+
nameContainer.appendChild(renderIRBadge());
|
|
1355
|
+
}
|
|
1356
|
+
if (d.rssi !== void 0 && d.rssi !== null && d.rssi !== 0) {
|
|
1357
|
+
nameContainer.appendChild(renderSignalBars(d.rssi));
|
|
1358
|
+
nameContainer.appendChild(renderSignalQualityBadge(d.rssi));
|
|
1359
|
+
}
|
|
1360
|
+
const details = document.createElement("div");
|
|
1361
|
+
details.style.fontSize = "11px";
|
|
1362
|
+
details.style.opacity = "0.7";
|
|
1363
|
+
details.style.marginTop = "4px";
|
|
1364
|
+
details.style.fontFamily = "monospace";
|
|
1365
|
+
let detailsText = `ID: ${d.id} | Type: ${d.type} | Model: ${d.model || "N/A"}`;
|
|
1366
|
+
if (d.hubDeviceId) {
|
|
1367
|
+
detailsText += ` | Hub: ${d.hubDeviceId}`;
|
|
1368
|
+
}
|
|
1369
|
+
if (d.address) {
|
|
1370
|
+
detailsText += ` | MAC: ${d.address}`;
|
|
1371
|
+
}
|
|
1372
|
+
details.textContent = detailsText;
|
|
1373
|
+
info.appendChild(nameContainer);
|
|
1374
|
+
info.appendChild(details);
|
|
1375
|
+
const addBtn = document.createElement("button");
|
|
1376
|
+
addBtn.textContent = alreadyAdded ? "Already Added" : "Add to Config";
|
|
1377
|
+
addBtn.style.marginLeft = "8px";
|
|
1378
|
+
addBtn.style.padding = "6px 14px";
|
|
1379
|
+
addBtn.style.fontSize = "12px";
|
|
1380
|
+
addBtn.style.whiteSpace = "nowrap";
|
|
1381
|
+
addBtn.style.flexShrink = "0";
|
|
1382
|
+
addBtn.disabled = alreadyAdded;
|
|
1383
|
+
if (alreadyAdded) {
|
|
1384
|
+
addBtn.style.opacity = "0.65";
|
|
1385
|
+
addBtn.style.cursor = "not-allowed";
|
|
1386
|
+
addBtn.style.background = "#6b7280";
|
|
1387
|
+
}
|
|
1388
|
+
addBtn.onclick = async () => {
|
|
1389
|
+
if (alreadyAdded) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
await addDeviceToConfig3(d);
|
|
1393
|
+
};
|
|
1394
|
+
if (alreadyAdded) {
|
|
1395
|
+
const viewBtn = document.createElement("button");
|
|
1396
|
+
viewBtn.textContent = "View in Config";
|
|
1397
|
+
viewBtn.className = "secondary";
|
|
1398
|
+
viewBtn.style.marginLeft = "8px";
|
|
1399
|
+
viewBtn.style.padding = "6px 12px";
|
|
1400
|
+
viewBtn.style.fontSize = "12px";
|
|
1401
|
+
viewBtn.onclick = async () => {
|
|
1402
|
+
await loadConfiguredDevices2();
|
|
1403
|
+
scrollToConfiguredDevice(d.id);
|
|
1404
|
+
};
|
|
1405
|
+
li.appendChild(info);
|
|
1406
|
+
const actions = document.createElement("div");
|
|
1407
|
+
actions.style.display = "flex";
|
|
1408
|
+
actions.style.alignItems = "center";
|
|
1409
|
+
actions.appendChild(viewBtn);
|
|
1410
|
+
actions.appendChild(addBtn);
|
|
1411
|
+
li.appendChild(actions);
|
|
1412
|
+
ul.appendChild(li);
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
li.appendChild(info);
|
|
1416
|
+
li.appendChild(addBtn);
|
|
1417
|
+
ul.appendChild(li);
|
|
1418
|
+
}
|
|
1419
|
+
return ul;
|
|
1420
|
+
}
|
|
1421
|
+
function filterDevices(devices, connectionType = "all", searchQuery = "") {
|
|
1422
|
+
let filtered = [...devices];
|
|
1423
|
+
if (connectionType !== "all") {
|
|
1424
|
+
filtered = filtered.filter((d) => {
|
|
1425
|
+
if (connectionType === "ir") {
|
|
1426
|
+
return d.isIR === true;
|
|
1427
|
+
}
|
|
1428
|
+
if (connectionType === "ble") {
|
|
1429
|
+
return d.connectionType === "BLE" || d.connectionType?.includes("BLE");
|
|
1430
|
+
}
|
|
1431
|
+
if (connectionType === "api") {
|
|
1432
|
+
return d.connectionType === "OpenAPI" || d.connectionType === "API" || d.connectionType?.includes("API");
|
|
1433
|
+
}
|
|
1434
|
+
if (connectionType === "both") {
|
|
1435
|
+
return d.connectionType === "Both" || d.connectionType?.includes("Both");
|
|
1436
|
+
}
|
|
1437
|
+
return true;
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
if (searchQuery.trim()) {
|
|
1441
|
+
const query = searchQuery.toLowerCase();
|
|
1442
|
+
filtered = filtered.filter((d) => {
|
|
1443
|
+
const name = (d.name || "").toLowerCase();
|
|
1444
|
+
const id = (d.id || "").toLowerCase();
|
|
1445
|
+
const type = (d.type || "").toLowerCase();
|
|
1446
|
+
const model = (d.model || "").toLowerCase();
|
|
1447
|
+
return name.includes(query) || id.includes(query) || type.includes(query) || model.includes(query);
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
return filtered;
|
|
1451
|
+
}
|
|
1452
|
+
function sortDevices(devices, sortBy = "name") {
|
|
1453
|
+
const sorted = [...devices];
|
|
1454
|
+
switch (sortBy) {
|
|
1455
|
+
case "signal": {
|
|
1456
|
+
sorted.sort((a, b) => {
|
|
1457
|
+
const aRssi = a.rssi || 0;
|
|
1458
|
+
const bRssi = b.rssi || 0;
|
|
1459
|
+
return bRssi - aRssi;
|
|
1460
|
+
});
|
|
1461
|
+
break;
|
|
1462
|
+
}
|
|
1463
|
+
case "type": {
|
|
1464
|
+
sorted.sort((a, b) => {
|
|
1465
|
+
const aType = (a.type || "").localeCompare(b.type || "");
|
|
1466
|
+
return aType;
|
|
1467
|
+
});
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
case "connection": {
|
|
1471
|
+
const connectionOrder = {
|
|
1472
|
+
"Both": 0,
|
|
1473
|
+
"BLE": 1,
|
|
1474
|
+
"OpenAPI": 2,
|
|
1475
|
+
"API": 2,
|
|
1476
|
+
"Unknown": 3
|
|
1477
|
+
};
|
|
1478
|
+
sorted.sort((a, b) => {
|
|
1479
|
+
const aOrder = connectionOrder[a.connectionType || "Unknown"] ?? 3;
|
|
1480
|
+
const bOrder = connectionOrder[b.connectionType || "Unknown"] ?? 3;
|
|
1481
|
+
return aOrder - bOrder;
|
|
1482
|
+
});
|
|
1483
|
+
break;
|
|
1484
|
+
}
|
|
1485
|
+
case "name":
|
|
1486
|
+
default: {
|
|
1487
|
+
sorted.sort((a, b) => (a.name || a.id || "").localeCompare(b.name || b.id || ""));
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
return sorted;
|
|
1492
|
+
}
|
|
1493
|
+
function getDiscoveryPreferences() {
|
|
1494
|
+
try {
|
|
1495
|
+
const stored = localStorage.getItem("discoveryPreferences");
|
|
1496
|
+
if (stored) {
|
|
1497
|
+
return JSON.parse(stored);
|
|
1498
|
+
}
|
|
1499
|
+
} catch (_e) {
|
|
1500
|
+
}
|
|
1501
|
+
return {
|
|
1502
|
+
connectionType: "all",
|
|
1503
|
+
sortBy: "name",
|
|
1504
|
+
searchQuery: ""
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
function setDiscoveryPreferences(preferences) {
|
|
1508
|
+
try {
|
|
1509
|
+
localStorage.setItem("discoveryPreferences", JSON.stringify(preferences));
|
|
1510
|
+
} catch (_e) {
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function renderDeviceList(list) {
|
|
1514
|
+
const ul = document.getElementById("devices");
|
|
1515
|
+
const status = document.getElementById("status");
|
|
1516
|
+
const removeAllContainer = document.getElementById("removeAllContainer");
|
|
1517
|
+
if (!ul || !status) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
if (!list.length) {
|
|
1521
|
+
status.textContent = "No devices found in config.";
|
|
1522
|
+
ul.innerHTML = "";
|
|
1523
|
+
if (removeAllContainer) {
|
|
1524
|
+
removeAllContainer.style.display = "none";
|
|
1525
|
+
}
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
status.textContent = `Found ${list.length} device(s)`;
|
|
1529
|
+
ul.innerHTML = "";
|
|
1530
|
+
if (removeAllContainer) {
|
|
1531
|
+
removeAllContainer.style.display = "block";
|
|
1532
|
+
}
|
|
1533
|
+
for (const d of list) {
|
|
1534
|
+
const li = document.createElement("li");
|
|
1535
|
+
li.className = "device-item";
|
|
1536
|
+
li.setAttribute("data-device-id", normalizeId2(d.id));
|
|
1537
|
+
const info = document.createElement("div");
|
|
1538
|
+
info.style.flex = "1";
|
|
1539
|
+
const nameContainer = document.createElement("div");
|
|
1540
|
+
nameContainer.style.display = "flex";
|
|
1541
|
+
nameContainer.style.alignItems = "center";
|
|
1542
|
+
nameContainer.style.flexWrap = "wrap";
|
|
1543
|
+
nameContainer.style.gap = "6px";
|
|
1544
|
+
const name = document.createElement("div");
|
|
1545
|
+
name.style.fontWeight = "500";
|
|
1546
|
+
name.textContent = d.name || d.id;
|
|
1547
|
+
const code = document.createElement("code");
|
|
1548
|
+
code.textContent = d.id;
|
|
1549
|
+
code.style.fontSize = "12px";
|
|
1550
|
+
code.style.opacity = "0.75";
|
|
1551
|
+
code.style.marginLeft = "8px";
|
|
1552
|
+
nameContainer.appendChild(name);
|
|
1553
|
+
nameContainer.appendChild(code);
|
|
1554
|
+
if (d.rssi !== void 0 && d.rssi !== null && d.rssi !== 0) {
|
|
1555
|
+
nameContainer.appendChild(renderSignalBars(d.rssi));
|
|
1556
|
+
nameContainer.appendChild(renderSignalQualityBadge(d.rssi));
|
|
1557
|
+
}
|
|
1558
|
+
const meta = document.createElement("div");
|
|
1559
|
+
meta.style.opacity = "0.75";
|
|
1560
|
+
meta.style.marginTop = "4px";
|
|
1561
|
+
meta.style.fontSize = "12px";
|
|
1562
|
+
const typeText = d.type ? `type: ${d.type}` : "";
|
|
1563
|
+
const connText = d.connectionPreference ? `conn: ${d.connectionPreference}` : "";
|
|
1564
|
+
const roomText = d.room ? `room: ${d.room}` : "";
|
|
1565
|
+
meta.textContent = [typeText, connText, roomText].filter(Boolean).join(" | ");
|
|
1566
|
+
info.appendChild(nameContainer);
|
|
1567
|
+
info.appendChild(meta);
|
|
1568
|
+
const buttons = document.createElement("div");
|
|
1569
|
+
buttons.style.display = "flex";
|
|
1570
|
+
buttons.style.gap = "8px";
|
|
1571
|
+
const editBtn = document.createElement("button");
|
|
1572
|
+
editBtn.textContent = "\u270F\uFE0F Edit";
|
|
1573
|
+
editBtn.style.padding = "6px 12px";
|
|
1574
|
+
editBtn.style.fontSize = "12px";
|
|
1575
|
+
editBtn.onclick = async () => {
|
|
1576
|
+
const { editDevice: editDevice2 } = await Promise.resolve().then(() => (init_modals(), modals_exports));
|
|
1577
|
+
await editDevice2(d);
|
|
1578
|
+
};
|
|
1579
|
+
const copyBtn = document.createElement("button");
|
|
1580
|
+
copyBtn.textContent = "Copy ID";
|
|
1581
|
+
copyBtn.style.padding = "6px 12px";
|
|
1582
|
+
copyBtn.style.fontSize = "12px";
|
|
1583
|
+
copyBtn.addEventListener("click", async () => {
|
|
1584
|
+
try {
|
|
1585
|
+
await navigator.clipboard.writeText(d.id);
|
|
1586
|
+
copyBtn.textContent = "Copied";
|
|
1587
|
+
copyBtn.classList.add("success");
|
|
1588
|
+
setTimeout(() => {
|
|
1589
|
+
copyBtn.textContent = "Copy ID";
|
|
1590
|
+
copyBtn.classList.remove("success");
|
|
1591
|
+
}, 1200);
|
|
1592
|
+
} catch (e) {
|
|
1593
|
+
alert("Failed to copy");
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
const deleteBtn = document.createElement("button");
|
|
1597
|
+
deleteBtn.textContent = "\u{1F5D1}\uFE0F Delete";
|
|
1598
|
+
deleteBtn.style.padding = "6px 12px";
|
|
1599
|
+
deleteBtn.style.fontSize = "12px";
|
|
1600
|
+
deleteBtn.style.background = "#ef4444";
|
|
1601
|
+
deleteBtn.onclick = async () => {
|
|
1602
|
+
const { deleteDeviceFromConfig: deleteDeviceFromConfig2 } = await Promise.resolve().then(() => (init_devices_delete(), devices_delete_exports));
|
|
1603
|
+
await deleteDeviceFromConfig2(d.id, d.name || d.id);
|
|
1604
|
+
};
|
|
1605
|
+
buttons.appendChild(editBtn);
|
|
1606
|
+
buttons.appendChild(copyBtn);
|
|
1607
|
+
buttons.appendChild(deleteBtn);
|
|
1608
|
+
li.appendChild(info);
|
|
1609
|
+
li.appendChild(buttons);
|
|
1610
|
+
ul.appendChild(li);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
var init_render = __esm({
|
|
1614
|
+
"src/homebridge-ui/public/js/render.ts"() {
|
|
1615
|
+
"use strict";
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
|
|
1619
|
+
// src/homebridge-ui/public/js/devices.ts
|
|
1620
|
+
var devices_exports = {};
|
|
1621
|
+
__export(devices_exports, {
|
|
1622
|
+
addDeviceToConfig: () => addDeviceToConfig2,
|
|
1623
|
+
initRemoveAllButton: () => initRemoveAllButton,
|
|
1624
|
+
loadConfiguredDevices: () => loadConfiguredDevices
|
|
1625
|
+
});
|
|
1626
|
+
async function addDeviceToConfig2(device, options = {}) {
|
|
1627
|
+
const { refresh = true, showStatus = true } = options;
|
|
1628
|
+
try {
|
|
1629
|
+
const { importDiscoveredDevice: importDiscoveredDevice2 } = await Promise.resolve().then(() => (init_modals(), modals_exports));
|
|
1630
|
+
const importValues = await importDiscoveredDevice2(device);
|
|
1631
|
+
if (!importValues) {
|
|
1632
|
+
return { added: false };
|
|
1633
|
+
}
|
|
1634
|
+
showBusyUi();
|
|
1635
|
+
uiLog.info("Adding device to config:", device);
|
|
1636
|
+
const resp = await addDevice(device.id, importValues.configDeviceName, importValues.configDeviceType, {
|
|
1637
|
+
address: importValues.address,
|
|
1638
|
+
model: device.model,
|
|
1639
|
+
rssi: device.rssi
|
|
1640
|
+
});
|
|
1641
|
+
uiLog.info("Add device response:", resp);
|
|
1642
|
+
if (!resp || resp.success === false) {
|
|
1643
|
+
throw new Error(resp?.data?.message || "Failed to add device");
|
|
1644
|
+
}
|
|
1645
|
+
const alreadyExists = !!resp?.alreadyExists;
|
|
1646
|
+
const message = resp?.message || (alreadyExists ? `Device "${importValues.configDeviceName}" already in config` : `Device "${importValues.configDeviceName}" added successfully!`);
|
|
1647
|
+
if (alreadyExists) {
|
|
1648
|
+
toastInfo(message);
|
|
1649
|
+
} else {
|
|
1650
|
+
toastSuccess(message);
|
|
1651
|
+
}
|
|
1652
|
+
if (showStatus) {
|
|
1653
|
+
const status = document.getElementById("discoverStatus");
|
|
1654
|
+
if (status) {
|
|
1655
|
+
status.textContent = (alreadyExists ? "\u2022 " : "\u2713 ") + message;
|
|
1656
|
+
status.classList.remove("error");
|
|
1657
|
+
status.classList.add("success-msg");
|
|
1658
|
+
if (!alreadyExists) {
|
|
1659
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
1660
|
+
status.textContent += synced ? " - Config saved automatically." : " - Warning: config may not persist until you close/reopen settings.";
|
|
1661
|
+
if (synced) {
|
|
1662
|
+
toastSuccess("Configuration synced and saved automatically");
|
|
1663
|
+
} else {
|
|
1664
|
+
toastWarning("Configuration sync failed; close and reopen settings before Save");
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
if (refresh) {
|
|
1670
|
+
await loadConfiguredDevices();
|
|
1671
|
+
}
|
|
1672
|
+
return { added: !alreadyExists };
|
|
1673
|
+
} catch (e) {
|
|
1674
|
+
uiLog.error("Add device error:", e);
|
|
1675
|
+
const status = document.getElementById("discoverStatus");
|
|
1676
|
+
if (status) {
|
|
1677
|
+
status.textContent = `\u2717 Error: ${e instanceof Error ? e.message : "Failed to add device"}`;
|
|
1678
|
+
status.classList.add("error");
|
|
1679
|
+
}
|
|
1680
|
+
toastError(e instanceof Error ? e.message : "Failed to add device");
|
|
1681
|
+
return { added: false };
|
|
1682
|
+
} finally {
|
|
1683
|
+
hideBusyUi();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
async function initRemoveAllButton() {
|
|
1687
|
+
const removeAllBtn = document.getElementById("removeAllBtn");
|
|
1688
|
+
if (!removeAllBtn) {
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
removeAllBtn.addEventListener("click", async () => {
|
|
1692
|
+
const { deleteAllDevicesFromConfig: deleteAllDevicesFromConfig2 } = await Promise.resolve().then(() => (init_devices_delete(), devices_delete_exports));
|
|
1693
|
+
await deleteAllDevicesFromConfig2();
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
async function loadConfiguredDevices() {
|
|
1697
|
+
const list = await fetchDevices();
|
|
1698
|
+
renderDeviceList(list);
|
|
1699
|
+
}
|
|
1700
|
+
var init_devices = __esm({
|
|
1701
|
+
"src/homebridge-ui/public/js/devices.ts"() {
|
|
1702
|
+
"use strict";
|
|
1703
|
+
init_api();
|
|
1704
|
+
init_logger();
|
|
1705
|
+
init_modal();
|
|
1706
|
+
init_render();
|
|
1707
|
+
init_toast();
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
// src/homebridge-ui/public/js/credentials.ts
|
|
1712
|
+
init_api();
|
|
1713
|
+
init_logger();
|
|
1714
|
+
init_modal();
|
|
1715
|
+
init_toast();
|
|
1716
|
+
async function loadCredentialStatus() {
|
|
1717
|
+
try {
|
|
1718
|
+
const creds = await fetchCredentialStatus();
|
|
1719
|
+
if (!creds) {
|
|
1720
|
+
uiLog.error("Failed to load credentials");
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
const tokenStatus = document.getElementById("tokenStatus");
|
|
1724
|
+
const secretStatus = document.getElementById("secretStatus");
|
|
1725
|
+
if (!tokenStatus || !secretStatus) {
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
if (creds.hasToken) {
|
|
1729
|
+
tokenStatus.textContent = `\u2713 Configured (${creds.tokenLength} characters)`;
|
|
1730
|
+
tokenStatus.classList.add("ok");
|
|
1731
|
+
} else {
|
|
1732
|
+
tokenStatus.textContent = "Not configured";
|
|
1733
|
+
tokenStatus.classList.remove("ok");
|
|
1734
|
+
}
|
|
1735
|
+
if (creds.hasSecret) {
|
|
1736
|
+
secretStatus.textContent = `\u2713 Configured (${creds.secretLength} characters)`;
|
|
1737
|
+
secretStatus.classList.add("ok");
|
|
1738
|
+
} else {
|
|
1739
|
+
secretStatus.textContent = "Not configured";
|
|
1740
|
+
secretStatus.classList.remove("ok");
|
|
1741
|
+
}
|
|
1742
|
+
} catch (e) {
|
|
1743
|
+
uiLog.error("Error loading credentials:", e);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
async function saveCredentials2() {
|
|
1747
|
+
const token = document.getElementById("token")?.value;
|
|
1748
|
+
const secret = document.getElementById("secret")?.value;
|
|
1749
|
+
const saveStatus = document.getElementById("saveStatus");
|
|
1750
|
+
const saveBtn = document.getElementById("saveBtn");
|
|
1751
|
+
if (!saveStatus || !saveBtn) {
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
if (!token || !secret) {
|
|
1755
|
+
saveStatus.textContent = "Please enter both token and secret";
|
|
1756
|
+
saveStatus.classList.add("error");
|
|
1757
|
+
toastWarning("Please enter both token and secret");
|
|
1758
|
+
return;
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
showBusyUi();
|
|
1762
|
+
saveBtn.disabled = true;
|
|
1763
|
+
saveBtn.textContent = "Saving...";
|
|
1764
|
+
uiLog.info("Saving credentials...");
|
|
1765
|
+
const result = await saveCredentials(token, secret);
|
|
1766
|
+
uiLog.info("Save response:", result);
|
|
1767
|
+
const message = result?.message || "Credentials saved successfully";
|
|
1768
|
+
saveStatus.textContent = `\u2713 ${message}`;
|
|
1769
|
+
saveStatus.classList.remove("error");
|
|
1770
|
+
saveStatus.classList.add("success-msg");
|
|
1771
|
+
toastSuccess(message);
|
|
1772
|
+
const synced = await syncParentPluginConfigFromDisk(true);
|
|
1773
|
+
if (synced) {
|
|
1774
|
+
saveStatus.textContent += " - Config saved automatically.";
|
|
1775
|
+
toastSuccess("Configuration synced and saved automatically");
|
|
1776
|
+
} else {
|
|
1777
|
+
toastWarning("Credentials saved, but configuration sync failed");
|
|
1778
|
+
}
|
|
1779
|
+
;
|
|
1780
|
+
document.getElementById("token").value = "";
|
|
1781
|
+
document.getElementById("secret").value = "";
|
|
1782
|
+
setTimeout(() => loadCredentialStatus(), 500);
|
|
1783
|
+
setTimeout(() => {
|
|
1784
|
+
saveStatus.textContent = "";
|
|
1785
|
+
saveStatus.classList.remove("success-msg");
|
|
1786
|
+
}, 3e3);
|
|
1787
|
+
} catch (e) {
|
|
1788
|
+
uiLog.error("Save error:", e);
|
|
1789
|
+
saveStatus.textContent = `Error: ${e instanceof Error ? e.message : "Failed to save"}`;
|
|
1790
|
+
saveStatus.classList.add("error");
|
|
1791
|
+
toastError(e instanceof Error ? e.message : "Failed to save credentials");
|
|
1792
|
+
} finally {
|
|
1793
|
+
hideBusyUi();
|
|
1794
|
+
saveBtn.disabled = false;
|
|
1795
|
+
saveBtn.textContent = "Save Credentials";
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
// src/homebridge-ui/public/js/app.ts
|
|
1800
|
+
init_devices();
|
|
1801
|
+
init_discovery();
|
|
1802
|
+
window.loadCredentialStatus = loadCredentialStatus;
|
|
1803
|
+
window.saveCredentials = saveCredentials2;
|
|
1804
|
+
window.discoverDevices = discoverDevices2;
|
|
1805
|
+
async function init() {
|
|
1806
|
+
await loadCredentialStatus();
|
|
1807
|
+
const list = await loadConfiguredDevices();
|
|
1808
|
+
await initRemoveAllButton();
|
|
1809
|
+
}
|
|
1810
|
+
if (document.readyState === "loading") {
|
|
1811
|
+
document.addEventListener("DOMContentLoaded", init);
|
|
1812
|
+
} else {
|
|
1813
|
+
init();
|
|
1814
|
+
}
|
|
1815
|
+
//# sourceMappingURL=app.js.map
|