@switchbot/homebridge-switchbot 5.0.0-beta.13 → 5.0.0-beta.130
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 +54 -0
- package/README.md +99 -3
- package/TODO.md +263 -0
- package/config.schema.json +198 -14787
- package/dist/device-types.d.ts +31 -0
- package/dist/device-types.d.ts.map +1 -0
- package/dist/device-types.js +246 -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 +146 -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 +277 -0
- package/dist/devices/genericDevice.d.ts.map +1 -0
- package/dist/devices/genericDevice.js +1383 -0
- package/dist/devices/genericDevice.js.map +1 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +51 -0
- package/dist/errors.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 +107 -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 +430 -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 +212 -0
- package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/css/styles.css +447 -0
- package/dist/homebridge-ui/public/index.html +144 -248
- package/dist/homebridge-ui/public/js/api.d.ts +62 -0
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/api.js +225 -0
- package/dist/homebridge-ui/public/js/api.js.map +1 -0
- package/dist/homebridge-ui/public/js/api.ts +279 -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 +3600 -0
- package/dist/homebridge-ui/public/js/app.js.map +7 -0
- package/dist/homebridge-ui/public/js/app.ts +23 -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 +94 -0
- package/dist/homebridge-ui/public/js/devices.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices.ts +114 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts +4 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.js +1364 -0
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.ts +1492 -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 +494 -0
- package/dist/homebridge-ui/public/js/modals.js.map +1 -0
- package/dist/homebridge-ui/public/js/modals.ts +546 -0
- package/dist/homebridge-ui/public/js/render.d.ts +68 -0
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/render.js +914 -0
- package/dist/homebridge-ui/public/js/render.js.map +1 -0
- package/dist/homebridge-ui/public/js/render.ts +1026 -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 +1 -3
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +39 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +1570 -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 +253 -0
- package/dist/switchbotClient.js.map +1 -0
- package/dist/utils.d.ts +36 -82
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +40 -786
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +21 -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 +103 -13
- package/docs/variables/default.html +1 -1
- package/eslint.config.js +7 -8
- package/nodemon.json +2 -2
- package/package.json +36 -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 +261 -0
- package/src/deviceFactory.ts +190 -0
- package/src/devices/deviceBase.ts +141 -0
- package/src/devices/genericDevice.ts +1333 -0
- package/src/errors.ts +43 -0
- package/src/homebridge-ui/endpoints/config.ts +126 -0
- package/src/homebridge-ui/endpoints/credentials.ts +74 -0
- package/src/homebridge-ui/endpoints/devices.ts +464 -0
- package/src/homebridge-ui/endpoints/discovery.ts +233 -0
- package/src/homebridge-ui/public/css/styles.css +447 -0
- package/src/homebridge-ui/public/index.html +144 -248
- package/src/homebridge-ui/public/js/api.ts +279 -0
- package/src/homebridge-ui/public/js/app.ts +23 -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 +114 -0
- package/src/homebridge-ui/public/js/discovery.ts +1492 -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 +546 -0
- package/src/homebridge-ui/public/js/render.ts +1026 -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 +1 -3
- package/src/platform.ts +1585 -0
- package/src/settings.ts +12 -277
- package/src/switchbotClient.ts +251 -0
- package/src/utils.ts +48 -812
- 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 +52 -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 +136 -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 +542 -0
- package/todo/README.md +59 -0
- package/todo/TODO.md +190 -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/baseMatterAccessory.test.d.ts +0 -2
- package/dist/baseMatterAccessory.test.d.ts.map +0 -1
- package/dist/baseMatterAccessory.test.js +0 -71
- package/dist/baseMatterAccessory.test.js.map +0 -1
- 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 -78
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +0 -1
- package/dist/devices-matter/BaseMatterAccessory.js +0 -220
- 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 -76
- 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 -106
- 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 -110
- package/dist/devices-matter/OnOffLightAccessory.js.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +0 -14
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +0 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +0 -43
- 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 -999
- package/dist/platform-matter.js.map +0 -1
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/utils.test.js +0 -95
- package/dist/utils.test.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/baseMatterAccessory.test.ts +0 -88
- 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 -249
- package/src/devices-matter/ColorLightAccessory.ts +0 -110
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +0 -90
- 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 -122
- 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 -125
- package/src/devices-matter/OnOffOutletAccessory.ts +0 -51
- 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 -1124
- package/src/utils.test.ts +0 -96
- package/src/verifyconfig.test.ts +0 -197
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import './types.js'
|
|
2
|
+
import { uiLog } from './logger.js'
|
|
3
|
+
|
|
4
|
+
function showToast(
|
|
5
|
+
method: 'success' | 'error' | 'warning' | 'info',
|
|
6
|
+
message: string,
|
|
7
|
+
title = 'SwitchBot',
|
|
8
|
+
): void {
|
|
9
|
+
try {
|
|
10
|
+
const toast = homebridge?.toast
|
|
11
|
+
const fn = toast?.[method]
|
|
12
|
+
if (typeof fn === 'function') {
|
|
13
|
+
fn(message, title)
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
uiLog.info(`[Toast:${method}] ${title} - ${message}`)
|
|
18
|
+
} catch (e) {
|
|
19
|
+
uiLog.warn(`Toast ${method} failed:`, e)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function toastSuccess(message: string, title?: string): void {
|
|
24
|
+
showToast('success', message, title)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function toastError(message: string, title?: string): void {
|
|
28
|
+
showToast('error', message, title)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function toastWarning(message: string, title?: string): void {
|
|
32
|
+
showToast('warning', message, title)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function toastInfo(message: string, title?: string): void {
|
|
36
|
+
showToast('info', message, title)
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Global homebridge API type declarations
|
|
2
|
+
declare global {
|
|
3
|
+
interface HomebridgeToastApi {
|
|
4
|
+
success?: (message: string, title?: string) => void
|
|
5
|
+
error?: (message: string, title?: string) => void
|
|
6
|
+
warning?: (message: string, title?: string) => void
|
|
7
|
+
info?: (message: string, title?: string) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface HomebridgePluginUiAPI {
|
|
11
|
+
request: (endpoint: string, params?: any) => Promise<any>
|
|
12
|
+
getPluginConfig?: () => Promise<any[]>
|
|
13
|
+
updatePluginConfig?: (config: any[]) => Promise<void>
|
|
14
|
+
savePluginConfig?: () => Promise<void>
|
|
15
|
+
closeSettings?: () => void
|
|
16
|
+
showSpinner?: () => void
|
|
17
|
+
hideSpinner?: () => void
|
|
18
|
+
disableSaveButton?: () => void
|
|
19
|
+
enableSaveButton?: () => void
|
|
20
|
+
toast?: HomebridgeToastApi
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let homebridge: HomebridgePluginUiAPI
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {}
|
|
@@ -1,48 +1,16 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
|
|
3
1
|
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
10
|
-
The following is for users who have a lower version of config-ui-x
|
|
11
|
-
*/
|
|
12
|
-
this.onRequest('getCachedAccessories', () => {
|
|
13
|
-
try {
|
|
14
|
-
const plugin = 'homebridge-switchbot'
|
|
15
|
-
const devicesToReturn = []
|
|
16
|
-
|
|
17
|
-
// The path and file of the cached accessories
|
|
18
|
-
const accFile = `${this.homebridgeStoragePath}/accessories/cachedAccessories`
|
|
19
|
-
|
|
20
|
-
// Check the file exists
|
|
21
|
-
if (fs.existsSync(accFile)) {
|
|
22
|
-
// read the cached accessories file
|
|
23
|
-
const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8'))
|
|
3
|
+
import { registerConfigEndpoints } from './endpoints/config.js'
|
|
4
|
+
import { registerCredentialsEndpoint } from './endpoints/credentials.js'
|
|
5
|
+
import { registerDeviceEndpoints } from './endpoints/devices.js'
|
|
6
|
+
import { registerDiscoveryEndpoint } from './endpoints/discovery.js'
|
|
24
7
|
|
|
25
|
-
|
|
26
|
-
// Check the accessory is from this plugin
|
|
27
|
-
if (accessory.plugin === plugin) {
|
|
28
|
-
// Add the cached accessory to the array
|
|
29
|
-
devicesToReturn.push(accessory.accessory as never)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
// Return the array
|
|
34
|
-
return devicesToReturn
|
|
35
|
-
} catch {
|
|
36
|
-
// Just return an empty accessory list in case of any errors
|
|
37
|
-
return []
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
this.ready()
|
|
41
|
-
}
|
|
42
|
-
}
|
|
8
|
+
const server = new HomebridgePluginUiServer()
|
|
43
9
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
10
|
+
// Register all endpoints
|
|
11
|
+
registerConfigEndpoints(server)
|
|
12
|
+
registerDiscoveryEndpoint(server)
|
|
13
|
+
registerDeviceEndpoints(server)
|
|
14
|
+
registerCredentialsEndpoint(server)
|
|
47
15
|
|
|
48
|
-
|
|
16
|
+
server.ready()
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
|
|
5
|
+
import { uiLog } from './logger.js'
|
|
6
|
+
|
|
7
|
+
// Module-scope regex pattern to avoid recompilation
|
|
8
|
+
export const SWITCHBOT_PLATFORM_REGEX = /switchbot/i
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get reference to the devices array in platform config
|
|
12
|
+
*/
|
|
13
|
+
export function getDevicesRef(platform: any): any[] {
|
|
14
|
+
if (!platform || typeof platform !== 'object') {
|
|
15
|
+
return []
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Array.isArray(platform.devices)) {
|
|
19
|
+
return platform.devices
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
platform.devices = []
|
|
23
|
+
return platform.devices
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get all device arrays from platform config
|
|
28
|
+
*/
|
|
29
|
+
export function getDeviceArrays(platform: any): any[][] {
|
|
30
|
+
const rootDevices = getDevicesRef(platform)
|
|
31
|
+
return [rootDevices]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get all unique devices from platform config
|
|
36
|
+
*/
|
|
37
|
+
export function getAllDevices(platform: any): any[] {
|
|
38
|
+
const all = getDevicesRef(platform)
|
|
39
|
+
const seen = new Set<string>()
|
|
40
|
+
|
|
41
|
+
return all.filter((d: any) => {
|
|
42
|
+
const id = String(d?.deviceId ?? d?.id ?? '').trim().toLowerCase()
|
|
43
|
+
if (!id || seen.has(id)) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
seen.add(id)
|
|
47
|
+
return true
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get credential from platform config
|
|
53
|
+
*/
|
|
54
|
+
export function getCredential(platform: any, key: 'openApiToken' | 'openApiSecret'): string | undefined {
|
|
55
|
+
return platform?.[key]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Set credential in platform config
|
|
60
|
+
*/
|
|
61
|
+
export function setCredential(platform: any, key: 'openApiToken' | 'openApiSecret', value: string): void {
|
|
62
|
+
if (!platform || typeof platform !== 'object') {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
platform[key] = value
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Find and parse the SwitchBot platform config from Homebridge config file
|
|
71
|
+
*/
|
|
72
|
+
export async function getSwitchBotPlatformConfig(server: HomebridgePluginUiServer) {
|
|
73
|
+
const cfgPath = server.homebridgeConfigPath
|
|
74
|
+
if (!cfgPath) {
|
|
75
|
+
throw new Error('HOMEBRIDGE_CONFIG_PATH not set')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const raw = await fs.readFile(cfgPath, 'utf-8')
|
|
79
|
+
const cfg = JSON.parse(raw)
|
|
80
|
+
|
|
81
|
+
const platforms = Array.isArray(cfg.platforms) ? cfg.platforms : []
|
|
82
|
+
|
|
83
|
+
const candidates = platforms.filter((p: any) => {
|
|
84
|
+
const platformName = p.platform || p.name || ''
|
|
85
|
+
return !!platformName && (SWITCHBOT_PLATFORM_REGEX.test(String(platformName)) || String(platformName).toLowerCase() === '@switchbot/homebridge-switchbot')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
uiLog.info(`Found ${candidates.length} SwitchBot candidate(s)`)
|
|
89
|
+
|
|
90
|
+
const platform = candidates.find((p: any) => {
|
|
91
|
+
const name = String(p.platform || '').toLowerCase()
|
|
92
|
+
return name === 'switchbot' || name.includes('switchbot')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
if (!platform) {
|
|
96
|
+
throw new Error('SwitchBot platform not found in config. Please add the plugin configuration first.')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
uiLog.info(`Using SwitchBot platform: ${platform.name || platform.platform || 'SwitchBot'}`)
|
|
100
|
+
return { platform, cfg, cfgPath }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Save the Homebridge config file
|
|
105
|
+
*/
|
|
106
|
+
export async function saveConfig(cfgPath: string, cfg: any): Promise<void> {
|
|
107
|
+
await fs.writeFile(cfgPath, JSON.stringify(cfg, null, 2), 'utf-8')
|
|
108
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { DEVICE_TYPES, isValidDeviceType, normalizeDeviceType } from '../../device-types.js'
|
|
2
|
+
|
|
3
|
+
export interface DeviceMigrationResult {
|
|
4
|
+
migrated: boolean
|
|
5
|
+
originalType: string | undefined
|
|
6
|
+
correctedType: string | null
|
|
7
|
+
message: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Validate and optionally correct a device's configDeviceType
|
|
12
|
+
* @param device Device object from config
|
|
13
|
+
* @param autoCorrect Whether to auto-correct invalid types
|
|
14
|
+
* @returns Migration result with details
|
|
15
|
+
*/
|
|
16
|
+
export function validateAndMigrateDeviceType(
|
|
17
|
+
device: any,
|
|
18
|
+
autoCorrect = false,
|
|
19
|
+
): DeviceMigrationResult {
|
|
20
|
+
const originalType = device.configDeviceType
|
|
21
|
+
const deviceId = device.deviceId || device.id || 'unknown'
|
|
22
|
+
|
|
23
|
+
// Check if type is valid
|
|
24
|
+
if (isValidDeviceType(originalType)) {
|
|
25
|
+
return {
|
|
26
|
+
migrated: false,
|
|
27
|
+
originalType,
|
|
28
|
+
correctedType: originalType,
|
|
29
|
+
message: `Device "${device.configDeviceName || deviceId}" type is valid`,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Try to find a valid mapping
|
|
34
|
+
const correctedType = normalizeDeviceType(originalType)
|
|
35
|
+
|
|
36
|
+
if (!correctedType) {
|
|
37
|
+
return {
|
|
38
|
+
migrated: false,
|
|
39
|
+
originalType,
|
|
40
|
+
correctedType: null,
|
|
41
|
+
message: `Device "${device.configDeviceName || deviceId}" has invalid type "${originalType}" with no valid mapping`,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Found a valid mapping
|
|
46
|
+
if (autoCorrect) {
|
|
47
|
+
device.configDeviceType = correctedType
|
|
48
|
+
return {
|
|
49
|
+
migrated: true,
|
|
50
|
+
originalType,
|
|
51
|
+
correctedType,
|
|
52
|
+
message: `Device "${device.configDeviceName || deviceId}" type auto-corrected: "${originalType}" → "${correctedType}"`,
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
return {
|
|
56
|
+
migrated: false,
|
|
57
|
+
originalType,
|
|
58
|
+
correctedType,
|
|
59
|
+
message: `Device "${device.configDeviceName || deviceId}" requires migration: "${originalType}" → "${correctedType}"`,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Validate all devices in config and optionally auto-correct invalid types
|
|
66
|
+
* @param config Configuration object containing devices array
|
|
67
|
+
* @param autoCorrect Whether to auto-correct invalid types
|
|
68
|
+
* @returns Array of migration results with statistics
|
|
69
|
+
*/
|
|
70
|
+
export function validateAndMigrateConfig(
|
|
71
|
+
config: any,
|
|
72
|
+
autoCorrect = false,
|
|
73
|
+
): {
|
|
74
|
+
results: DeviceMigrationResult[]
|
|
75
|
+
statistics: {
|
|
76
|
+
total: number
|
|
77
|
+
valid: number
|
|
78
|
+
corrected: number
|
|
79
|
+
invalid: number
|
|
80
|
+
}
|
|
81
|
+
warnings: string[]
|
|
82
|
+
} {
|
|
83
|
+
const results: DeviceMigrationResult[] = []
|
|
84
|
+
const warnings: string[] = []
|
|
85
|
+
let validCount = 0
|
|
86
|
+
let correctedCount = 0
|
|
87
|
+
let invalidCount = 0
|
|
88
|
+
|
|
89
|
+
if (!config?.devices || !Array.isArray(config.devices)) {
|
|
90
|
+
return {
|
|
91
|
+
results,
|
|
92
|
+
statistics: {
|
|
93
|
+
total: 0,
|
|
94
|
+
valid: 0,
|
|
95
|
+
corrected: 0,
|
|
96
|
+
invalid: 0,
|
|
97
|
+
},
|
|
98
|
+
warnings: ['No devices found in config'],
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const device of config.devices) {
|
|
103
|
+
const result = validateAndMigrateDeviceType(device, autoCorrect)
|
|
104
|
+
results.push(result)
|
|
105
|
+
|
|
106
|
+
if (!result.originalType || isValidDeviceType(result.originalType)) {
|
|
107
|
+
validCount++
|
|
108
|
+
} else if (result.migrated) {
|
|
109
|
+
correctedCount++
|
|
110
|
+
} else if (result.correctedType) {
|
|
111
|
+
warnings.push(
|
|
112
|
+
`Device "${device.configDeviceName || device.deviceId}" needs correction: "${result.originalType}" → "${result.correctedType}"`,
|
|
113
|
+
)
|
|
114
|
+
invalidCount++
|
|
115
|
+
} else {
|
|
116
|
+
invalidCount++
|
|
117
|
+
warnings.push(
|
|
118
|
+
`Device "${device.configDeviceName || device.deviceId}" has INVALID type "${result.originalType}" with no mapping`,
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Validation complete - results and warnings are returned via return value
|
|
124
|
+
// Caller (config endpoint) will handle logging/reporting
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
results,
|
|
128
|
+
statistics: {
|
|
129
|
+
total: config.devices.length,
|
|
130
|
+
valid: validCount,
|
|
131
|
+
corrected: correctedCount,
|
|
132
|
+
invalid: invalidCount,
|
|
133
|
+
},
|
|
134
|
+
warnings,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get list of all valid device types for error messages
|
|
140
|
+
* @returns Array of valid device types grouped by category
|
|
141
|
+
*/
|
|
142
|
+
export function getValidDeviceTypesList(): Record<string, readonly string[]> {
|
|
143
|
+
return DEVICE_TYPES
|
|
144
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const PREFIX = '[SwitchBot UI]'
|
|
3
|
+
|
|
4
|
+
export const uiLog = {
|
|
5
|
+
info: (message: string, ...parameters: any[]) => {
|
|
6
|
+
console.log(PREFIX, message, ...parameters)
|
|
7
|
+
},
|
|
8
|
+
warn: (message: string, ...parameters: any[]) => {
|
|
9
|
+
console.warn(PREFIX, message, ...parameters)
|
|
10
|
+
},
|
|
11
|
+
error: (message: string, ...parameters: any[]) => {
|
|
12
|
+
console.error(PREFIX, message, ...parameters)
|
|
13
|
+
},
|
|
14
|
+
debug: (message: string, ...parameters: any[]) => {
|
|
15
|
+
console.debug(PREFIX, message, ...parameters)
|
|
16
|
+
},
|
|
17
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { API } from 'homebridge'
|
|
6
6
|
|
|
7
|
-
import { SwitchBotHAPPlatform } from './platform
|
|
8
|
-
import { SwitchBotMatterPlatform } from './platform-matter.js'
|
|
7
|
+
import { SwitchBotHAPPlatform, SwitchBotMatterPlatform } from './platform.js'
|
|
9
8
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
10
9
|
import { createPlatformProxy } from './utils.js'
|
|
11
10
|
|
|
12
11
|
// Register our platform with homebridge.
|
|
13
12
|
export default (api: API): void => {
|
|
14
|
-
// Create and register a small proxy that selects the correct platform (HAP or Matter) at runtime.
|
|
15
13
|
const ProxyCtor = createPlatformProxy(SwitchBotHAPPlatform, SwitchBotMatterPlatform)
|
|
16
14
|
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, ProxyCtor as any)
|
|
17
15
|
}
|