@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,1383 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { MATTER_ATTRIBUTE_IDS, MATTER_CLUSTER_IDS } from '../utils.js';
|
|
3
|
+
import { DeviceBase } from './deviceBase.js';
|
|
4
|
+
function validateBLEResponseLength(buf, expected, context = '') {
|
|
5
|
+
if (!buf || typeof buf.length !== 'number' || buf.length !== expected) {
|
|
6
|
+
console.warn(`[BLE] Invalid response length${context ? ` for ${context}` : ''}: expected ${expected}, got ${buf?.length}`);
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
// BLE notification handling: per-command notification futures and unsolicited notification logging
|
|
12
|
+
const BLE_NOTIFICATION_HANDLERS = new Map();
|
|
13
|
+
// Module-scope regex pattern to avoid recompilation
|
|
14
|
+
const HEX_COLOR_REGEX = /^#?[0-9A-F]{6}$/i;
|
|
15
|
+
export class GenericDevice extends DeviceBase {
|
|
16
|
+
log;
|
|
17
|
+
constructor(opts, cfg) {
|
|
18
|
+
super(opts, cfg);
|
|
19
|
+
// Prefer logger from opts, then cfg, fallback to console
|
|
20
|
+
this.log = opts?.log || cfg?.log || console;
|
|
21
|
+
// If BLE encryptionKey/keyId provided, set on node-switchbot device instance if possible
|
|
22
|
+
if (opts.encryptionKey && this.client && typeof this.client.devices?.get === 'function') {
|
|
23
|
+
try {
|
|
24
|
+
const dev = this.client.devices.get(opts.id);
|
|
25
|
+
if (dev && typeof dev.setKey === 'function') {
|
|
26
|
+
dev.setKey({
|
|
27
|
+
encryptionKey: opts.encryptionKey,
|
|
28
|
+
keyId: opts.keyId || undefined,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// ignore if device not found or setKey not available
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Ensure log is always set
|
|
37
|
+
if (!this.log) {
|
|
38
|
+
this.log = console;
|
|
39
|
+
}
|
|
40
|
+
// Subscribe to BLE notifications if supported (node-switchbot v4+)
|
|
41
|
+
this._subscribeBLENotifications();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to BLE notifications for this device (if supported by node-switchbot)
|
|
45
|
+
* Logs unsolicited notifications and enables per-command notification futures.
|
|
46
|
+
*/
|
|
47
|
+
async _subscribeBLENotifications() {
|
|
48
|
+
if (!this.client || typeof this.client.devices?.get !== 'function') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const dev = this.client.devices.get(this.opts.id);
|
|
52
|
+
if (!dev || typeof dev.mac !== 'string' || !dev.mac) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Only subscribe once per device
|
|
56
|
+
if (BLE_NOTIFICATION_HANDLERS.has(dev.mac)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (typeof dev.subscribeNotifications === 'function') {
|
|
60
|
+
const handler = (payload) => {
|
|
61
|
+
// If a per-command notification future is waiting, let node-switchbot handle it
|
|
62
|
+
// Otherwise, log unsolicited notification
|
|
63
|
+
if (payload && payload.length > 0) {
|
|
64
|
+
// Unsolicited notification logging
|
|
65
|
+
// (node-switchbot will resolve per-command futures internally)
|
|
66
|
+
this.log.debug(`[BLE] Unsolicited notification from ${dev.mac}: ${payload.toString('hex')}`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
// Subscribe and remember handler for possible cleanup
|
|
71
|
+
await dev.subscribeNotifications(handler);
|
|
72
|
+
BLE_NOTIFICATION_HANDLERS.set(dev.mac, handler);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// ignore if subscription fails
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Await a BLE notification for this device (for advanced use in subclasses)
|
|
81
|
+
* Returns the notification payload or throws on timeout.
|
|
82
|
+
*/
|
|
83
|
+
async _awaitBLENotification(timeoutMs = 5000) {
|
|
84
|
+
if (!this.client || typeof this.client.devices?.get !== 'function') {
|
|
85
|
+
throw new Error('No BLE client/device');
|
|
86
|
+
}
|
|
87
|
+
const dev = this.client.devices.get(this.opts.id);
|
|
88
|
+
if (!dev || typeof dev.mac !== 'string' || !dev.mac) {
|
|
89
|
+
throw new Error('No BLE MAC for device');
|
|
90
|
+
}
|
|
91
|
+
if (typeof dev.bleConnection?.sendCommand !== 'function') {
|
|
92
|
+
throw new TypeError('BLE connection does not support sendCommand');
|
|
93
|
+
}
|
|
94
|
+
// This is a low-level utility; in most cases, node-switchbot handles notification futures for commands
|
|
95
|
+
// Here, we expose a direct await for advanced use
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
let timer;
|
|
98
|
+
const handler = (payload) => {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
dev.bleConnection?.unsubscribeNotifications(dev.mac, handler);
|
|
101
|
+
resolve(payload);
|
|
102
|
+
};
|
|
103
|
+
dev.bleConnection?.subscribeNotifications(dev.mac, handler).then(() => {
|
|
104
|
+
timer = setTimeout(() => {
|
|
105
|
+
dev.bleConnection?.unsubscribeNotifications(dev.mac, handler);
|
|
106
|
+
reject(new Error('BLE notification timeout'));
|
|
107
|
+
}, timeoutMs);
|
|
108
|
+
}).catch(reject);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async getState() {
|
|
112
|
+
// Default: return minimal info; implementations should override
|
|
113
|
+
if (this.client && typeof this.client.getDevice === 'function') {
|
|
114
|
+
try {
|
|
115
|
+
const raw = await this.client.getDevice(this.opts.id);
|
|
116
|
+
// If this is a BLE buffer/array, validate length (common BLE status: 12 bytes, but may vary by device)
|
|
117
|
+
if (raw && (raw instanceof Buffer || Array.isArray(raw) || raw instanceof Uint8Array)) {
|
|
118
|
+
// Default to 12, override per device if needed
|
|
119
|
+
if (!validateBLEResponseLength(raw, 12, this.opts.type)) {
|
|
120
|
+
return { id: this.opts.id, type: this.opts.type, error: 'invalid_ble_response_length', raw };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Normalize common response shapes
|
|
124
|
+
try {
|
|
125
|
+
const device = raw?.body ?? raw;
|
|
126
|
+
return device;
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
return raw;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
// ignore and fallback
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { id: this.opts.id, type: this.opts.type };
|
|
137
|
+
}
|
|
138
|
+
async setState(change) {
|
|
139
|
+
// Apply change via SwitchBot API in real implementation
|
|
140
|
+
// Translate common high-level changes into SwitchBot OpenAPI commands
|
|
141
|
+
if (!this.client) {
|
|
142
|
+
return { success: false, reason: 'no client', change };
|
|
143
|
+
}
|
|
144
|
+
const cmdBody = {};
|
|
145
|
+
if (typeof change.on === 'boolean') {
|
|
146
|
+
cmdBody.command = change.on ? 'turnOn' : 'turnOff';
|
|
147
|
+
cmdBody.parameter = 'default';
|
|
148
|
+
cmdBody.commandType = 'command';
|
|
149
|
+
}
|
|
150
|
+
else if (typeof change.brightness === 'number') {
|
|
151
|
+
const v = Math.max(0, Math.min(100, Number(change.brightness)));
|
|
152
|
+
cmdBody.command = 'setBrightness';
|
|
153
|
+
cmdBody.parameter = String(v);
|
|
154
|
+
cmdBody.commandType = 'command';
|
|
155
|
+
}
|
|
156
|
+
else if (typeof change.speed === 'number') {
|
|
157
|
+
const v = Math.max(0, Math.min(100, Number(change.speed)));
|
|
158
|
+
cmdBody.command = 'setFanSpeed';
|
|
159
|
+
cmdBody.parameter = String(v);
|
|
160
|
+
cmdBody.commandType = 'command';
|
|
161
|
+
}
|
|
162
|
+
else if (typeof change.position === 'number') {
|
|
163
|
+
const v = Math.max(0, Math.min(100, Number(change.position)));
|
|
164
|
+
cmdBody.command = 'setPosition';
|
|
165
|
+
cmdBody.parameter = String(v);
|
|
166
|
+
cmdBody.commandType = 'command';
|
|
167
|
+
}
|
|
168
|
+
else if (typeof change.locked === 'boolean') {
|
|
169
|
+
cmdBody.command = change.locked ? 'lock' : 'unlock';
|
|
170
|
+
cmdBody.parameter = 'default';
|
|
171
|
+
cmdBody.commandType = 'command';
|
|
172
|
+
}
|
|
173
|
+
else if (typeof change.start === 'boolean') {
|
|
174
|
+
cmdBody.command = change.start ? 'start' : 'stop';
|
|
175
|
+
cmdBody.parameter = 'default';
|
|
176
|
+
cmdBody.commandType = 'command';
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// If caller supplied an explicit command body, pass through
|
|
180
|
+
if (change && typeof change.command === 'string') {
|
|
181
|
+
Object.assign(cmdBody, change);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Fallback: send raw change to client setDeviceState
|
|
185
|
+
try {
|
|
186
|
+
if (typeof this.client.setDeviceState === 'function') {
|
|
187
|
+
return await this.client.setDeviceState(this.opts.id, change);
|
|
188
|
+
}
|
|
189
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
190
|
+
return await this.client.sendCommand(this.opts.id, change);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
const e = err;
|
|
195
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
196
|
+
}
|
|
197
|
+
return { success: false, reason: 'unsupported change', change };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
return await this.client.setDeviceState(this.opts.id, cmdBody);
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
// try alternative client API if available
|
|
205
|
+
try {
|
|
206
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
207
|
+
return await this.client.sendCommand(this.opts.id, cmdBody);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e2) {
|
|
211
|
+
// ignore
|
|
212
|
+
}
|
|
213
|
+
const e = err;
|
|
214
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
createHAPAccessory(api) {
|
|
218
|
+
// Default HAP descriptor: a Switch service with On characteristic
|
|
219
|
+
return {
|
|
220
|
+
services: [
|
|
221
|
+
{
|
|
222
|
+
type: 'Switch',
|
|
223
|
+
characteristics: {
|
|
224
|
+
On: {
|
|
225
|
+
get: async () => {
|
|
226
|
+
const s = await this.getState();
|
|
227
|
+
return !!(s && (s.on === true || s.state === 'on' || s.power === 'on'));
|
|
228
|
+
},
|
|
229
|
+
set: async (v) => {
|
|
230
|
+
await this.setState({ on: !!v });
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// Default Matter descriptor mirrors HAP descriptor structure so the
|
|
239
|
+
// platform can construct a Matter accessory representation when
|
|
240
|
+
// Homebridge Matter APIs are available. Device subclasses may override
|
|
241
|
+
// this to provide Matter-specific clusters/attributes if desired.
|
|
242
|
+
async createMatterAccessory(api) {
|
|
243
|
+
// Dynamically detect features from getState()
|
|
244
|
+
const state = await this.getState();
|
|
245
|
+
const clusters = [];
|
|
246
|
+
// On/Off (Switch/Plug/Generic)
|
|
247
|
+
if ('on' in state || 'power' in state || 'state' in state) {
|
|
248
|
+
clusters.push({
|
|
249
|
+
type: 'OnOff',
|
|
250
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
251
|
+
attributes: {
|
|
252
|
+
onOff: { read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on', write: async (v) => this.setState({ on: !!v }) },
|
|
253
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => !!(await this.getState()).on || (await this.getState()).power === 'on' || (await this.getState()).state === 'on', write: async (v) => this.setState({ on: !!v }) },
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
// Brightness (Light)
|
|
258
|
+
if ('brightness' in state) {
|
|
259
|
+
clusters.push({
|
|
260
|
+
type: 'LevelControl',
|
|
261
|
+
clusterId: MATTER_CLUSTER_IDS.LevelControl,
|
|
262
|
+
attributes: {
|
|
263
|
+
currentLevel: { read: async () => (await this.getState()).brightness ?? 100, write: async (v) => this.setState({ brightness: Number(v) }) },
|
|
264
|
+
[MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => (await this.getState()).brightness ?? 100, write: async (v) => this.setState({ brightness: Number(v) }) },
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// Color (Light)
|
|
269
|
+
if ('hue' in state && 'saturation' in state) {
|
|
270
|
+
clusters.push({
|
|
271
|
+
type: 'ColorControl',
|
|
272
|
+
clusterId: MATTER_CLUSTER_IDS.ColorControl,
|
|
273
|
+
attributes: {
|
|
274
|
+
colorMode: { read: async () => 0 },
|
|
275
|
+
colorHue: { read: async () => (await this.getState()).hue ?? 0, write: async (v) => this.setState({ hue: Number(v) }) },
|
|
276
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => (await this.getState()).hue ?? 0, write: async (v) => this.setState({ hue: Number(v) }) },
|
|
277
|
+
colorSaturation: { read: async () => (await this.getState()).saturation ?? 0, write: async (v) => this.setState({ saturation: Number(v) }) },
|
|
278
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => (await this.getState()).saturation ?? 0, write: async (v) => this.setState({ saturation: Number(v) }) },
|
|
279
|
+
...(typeof state.colorTemperature === 'number' || typeof state.kelvin === 'number'
|
|
280
|
+
? {
|
|
281
|
+
colorTemperature: { read: async () => typeof (await this.getState()).colorTemperature === 'number' ? (await this.getState()).colorTemperature : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)), write: async (v) => this.setState({ colorTemperature: Number(v) }) },
|
|
282
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => typeof (await this.getState()).colorTemperature === 'number' ? (await this.getState()).colorTemperature : Math.round(1000000 / ((await this.getState()).kelvin ?? 2500)), write: async (v) => this.setState({ colorTemperature: Number(v) }) },
|
|
283
|
+
}
|
|
284
|
+
: {}),
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
// Temperature sensor
|
|
289
|
+
if ('temperature' in state) {
|
|
290
|
+
clusters.push({
|
|
291
|
+
type: 'TemperatureMeasurement',
|
|
292
|
+
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
293
|
+
attributes: {
|
|
294
|
+
measuredValue: { read: async () => (await this.getState()).temperature ?? 0 },
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// Humidity sensor
|
|
299
|
+
if ('humidity' in state) {
|
|
300
|
+
clusters.push({
|
|
301
|
+
type: 'RelativeHumidityMeasurement',
|
|
302
|
+
clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
|
|
303
|
+
attributes: {
|
|
304
|
+
measuredValue: { read: async () => (await this.getState()).humidity ?? 0 },
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
// CO2 sensor
|
|
309
|
+
if ('CO2' in state) {
|
|
310
|
+
clusters.push({
|
|
311
|
+
type: 'AirQuality',
|
|
312
|
+
attributes: {
|
|
313
|
+
CO2: { read: async () => (await this.getState()).CO2 ?? 0 },
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
// Lock
|
|
318
|
+
if ('lockState' in state || 'locked' in state) {
|
|
319
|
+
clusters.push({
|
|
320
|
+
type: 'DoorLock',
|
|
321
|
+
clusterId: MATTER_CLUSTER_IDS.DoorLock,
|
|
322
|
+
attributes: {
|
|
323
|
+
lockState: { read: async () => (await this.getState()).lockState ?? (await this.getState()).locked ? 1 : 0, write: async (v) => this.setState({ locked: !!v }) },
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
// Motion sensor
|
|
328
|
+
if ('moveDetected' in state || 'motion' in state) {
|
|
329
|
+
clusters.push({
|
|
330
|
+
type: 'OccupancySensing',
|
|
331
|
+
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
332
|
+
attributes: {
|
|
333
|
+
occupancy: { read: async () => (await this.getState()).moveDetected === true || (await this.getState()).motion === true ? 1 : 0 },
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
// Contact sensor
|
|
338
|
+
if ('openState' in state || 'contact' in state || 'open' in state) {
|
|
339
|
+
clusters.push({
|
|
340
|
+
type: 'BooleanState',
|
|
341
|
+
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
342
|
+
attributes: {
|
|
343
|
+
stateValue: { read: async () => (await this.getState()).openState === 'open' || (await this.getState()).open === true ? 1 : 0 },
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
// Leak sensor
|
|
348
|
+
if ('leak' in state || 'status' in state) {
|
|
349
|
+
clusters.push({
|
|
350
|
+
type: 'LeakSensor',
|
|
351
|
+
attributes: {
|
|
352
|
+
leakDetected: { read: async () => (await this.getState()).leak === true || (await this.getState()).status === 1 ? 1 : 0 },
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
// Energy monitoring (Plug)
|
|
357
|
+
if ('voltage' in state || 'power' in state || 'electricCurrent' in state) {
|
|
358
|
+
clusters.push({
|
|
359
|
+
type: 'ElectricalMeasurement',
|
|
360
|
+
// No clusterId, not present in MATTER_CLUSTER_IDS
|
|
361
|
+
attributes: {
|
|
362
|
+
voltage: { read: async () => (await this.getState()).voltage ?? 0 },
|
|
363
|
+
power: { read: async () => (await this.getState()).power ?? 0 },
|
|
364
|
+
electricCurrent: { read: async () => (await this.getState()).electricCurrent ?? 0 },
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
// Fan
|
|
369
|
+
if ('speed' in state || 'fanSpeed' in state) {
|
|
370
|
+
clusters.push({
|
|
371
|
+
type: 'FanControl',
|
|
372
|
+
clusterId: MATTER_CLUSTER_IDS.FanControl,
|
|
373
|
+
attributes: {
|
|
374
|
+
speedCurrent: { read: async () => (await this.getState()).speed ?? (await this.getState()).fanSpeed ?? 0, write: async (v) => this.setState({ speed: Number(v) }) },
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
// Vacuum
|
|
379
|
+
if ('workingStatus' in state) {
|
|
380
|
+
clusters.push({
|
|
381
|
+
type: 'RobotVacuumCleaner',
|
|
382
|
+
attributes: {
|
|
383
|
+
workingStatus: { read: async () => (await this.getState()).workingStatus ?? 'StandBy' },
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
id: this.opts.id,
|
|
389
|
+
name: this.opts.name ?? this.opts.type,
|
|
390
|
+
protocol: 'matter',
|
|
391
|
+
clusters,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
// Specific device classes can extend GenericDevice for custom behavior.
|
|
396
|
+
export class BotDevice extends GenericDevice {
|
|
397
|
+
}
|
|
398
|
+
export class CurtainDevice extends GenericDevice {
|
|
399
|
+
createHAPAccessory(api) {
|
|
400
|
+
return {
|
|
401
|
+
services: [
|
|
402
|
+
{
|
|
403
|
+
type: 'WindowCovering',
|
|
404
|
+
characteristics: {
|
|
405
|
+
CurrentPosition: {
|
|
406
|
+
get: async () => {
|
|
407
|
+
const s = await this.getState();
|
|
408
|
+
return typeof s.position === 'number' ? s.position : 0;
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
TargetPosition: {
|
|
412
|
+
get: async () => {
|
|
413
|
+
const s = await this.getState();
|
|
414
|
+
return typeof s.position === 'number' ? s.position : 0;
|
|
415
|
+
},
|
|
416
|
+
set: async (v) => {
|
|
417
|
+
await this.setState({ position: Number(v) });
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
// Matter-specific descriptor for Curtain (Shade cluster) with conformance type
|
|
426
|
+
async createMatterAccessory(api) {
|
|
427
|
+
// Determine device type and features
|
|
428
|
+
const typeKey = (this.opts.type || '').toLowerCase();
|
|
429
|
+
// Dynamic detection: check config/state for lift/tilt support
|
|
430
|
+
const hasConfigLift = !!this.opts.lift || typeof this.opts.lift === 'number';
|
|
431
|
+
const hasConfigTilt = !!this.opts.tilt || typeof this.opts.tilt === 'number';
|
|
432
|
+
let hasLiftAttrs = false;
|
|
433
|
+
let hasTiltAttrs = false;
|
|
434
|
+
if (typeof this.getState === 'function') {
|
|
435
|
+
let state;
|
|
436
|
+
try {
|
|
437
|
+
state = await this.getState();
|
|
438
|
+
}
|
|
439
|
+
catch (e) {
|
|
440
|
+
state = undefined;
|
|
441
|
+
}
|
|
442
|
+
if (state) {
|
|
443
|
+
hasLiftAttrs = typeof state.position === 'number';
|
|
444
|
+
hasTiltAttrs = typeof state.tilt === 'number';
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
// For SwitchBot Curtain, always set supportsLift = true
|
|
448
|
+
let supportsLift = hasConfigLift || hasLiftAttrs;
|
|
449
|
+
if (typeKey.includes('curtain')) {
|
|
450
|
+
supportsLift = true;
|
|
451
|
+
}
|
|
452
|
+
else if (!supportsLift && (typeKey.includes('rollershade') || typeKey.includes('blindtilt'))) {
|
|
453
|
+
supportsLift = true;
|
|
454
|
+
}
|
|
455
|
+
const supportsTilt = hasConfigTilt || hasTiltAttrs || typeKey.includes('blindtilt') || typeKey.includes('blind tilt');
|
|
456
|
+
// Debug: Log feature detection variables
|
|
457
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} feature detection: typeKey='${typeKey}', hasConfigLift=${hasConfigLift}, hasLiftAttrs=${hasLiftAttrs}, hasConfigTilt=${hasConfigTilt}, hasTiltAttrs=${hasTiltAttrs}, supportsLift=${supportsLift}, supportsTilt=${supportsTilt}`);
|
|
458
|
+
// If neither lift nor tilt is supported, do not register as Matter window covering
|
|
459
|
+
if (!supportsLift && !supportsTilt) {
|
|
460
|
+
this.log.warn(`[Matter] Skipping Matter registration for window covering device '${this.opts.name ?? this.opts.id}' (id: ${this.opts.id}): no lift or tilt support detected.`);
|
|
461
|
+
return undefined;
|
|
462
|
+
}
|
|
463
|
+
// Allow user to override Matter type via config (opts.matterType)
|
|
464
|
+
if (typeof this.opts.matterType === 'number') {
|
|
465
|
+
const matterType = this.opts.matterType;
|
|
466
|
+
this.log.info(`[Matter/Config] Using user-specified Matter type for ${this.opts.name ?? this.opts.id}: matterType=${matterType}`);
|
|
467
|
+
// Build attributes for Matter WindowCovering
|
|
468
|
+
const attributes = {
|
|
469
|
+
type: {
|
|
470
|
+
read: async () => {
|
|
471
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} returning config-overridden type attribute value:`, matterType);
|
|
472
|
+
return matterType;
|
|
473
|
+
},
|
|
474
|
+
write: undefined,
|
|
475
|
+
},
|
|
476
|
+
currentPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: undefined },
|
|
477
|
+
targetPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: async (v) => this.setState({ position: Number(v) }) },
|
|
478
|
+
};
|
|
479
|
+
if (supportsTilt) {
|
|
480
|
+
attributes.currentTilt = { read: async () => { const s = await this.getState(); return typeof s.tilt === 'number' ? s.tilt : 0; }, write: undefined };
|
|
481
|
+
attributes.targetTilt = { read: async () => { const s = await this.getState(); return typeof s.tilt === 'number' ? s.tilt : 0; }, write: async (v) => this.setState({ tilt: Number(v) }) };
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} attributes:`, JSON.stringify(attributes, null, 2));
|
|
485
|
+
}
|
|
486
|
+
catch (e) {
|
|
487
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} attributes: [unserializable]`);
|
|
488
|
+
}
|
|
489
|
+
return {
|
|
490
|
+
id: this.opts.id,
|
|
491
|
+
name: this.opts.name ?? this.opts.type,
|
|
492
|
+
protocol: 'matter',
|
|
493
|
+
clusters: [
|
|
494
|
+
{
|
|
495
|
+
type: 'WindowCovering',
|
|
496
|
+
clusterId: MATTER_CLUSTER_IDS.WindowCovering,
|
|
497
|
+
attributes,
|
|
498
|
+
},
|
|
499
|
+
],
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
const combos = [];
|
|
503
|
+
if (supportsLift && supportsTilt) {
|
|
504
|
+
// Both supported: allow RollerShade (0), optionally Drapery (4) if typeKey includes 'drapery'
|
|
505
|
+
combos.push({ matterType: 0, supportsLift: true, supportsTilt: true });
|
|
506
|
+
if (typeKey.includes('drapery')) {
|
|
507
|
+
combos.push({ matterType: 4, supportsLift: true, supportsTilt: true });
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
else if (supportsLift && !supportsTilt) {
|
|
511
|
+
// Only lift: allow RollerShade (0)
|
|
512
|
+
combos.push({ matterType: 0, supportsLift: true, supportsTilt: false });
|
|
513
|
+
}
|
|
514
|
+
else if (!supportsLift && supportsTilt) {
|
|
515
|
+
// Only tilt: allow BlindTilt (8)
|
|
516
|
+
combos.push({ matterType: 8, supportsLift: false, supportsTilt: true });
|
|
517
|
+
}
|
|
518
|
+
let lastError;
|
|
519
|
+
for (const combo of combos) {
|
|
520
|
+
try {
|
|
521
|
+
this.log.info(`[Matter/Retry] Trying combo for ${this.opts.name ?? this.opts.id}: matterType=${combo.matterType}, supportsLift=${combo.supportsLift}, supportsTilt=${combo.supportsTilt}`);
|
|
522
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} trying combo: matterType=${combo.matterType}, supportsLift=${combo.supportsLift}, supportsTilt=${combo.supportsTilt}`);
|
|
523
|
+
// Build attributes for Matter WindowCovering (string keys only)
|
|
524
|
+
const attributes = {
|
|
525
|
+
type: {
|
|
526
|
+
read: async () => {
|
|
527
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} returning type attribute value:`, combo.matterType);
|
|
528
|
+
return combo.matterType;
|
|
529
|
+
},
|
|
530
|
+
write: undefined,
|
|
531
|
+
},
|
|
532
|
+
currentPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: undefined },
|
|
533
|
+
targetPosition: { read: async () => { const s = await this.getState(); return typeof s.position === 'number' ? s.position : 0; }, write: async (v) => this.setState({ position: Number(v) }) },
|
|
534
|
+
};
|
|
535
|
+
if (combo.supportsTilt) {
|
|
536
|
+
attributes.currentTilt = { read: async () => { const s = await this.getState(); return typeof s.tilt === 'number' ? s.tilt : 0; }, write: undefined };
|
|
537
|
+
attributes.targetTilt = { read: async () => { const s = await this.getState(); return typeof s.tilt === 'number' ? s.tilt : 0; }, write: async (v) => this.setState({ tilt: Number(v) }) };
|
|
538
|
+
}
|
|
539
|
+
// Log the final attributes object
|
|
540
|
+
try {
|
|
541
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} attributes:`, JSON.stringify(attributes, null, 2));
|
|
542
|
+
}
|
|
543
|
+
catch (e) {
|
|
544
|
+
this.log.debug(`[Matter/Debug] ${this.opts.name ?? this.opts.id} attributes: [unserializable]`);
|
|
545
|
+
}
|
|
546
|
+
// Try to register with this combo
|
|
547
|
+
return {
|
|
548
|
+
id: this.opts.id,
|
|
549
|
+
name: this.opts.name ?? this.opts.type,
|
|
550
|
+
protocol: 'matter',
|
|
551
|
+
clusters: [
|
|
552
|
+
{
|
|
553
|
+
type: 'WindowCovering',
|
|
554
|
+
clusterId: MATTER_CLUSTER_IDS.WindowCovering,
|
|
555
|
+
attributes,
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
lastError = err;
|
|
562
|
+
this.log.warn(`[Matter/Retry] Failed combo matterType=${combo.matterType}, supportsLift=${combo.supportsLift}, supportsTilt=${combo.supportsTilt}: ${err}`);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
// If all combos fail, throw last error
|
|
566
|
+
throw lastError || new Error('All Matter window covering type combos failed');
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
export class FanDevice extends GenericDevice {
|
|
570
|
+
createHAPAccessory(api) {
|
|
571
|
+
return {
|
|
572
|
+
services: [
|
|
573
|
+
{
|
|
574
|
+
type: 'Fan',
|
|
575
|
+
characteristics: {
|
|
576
|
+
On: {
|
|
577
|
+
get: async () => {
|
|
578
|
+
const s = await this.getState();
|
|
579
|
+
return !!(s && (s.on === true || s.state === 'on'));
|
|
580
|
+
},
|
|
581
|
+
set: async (v) => {
|
|
582
|
+
await this.setState({ on: !!v });
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
RotationSpeed: {
|
|
586
|
+
get: async () => {
|
|
587
|
+
const s = await this.getState();
|
|
588
|
+
return typeof s.speed === 'number' ? s.speed : 0;
|
|
589
|
+
},
|
|
590
|
+
set: async (v) => {
|
|
591
|
+
await this.setState({ speed: Number(v) });
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
],
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
async setState(change) {
|
|
600
|
+
if (!this.client) {
|
|
601
|
+
return { success: false, reason: 'no client' };
|
|
602
|
+
}
|
|
603
|
+
// Oscillation support
|
|
604
|
+
if (typeof change.oscillate === 'boolean') {
|
|
605
|
+
const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
|
|
606
|
+
try {
|
|
607
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
608
|
+
}
|
|
609
|
+
catch (err) {
|
|
610
|
+
try {
|
|
611
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
612
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (e) { }
|
|
616
|
+
const e = err;
|
|
617
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
// Swing / sweep support (angle or mode)
|
|
621
|
+
if (change && (typeof change.swing === 'boolean' || typeof change.swingAngle === 'number' || typeof change.swingMode === 'string')) {
|
|
622
|
+
let param = 'default';
|
|
623
|
+
if (typeof change.swingMode === 'string') {
|
|
624
|
+
param = change.swingMode;
|
|
625
|
+
}
|
|
626
|
+
else if (typeof change.swingAngle === 'number') {
|
|
627
|
+
param = String(Number(change.swingAngle));
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
param = change.swing ? 'on' : 'off';
|
|
631
|
+
}
|
|
632
|
+
const body = { command: 'setSwing', parameter: param, commandType: 'command' };
|
|
633
|
+
try {
|
|
634
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
635
|
+
}
|
|
636
|
+
catch (err) {
|
|
637
|
+
try {
|
|
638
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
639
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
catch (e) { }
|
|
643
|
+
const e = err;
|
|
644
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return super.setState(change);
|
|
648
|
+
}
|
|
649
|
+
// Matter-specific descriptor for Fan
|
|
650
|
+
createMatterAccessory(api) {
|
|
651
|
+
return {
|
|
652
|
+
id: this.opts.id,
|
|
653
|
+
name: this.opts.name ?? this.opts.type,
|
|
654
|
+
protocol: 'matter',
|
|
655
|
+
clusters: [
|
|
656
|
+
{
|
|
657
|
+
// OnOff cluster
|
|
658
|
+
type: 'OnOff',
|
|
659
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
660
|
+
attributes: {
|
|
661
|
+
onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
|
|
662
|
+
// numeric attribute id for onOff
|
|
663
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
// Fan Control cluster
|
|
668
|
+
type: 'FanControl',
|
|
669
|
+
clusterId: MATTER_CLUSTER_IDS.FanControl,
|
|
670
|
+
attributes: {
|
|
671
|
+
rotationSpeed: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
|
|
672
|
+
[MATTER_ATTRIBUTE_IDS.FanControl.SpeedCurrent]: { read: async () => { const s = await this.getState(); return typeof s.speed === 'number' ? s.speed : 0; }, write: async (v) => this.setState({ speed: Number(v) }) },
|
|
673
|
+
oscillation: { read: async () => { const s = await this.getState(); return !!s?.oscillating; }, write: async (v) => this.setState({ oscillate: !!v }) },
|
|
674
|
+
swingMode: { read: async () => { const s = await this.getState(); return s?.swingMode ?? null; }, write: async (v) => this.setState({ swingMode: v }) },
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
],
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
export class LightDevice extends GenericDevice {
|
|
682
|
+
createHAPAccessory(api) {
|
|
683
|
+
return {
|
|
684
|
+
services: [
|
|
685
|
+
{
|
|
686
|
+
type: 'Lightbulb',
|
|
687
|
+
characteristics: {
|
|
688
|
+
On: {
|
|
689
|
+
get: async () => {
|
|
690
|
+
const s = await this.getState();
|
|
691
|
+
return !!(s && (s.on === true || s.state === 'on' || s.power === 'on'));
|
|
692
|
+
},
|
|
693
|
+
set: async (v) => {
|
|
694
|
+
await this.setState({ on: !!v });
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
Brightness: {
|
|
698
|
+
props: { minValue: 0, maxValue: 100, minStep: 1 },
|
|
699
|
+
get: async () => {
|
|
700
|
+
const s = await this.getState();
|
|
701
|
+
return typeof s.brightness === 'number' ? s.brightness : 100;
|
|
702
|
+
},
|
|
703
|
+
set: async (v) => {
|
|
704
|
+
await this.setState({ brightness: Number(v) });
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
Hue: {
|
|
708
|
+
props: { minValue: 0, maxValue: 360, minStep: 1 },
|
|
709
|
+
get: async () => {
|
|
710
|
+
const s = await this.getState();
|
|
711
|
+
// prefer explicit hue if provided
|
|
712
|
+
if (s && typeof s.hue === 'number') {
|
|
713
|
+
return s.hue;
|
|
714
|
+
}
|
|
715
|
+
// try HSV from color hex
|
|
716
|
+
const hex = s?.color || s?.colorHex || s?.colour;
|
|
717
|
+
if (typeof hex === 'string' && HEX_COLOR_REGEX.test(hex)) {
|
|
718
|
+
const h = (() => {
|
|
719
|
+
const hsl = (h, s, l) => ({ h, s, l });
|
|
720
|
+
// convert hex -> rgb -> hsv
|
|
721
|
+
const cleaned = hex.replace('#', '');
|
|
722
|
+
const r = Number.parseInt(cleaned.substr(0, 2), 16) / 255;
|
|
723
|
+
const g = Number.parseInt(cleaned.substr(2, 2), 16) / 255;
|
|
724
|
+
const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255;
|
|
725
|
+
const mx = Math.max(r, g, b);
|
|
726
|
+
const mn = Math.min(r, g, b);
|
|
727
|
+
const d = mx - mn;
|
|
728
|
+
if (d === 0) {
|
|
729
|
+
return 0;
|
|
730
|
+
}
|
|
731
|
+
let hue = 0;
|
|
732
|
+
switch (mx) {
|
|
733
|
+
case r:
|
|
734
|
+
hue = ((g - b) / d) % 6;
|
|
735
|
+
break;
|
|
736
|
+
case g:
|
|
737
|
+
hue = (b - r) / d + 2;
|
|
738
|
+
break;
|
|
739
|
+
case b:
|
|
740
|
+
hue = (r - g) / d + 4;
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
hue = Math.round(hue * 60);
|
|
744
|
+
if (hue < 0) {
|
|
745
|
+
hue += 360;
|
|
746
|
+
}
|
|
747
|
+
return hue;
|
|
748
|
+
})();
|
|
749
|
+
return h;
|
|
750
|
+
}
|
|
751
|
+
return 0;
|
|
752
|
+
},
|
|
753
|
+
set: async (v) => {
|
|
754
|
+
await this.setState({ hue: Number(v) });
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
Saturation: {
|
|
758
|
+
props: { minValue: 0, maxValue: 100, minStep: 1 },
|
|
759
|
+
get: async () => {
|
|
760
|
+
const s = await this.getState();
|
|
761
|
+
if (s && typeof s.saturation === 'number') {
|
|
762
|
+
return s.saturation;
|
|
763
|
+
}
|
|
764
|
+
// if color hex is available, derive saturation from rgb
|
|
765
|
+
const hex = s?.color || s?.colorHex || s?.colour;
|
|
766
|
+
if (typeof hex === 'string' && HEX_COLOR_REGEX.test(hex)) {
|
|
767
|
+
const cleaned = hex.replace('#', '');
|
|
768
|
+
const r = Number.parseInt(cleaned.substr(0, 2), 16) / 255;
|
|
769
|
+
const g = Number.parseInt(cleaned.substr(2, 2), 16) / 255;
|
|
770
|
+
const b = Number.parseInt(cleaned.substr(4, 2), 16) / 255;
|
|
771
|
+
const mx = Math.max(r, g, b);
|
|
772
|
+
const mn = Math.min(r, g, b);
|
|
773
|
+
const d = mx - mn;
|
|
774
|
+
const sat = mx === 0 ? 0 : Math.round((d / mx) * 100);
|
|
775
|
+
return sat;
|
|
776
|
+
}
|
|
777
|
+
return 0;
|
|
778
|
+
},
|
|
779
|
+
set: async (v) => {
|
|
780
|
+
await this.setState({ saturation: Number(v) });
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
ColorTemperature: {
|
|
784
|
+
props: { minValue: 153, maxValue: 500, minStep: 1 },
|
|
785
|
+
get: async () => {
|
|
786
|
+
const s = await this.getState();
|
|
787
|
+
// prefer mired if provided
|
|
788
|
+
if (s && typeof s.colorTemperature === 'number') {
|
|
789
|
+
return s.colorTemperature;
|
|
790
|
+
}
|
|
791
|
+
if (s && typeof s.color_temp === 'number') {
|
|
792
|
+
return s.color_temp;
|
|
793
|
+
}
|
|
794
|
+
// some devices provide kelvin
|
|
795
|
+
if (s && typeof s.kelvin === 'number' && s.kelvin > 0) {
|
|
796
|
+
return Math.round(1000000 / s.kelvin);
|
|
797
|
+
}
|
|
798
|
+
return 400;
|
|
799
|
+
},
|
|
800
|
+
set: async (v) => {
|
|
801
|
+
await this.setState({ colorTemperature: Number(v) });
|
|
802
|
+
},
|
|
803
|
+
},
|
|
804
|
+
},
|
|
805
|
+
},
|
|
806
|
+
],
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
async setState(change) {
|
|
810
|
+
if (!this.client) {
|
|
811
|
+
return { success: false, reason: 'no client' };
|
|
812
|
+
}
|
|
813
|
+
// Color temperature (mired) or brightness/hue/sat
|
|
814
|
+
if (typeof change.colorTemperature === 'number' || typeof change.color_temp === 'number') {
|
|
815
|
+
const v = String(Number(change.colorTemperature ?? change.color_temp));
|
|
816
|
+
const body = { command: 'setColorTemperature', parameter: v, commandType: 'command' };
|
|
817
|
+
try {
|
|
818
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
819
|
+
}
|
|
820
|
+
catch (err) {
|
|
821
|
+
try {
|
|
822
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
823
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
catch (e) { }
|
|
827
|
+
const e = err;
|
|
828
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (typeof change.hue === 'number' && typeof change.saturation === 'number') {
|
|
832
|
+
const body = { command: 'setColor', parameter: `${Number(change.hue)},${Number(change.saturation)}`, commandType: 'command' };
|
|
833
|
+
try {
|
|
834
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
835
|
+
}
|
|
836
|
+
catch (err) {
|
|
837
|
+
try {
|
|
838
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
839
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
catch (e) { }
|
|
843
|
+
const e = err;
|
|
844
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (change && typeof change.color === 'string') {
|
|
848
|
+
const body = { command: 'setColor', parameter: change.color, commandType: 'command' };
|
|
849
|
+
try {
|
|
850
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
851
|
+
}
|
|
852
|
+
catch (err) {
|
|
853
|
+
try {
|
|
854
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
855
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
catch (e) { }
|
|
859
|
+
const e = err;
|
|
860
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
// Fallback to generic handler (brightness/on)
|
|
864
|
+
return super.setState(change);
|
|
865
|
+
}
|
|
866
|
+
// Matter-specific descriptor for lights (OnOff + Level + Color)
|
|
867
|
+
createMatterAccessory(api) {
|
|
868
|
+
return {
|
|
869
|
+
id: this.opts.id,
|
|
870
|
+
name: this.opts.name ?? this.opts.type,
|
|
871
|
+
protocol: 'matter',
|
|
872
|
+
clusters: [
|
|
873
|
+
{
|
|
874
|
+
// OnOff cluster
|
|
875
|
+
type: 'OnOff',
|
|
876
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
877
|
+
attributes: {
|
|
878
|
+
onOff: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
|
|
879
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!(s && (s.on === true || s.state === 'on' || s.power === 'on')); }, write: async (v) => this.setState({ on: !!v }) },
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
// Level Control cluster
|
|
884
|
+
type: 'LevelControl',
|
|
885
|
+
clusterId: MATTER_CLUSTER_IDS.LevelControl,
|
|
886
|
+
attributes: {
|
|
887
|
+
currentLevel: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
|
|
888
|
+
[MATTER_ATTRIBUTE_IDS.LevelControl.CurrentLevel]: { read: async () => { const s = await this.getState(); return typeof s.brightness === 'number' ? s.brightness : 100; }, write: async (v) => this.setState({ brightness: Number(v) }) },
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
// Color Control cluster
|
|
893
|
+
type: 'ColorControl',
|
|
894
|
+
clusterId: MATTER_CLUSTER_IDS.ColorControl,
|
|
895
|
+
attributes: {
|
|
896
|
+
// Required colorMode attribute for Matter conformance (0 = currentHueAndSaturation)
|
|
897
|
+
colorMode: { read: async () => 0 },
|
|
898
|
+
colorHue: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
|
|
899
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentHue]: { read: async () => { const s = await this.getState(); return typeof s.hue === 'number' ? s.hue : 0; }, write: async (v) => this.setState({ hue: Number(v) }) },
|
|
900
|
+
colorSaturation: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
|
|
901
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.CurrentSaturation]: { read: async () => { const s = await this.getState(); return typeof s.saturation === 'number' ? s.saturation : 0; }, write: async (v) => this.setState({ saturation: Number(v) }) },
|
|
902
|
+
colorTemperature: { read: async () => {
|
|
903
|
+
const s = await this.getState();
|
|
904
|
+
if (typeof s.colorTemperature === 'number') {
|
|
905
|
+
return s.colorTemperature;
|
|
906
|
+
}
|
|
907
|
+
if (typeof s.kelvin === 'number') {
|
|
908
|
+
return Math.round(1000000 / s.kelvin);
|
|
909
|
+
}
|
|
910
|
+
return 400;
|
|
911
|
+
}, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
|
|
912
|
+
[MATTER_ATTRIBUTE_IDS.ColorControl.ColorTemperatureMireds]: { read: async () => {
|
|
913
|
+
const s = await this.getState();
|
|
914
|
+
if (typeof s.colorTemperature === 'number') {
|
|
915
|
+
return s.colorTemperature;
|
|
916
|
+
}
|
|
917
|
+
if (typeof s.kelvin === 'number') {
|
|
918
|
+
return Math.round(1000000 / s.kelvin);
|
|
919
|
+
}
|
|
920
|
+
return 400;
|
|
921
|
+
}, write: async (v) => this.setState({ colorTemperature: Number(v) }) },
|
|
922
|
+
},
|
|
923
|
+
},
|
|
924
|
+
],
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
export class LightStripDevice extends LightDevice {
|
|
929
|
+
}
|
|
930
|
+
export class MotionSensorDevice extends GenericDevice {
|
|
931
|
+
createHAPAccessory(api) {
|
|
932
|
+
return {
|
|
933
|
+
services: [
|
|
934
|
+
{
|
|
935
|
+
type: 'MotionSensor',
|
|
936
|
+
characteristics: {
|
|
937
|
+
MotionDetected: {
|
|
938
|
+
get: async () => {
|
|
939
|
+
const s = await this.getState();
|
|
940
|
+
return !!(s && s.motion === true);
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
},
|
|
945
|
+
],
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
async setState(change) {
|
|
949
|
+
if (!this.client) {
|
|
950
|
+
return { success: false, reason: 'no client' };
|
|
951
|
+
}
|
|
952
|
+
// Oscillation support
|
|
953
|
+
if (typeof change.oscillate === 'boolean') {
|
|
954
|
+
const body = { command: 'setOscillation', parameter: change.oscillate ? 'on' : 'off', commandType: 'command' };
|
|
955
|
+
try {
|
|
956
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
957
|
+
}
|
|
958
|
+
catch (err) {
|
|
959
|
+
try {
|
|
960
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
961
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
catch (e) { }
|
|
965
|
+
const e = err;
|
|
966
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
// Swing / sweep support (angle or mode)
|
|
970
|
+
if (change && (typeof change.swing === 'boolean' || typeof change.swingAngle === 'number' || typeof change.swingMode === 'string')) {
|
|
971
|
+
let param = 'default';
|
|
972
|
+
if (typeof change.swingMode === 'string') {
|
|
973
|
+
param = change.swingMode;
|
|
974
|
+
}
|
|
975
|
+
else if (typeof change.swingAngle === 'number') {
|
|
976
|
+
param = String(Number(change.swingAngle));
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
param = change.swing ? 'on' : 'off';
|
|
980
|
+
}
|
|
981
|
+
const body = { command: 'setSwing', parameter: param, commandType: 'command' };
|
|
982
|
+
try {
|
|
983
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
984
|
+
}
|
|
985
|
+
catch (err) {
|
|
986
|
+
try {
|
|
987
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
988
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
catch (e) { }
|
|
992
|
+
const e = err;
|
|
993
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return super.setState(change);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
export class ContactSensorDevice extends GenericDevice {
|
|
1000
|
+
createHAPAccessory(api) {
|
|
1001
|
+
return {
|
|
1002
|
+
services: [
|
|
1003
|
+
{
|
|
1004
|
+
type: 'ContactSensor',
|
|
1005
|
+
characteristics: {
|
|
1006
|
+
ContactSensorState: {
|
|
1007
|
+
get: async () => {
|
|
1008
|
+
const s = await this.getState();
|
|
1009
|
+
return s && s.open ? 1 : 0;
|
|
1010
|
+
},
|
|
1011
|
+
},
|
|
1012
|
+
},
|
|
1013
|
+
},
|
|
1014
|
+
],
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
export class VacuumDevice extends GenericDevice {
|
|
1019
|
+
// Use DeviceBase defaults (Switch-style) — no override needed
|
|
1020
|
+
createHAPAccessory(api) {
|
|
1021
|
+
return super.createHAPAccessory(api);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
export class LockDevice extends GenericDevice {
|
|
1025
|
+
createHAPAccessory(api) {
|
|
1026
|
+
return {
|
|
1027
|
+
services: [
|
|
1028
|
+
{
|
|
1029
|
+
type: 'LockMechanism',
|
|
1030
|
+
characteristics: {
|
|
1031
|
+
LockCurrentState: {
|
|
1032
|
+
get: async () => {
|
|
1033
|
+
const s = await this.getState();
|
|
1034
|
+
return s && s.locked ? 1 : 0;
|
|
1035
|
+
},
|
|
1036
|
+
},
|
|
1037
|
+
LockTargetState: {
|
|
1038
|
+
get: async () => {
|
|
1039
|
+
const s = await this.getState();
|
|
1040
|
+
return s && s.locked ? 1 : 0;
|
|
1041
|
+
},
|
|
1042
|
+
set: async (v) => {
|
|
1043
|
+
await this.setState({ locked: !!v });
|
|
1044
|
+
},
|
|
1045
|
+
},
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
],
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
async setState(change) {
|
|
1052
|
+
if (!this.client) {
|
|
1053
|
+
return { success: false, reason: 'no client' };
|
|
1054
|
+
}
|
|
1055
|
+
// User management actions: add/remove/list users, unlock with pin
|
|
1056
|
+
if (change && typeof change.action === 'string') {
|
|
1057
|
+
const action = change.action;
|
|
1058
|
+
try {
|
|
1059
|
+
if (action === 'addUser' && (change.user || change.userId) && (change.pin || change.code)) {
|
|
1060
|
+
const user = change.user ?? change.userId;
|
|
1061
|
+
const p = String(change.pin ?? change.code);
|
|
1062
|
+
const body = { command: 'addUserCode', parameter: `${user}:${p}`, commandType: 'command' };
|
|
1063
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1064
|
+
}
|
|
1065
|
+
if (action === 'removeUser' && (change.user || change.userId)) {
|
|
1066
|
+
const user = change.user ?? change.userId;
|
|
1067
|
+
const body = { command: 'removeUserCode', parameter: String(user), commandType: 'command' };
|
|
1068
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1069
|
+
}
|
|
1070
|
+
if (action === 'listUsers') {
|
|
1071
|
+
const body = { command: 'listUsers', parameter: 'default', commandType: 'command' };
|
|
1072
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1073
|
+
}
|
|
1074
|
+
if (action === 'unlockWithPin' && (change.pin || change.code)) {
|
|
1075
|
+
const p = String(change.pin ?? change.code);
|
|
1076
|
+
const body = { command: 'unlockWithPin', parameter: p, commandType: 'command' };
|
|
1077
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
catch (err) {
|
|
1081
|
+
try {
|
|
1082
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
1083
|
+
return await this.client.sendCommand(this.opts.id, { command: action, parameter: change.parameter ?? 'default', commandType: 'command' });
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
catch (e) { }
|
|
1087
|
+
const e = err;
|
|
1088
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
// Support setting lock PIN/passcode via `pin` or `passcode` (fallback)
|
|
1092
|
+
const pin = change?.pin ?? change?.passcode ?? change?.code;
|
|
1093
|
+
if (typeof pin === 'string' || typeof pin === 'number') {
|
|
1094
|
+
const body = { command: 'setLockPin', parameter: String(pin), commandType: 'command' };
|
|
1095
|
+
try {
|
|
1096
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1097
|
+
}
|
|
1098
|
+
catch (err) {
|
|
1099
|
+
try {
|
|
1100
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
1101
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
catch (e) { }
|
|
1105
|
+
const e = err;
|
|
1106
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return super.setState(change);
|
|
1110
|
+
}
|
|
1111
|
+
// Matter DoorLock descriptor including simple user-management actions
|
|
1112
|
+
createMatterAccessory(api) {
|
|
1113
|
+
return {
|
|
1114
|
+
id: this.opts.id,
|
|
1115
|
+
name: this.opts.name ?? this.opts.type,
|
|
1116
|
+
protocol: 'matter',
|
|
1117
|
+
clusters: [
|
|
1118
|
+
{
|
|
1119
|
+
// DoorLock cluster
|
|
1120
|
+
type: 'DoorLock',
|
|
1121
|
+
clusterId: MATTER_CLUSTER_IDS.DoorLock,
|
|
1122
|
+
attributes: {
|
|
1123
|
+
lockState: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
|
|
1124
|
+
[MATTER_ATTRIBUTE_IDS.DoorLock.LockState]: { read: async () => { const s = await this.getState(); return !!(s && s.locked); }, write: async (v) => this.setState({ locked: !!v }) },
|
|
1125
|
+
},
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
// DoorLock user mgmt cluster (conceptual)
|
|
1129
|
+
type: 'DoorLockUserManagement',
|
|
1130
|
+
clusterId: 0x0301,
|
|
1131
|
+
attributes: {
|
|
1132
|
+
addUser: { write: async (v) => this.setState({ action: 'addUser', user: v?.user, pin: v?.pin }) },
|
|
1133
|
+
removeUser: { write: async (v) => this.setState({ action: 'removeUser', user: v?.user }) },
|
|
1134
|
+
listUsers: { read: async () => { const r = await this.setState({ action: 'listUsers' }); return r; }, write: undefined },
|
|
1135
|
+
unlockWithPin: { write: async (v) => this.setState({ action: 'unlockWithPin', pin: v?.pin }) },
|
|
1136
|
+
},
|
|
1137
|
+
},
|
|
1138
|
+
],
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
export class HumidifierDevice extends GenericDevice {
|
|
1143
|
+
createHAPAccessory(api) {
|
|
1144
|
+
return {
|
|
1145
|
+
services: [
|
|
1146
|
+
{
|
|
1147
|
+
type: 'HumidifierDehumidifier',
|
|
1148
|
+
characteristics: {
|
|
1149
|
+
Active: {
|
|
1150
|
+
get: async () => {
|
|
1151
|
+
const s = await this.getState();
|
|
1152
|
+
return s && s.on ? 1 : 0;
|
|
1153
|
+
},
|
|
1154
|
+
set: async (v) => {
|
|
1155
|
+
await this.setState({ on: v === 1 });
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
CurrentHumidifierDehumidifierState: {
|
|
1159
|
+
get: async () => {
|
|
1160
|
+
const s = await this.getState();
|
|
1161
|
+
return s && s.on ? 2 : 0; // 0 = Inactive, 2 = Humidifying
|
|
1162
|
+
},
|
|
1163
|
+
},
|
|
1164
|
+
TargetHumidifierDehumidifierState: {
|
|
1165
|
+
get: async () => 1, // 1 = Humidifier
|
|
1166
|
+
set: async (v) => {
|
|
1167
|
+
// Support humidifier mode
|
|
1168
|
+
},
|
|
1169
|
+
},
|
|
1170
|
+
CurrentRelativeHumidity: {
|
|
1171
|
+
get: async () => {
|
|
1172
|
+
const s = await this.getState();
|
|
1173
|
+
return typeof s.humidity === 'number' ? s.humidity : 0;
|
|
1174
|
+
},
|
|
1175
|
+
},
|
|
1176
|
+
RelativeHumidityHumidifierThreshold: {
|
|
1177
|
+
get: async () => {
|
|
1178
|
+
const s = await this.getState();
|
|
1179
|
+
return typeof s.targetHumidity === 'number' ? s.targetHumidity : 50;
|
|
1180
|
+
},
|
|
1181
|
+
set: async (v) => {
|
|
1182
|
+
await this.setState({ humidity: Number(v) });
|
|
1183
|
+
},
|
|
1184
|
+
},
|
|
1185
|
+
},
|
|
1186
|
+
},
|
|
1187
|
+
],
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
async setState(change) {
|
|
1191
|
+
if (!this.client) {
|
|
1192
|
+
return { success: false, reason: 'no client' };
|
|
1193
|
+
}
|
|
1194
|
+
if (typeof change.humidity === 'number') {
|
|
1195
|
+
const v = String(Number(change.humidity));
|
|
1196
|
+
const body = { command: 'setHumidity', parameter: v, commandType: 'command' };
|
|
1197
|
+
try {
|
|
1198
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1199
|
+
}
|
|
1200
|
+
catch (err) {
|
|
1201
|
+
try {
|
|
1202
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
1203
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
catch (e) { }
|
|
1207
|
+
const e = err;
|
|
1208
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
if (typeof change.dry === 'boolean') {
|
|
1212
|
+
const body = { command: 'setDry', parameter: change.dry ? 'on' : 'off', commandType: 'command' };
|
|
1213
|
+
try {
|
|
1214
|
+
return await this.client.setDeviceState(this.opts.id, body);
|
|
1215
|
+
}
|
|
1216
|
+
catch (err) {
|
|
1217
|
+
try {
|
|
1218
|
+
if (typeof this.client.sendCommand === 'function') {
|
|
1219
|
+
return await this.client.sendCommand(this.opts.id, body);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
catch (e) { }
|
|
1223
|
+
const e = err;
|
|
1224
|
+
return { success: false, reason: e?.message ?? String(e) };
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return super.setState(change);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
// Provide Matter descriptor for humidifier (humidity and on/off)
|
|
1231
|
+
export class HumidifierMatterDevice extends HumidifierDevice {
|
|
1232
|
+
async createMatterAccessory(api) {
|
|
1233
|
+
return {
|
|
1234
|
+
id: this.opts.id,
|
|
1235
|
+
name: this.opts.name ?? this.opts.type,
|
|
1236
|
+
protocol: 'matter',
|
|
1237
|
+
clusters: [
|
|
1238
|
+
{
|
|
1239
|
+
// Relative Humidity Sensor cluster
|
|
1240
|
+
type: 'RelativeHumiditySensor',
|
|
1241
|
+
clusterId: MATTER_CLUSTER_IDS.RelativeHumidityMeasurement,
|
|
1242
|
+
attributes: {
|
|
1243
|
+
currentRelativeHumidity: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
|
|
1244
|
+
[MATTER_ATTRIBUTE_IDS.RelativeHumidityMeasurement.MeasuredValue]: { read: async () => { const s = await this.getState(); return typeof s.humidity === 'number' ? s.humidity : 0; }, write: undefined },
|
|
1245
|
+
},
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
type: 'OnOff',
|
|
1249
|
+
clusterId: MATTER_CLUSTER_IDS.OnOff,
|
|
1250
|
+
attributes: {
|
|
1251
|
+
onOff: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
|
|
1252
|
+
[MATTER_ATTRIBUTE_IDS.OnOff.OnOff]: { read: async () => { const s = await this.getState(); return !!s?.on; }, write: async (v) => this.setState({ on: !!v }) },
|
|
1253
|
+
},
|
|
1254
|
+
},
|
|
1255
|
+
],
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
export class TemperatureSensorDevice extends GenericDevice {
|
|
1260
|
+
createHAPAccessory(api) {
|
|
1261
|
+
return {
|
|
1262
|
+
services: [
|
|
1263
|
+
{
|
|
1264
|
+
type: 'TemperatureSensor',
|
|
1265
|
+
characteristics: {
|
|
1266
|
+
CurrentTemperature: {
|
|
1267
|
+
get: async () => {
|
|
1268
|
+
const s = await this.getState();
|
|
1269
|
+
return typeof s.temperature === 'number' ? s.temperature : 0;
|
|
1270
|
+
},
|
|
1271
|
+
},
|
|
1272
|
+
},
|
|
1273
|
+
},
|
|
1274
|
+
],
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
// Additional device classes (aliases / specialized variants)
|
|
1279
|
+
export class RelaySwitchDevice extends GenericDevice {
|
|
1280
|
+
}
|
|
1281
|
+
export class RelaySwitch1PMDevice extends GenericDevice {
|
|
1282
|
+
}
|
|
1283
|
+
export class PlugDevice extends GenericDevice {
|
|
1284
|
+
createHAPAccessory(api) {
|
|
1285
|
+
return {
|
|
1286
|
+
services: [
|
|
1287
|
+
{
|
|
1288
|
+
type: 'Outlet',
|
|
1289
|
+
characteristics: {
|
|
1290
|
+
On: {
|
|
1291
|
+
get: async () => {
|
|
1292
|
+
const s = await this.getState();
|
|
1293
|
+
return !!(s && (s.on === true || s.state === 'on'));
|
|
1294
|
+
},
|
|
1295
|
+
set: async (v) => {
|
|
1296
|
+
await this.setState({ on: !!v });
|
|
1297
|
+
},
|
|
1298
|
+
},
|
|
1299
|
+
OutletInUse: {
|
|
1300
|
+
get: async () => {
|
|
1301
|
+
const s = await this.getState();
|
|
1302
|
+
return s && s.inUse ? 1 : 0;
|
|
1303
|
+
},
|
|
1304
|
+
},
|
|
1305
|
+
},
|
|
1306
|
+
},
|
|
1307
|
+
],
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
export class PlugMiniDevice extends PlugDevice {
|
|
1312
|
+
}
|
|
1313
|
+
export class BlindTiltDevice extends CurtainDevice {
|
|
1314
|
+
}
|
|
1315
|
+
export class Curtain3Device extends CurtainDevice {
|
|
1316
|
+
}
|
|
1317
|
+
export class RollerShadeDevice extends CurtainDevice {
|
|
1318
|
+
}
|
|
1319
|
+
export class Hub2Device extends GenericDevice {
|
|
1320
|
+
}
|
|
1321
|
+
export class MeterDevice extends GenericDevice {
|
|
1322
|
+
createHAPAccessory(api) {
|
|
1323
|
+
return {
|
|
1324
|
+
services: [
|
|
1325
|
+
{
|
|
1326
|
+
type: 'TemperatureSensor',
|
|
1327
|
+
characteristics: {
|
|
1328
|
+
CurrentTemperature: {
|
|
1329
|
+
get: async () => {
|
|
1330
|
+
const s = await this.getState();
|
|
1331
|
+
return typeof s.temperature === 'number' ? s.temperature : 0;
|
|
1332
|
+
},
|
|
1333
|
+
},
|
|
1334
|
+
},
|
|
1335
|
+
},
|
|
1336
|
+
{
|
|
1337
|
+
type: 'HumiditySensor',
|
|
1338
|
+
characteristics: {
|
|
1339
|
+
CurrentRelativeHumidity: {
|
|
1340
|
+
get: async () => {
|
|
1341
|
+
const s = await this.getState();
|
|
1342
|
+
return typeof s.humidity === 'number' ? s.humidity : 0;
|
|
1343
|
+
},
|
|
1344
|
+
},
|
|
1345
|
+
},
|
|
1346
|
+
},
|
|
1347
|
+
],
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
export class WaterDetectorDevice extends GenericDevice {
|
|
1352
|
+
createHAPAccessory(api) {
|
|
1353
|
+
return {
|
|
1354
|
+
services: [
|
|
1355
|
+
{
|
|
1356
|
+
type: 'LeakSensor',
|
|
1357
|
+
characteristics: {
|
|
1358
|
+
LeakDetected: {
|
|
1359
|
+
get: async () => {
|
|
1360
|
+
const s = await this.getState();
|
|
1361
|
+
return s && s.leak ? 1 : 0;
|
|
1362
|
+
},
|
|
1363
|
+
},
|
|
1364
|
+
},
|
|
1365
|
+
},
|
|
1366
|
+
],
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
export class SmartFanDevice extends FanDevice {
|
|
1371
|
+
}
|
|
1372
|
+
export class StripLightDevice extends LightStripDevice {
|
|
1373
|
+
}
|
|
1374
|
+
export class WalletFinderDevice extends GenericDevice {
|
|
1375
|
+
}
|
|
1376
|
+
// K10 / WoSweeper variants map to VacuumDevice
|
|
1377
|
+
export class WoSweeperDevice extends VacuumDevice {
|
|
1378
|
+
}
|
|
1379
|
+
export class WoSweeperMiniDevice extends VacuumDevice {
|
|
1380
|
+
}
|
|
1381
|
+
export class WoSweeperMiniProDevice extends VacuumDevice {
|
|
1382
|
+
}
|
|
1383
|
+
//# sourceMappingURL=genericDevice.js.map
|