@switchbot/homebridge-switchbot 5.0.0-beta.98 → 5.0.0
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/.changeset/config.json +14 -0
- package/.github/copilot-instructions.md +39 -0
- package/.github/workflows/ci.yml +4 -1
- package/.github/workflows/manual-e2e.yml +6 -3
- package/.github/workflows/release.yml +64 -15
- package/.github/workflows/stale.yml +2 -4
- package/.husky/pre-push +15 -0
- package/CHANGELOG.md +126 -134
- package/MIGRATION.md +16 -6
- package/README.md +84 -3
- package/TODO.md +263 -0
- package/config.schema.json +229 -36
- package/dist/SwitchBotHAPPlatform.d.ts +133 -0
- package/dist/SwitchBotHAPPlatform.d.ts.map +1 -0
- package/dist/SwitchBotHAPPlatform.js +555 -0
- package/dist/SwitchBotHAPPlatform.js.map +1 -0
- package/dist/SwitchBotMatterPlatform.d.ts +141 -0
- package/dist/SwitchBotMatterPlatform.d.ts.map +1 -0
- package/dist/SwitchBotMatterPlatform.js +536 -0
- package/dist/SwitchBotMatterPlatform.js.map +1 -0
- 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/deviceCommandMapper.d.ts +10 -0
- package/dist/deviceCommandMapper.d.ts.map +1 -0
- package/dist/deviceCommandMapper.js +319 -0
- package/dist/deviceCommandMapper.js.map +1 -0
- package/dist/deviceFactory.d.ts +3 -2
- package/dist/deviceFactory.d.ts.map +1 -1
- package/dist/deviceFactory.js +107 -29
- package/dist/deviceFactory.js.map +1 -1
- package/dist/devices/genericDevice.d.ts +59 -37
- package/dist/devices/genericDevice.d.ts.map +1 -1
- package/dist/devices/genericDevice.js +376 -78
- package/dist/devices/genericDevice.js.map +1 -1
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/errors.js.map +1 -0
- package/dist/homebridge-ui/device-types.js +246 -0
- package/dist/homebridge-ui/device-types.js.map +1 -0
- package/dist/homebridge-ui/deviceCommandMapper.js +319 -0
- package/dist/homebridge-ui/deviceCommandMapper.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 +90 -0
- package/dist/homebridge-ui/endpoints/config.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 +144 -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 +219 -0
- package/dist/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/errors.js +32 -0
- package/dist/homebridge-ui/errors.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/config.js +90 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/config.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/devices.js +144 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/devices.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/discovery.js +219 -0
- package/dist/homebridge-ui/homebridge-ui/endpoints/discovery.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/server.js +11 -0
- package/dist/homebridge-ui/homebridge-ui/server.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/utils/config-parser.js +108 -0
- package/dist/homebridge-ui/homebridge-ui/utils/config-parser.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/utils/device-migration.js +111 -0
- package/dist/homebridge-ui/homebridge-ui/utils/device-migration.js.map +1 -0
- package/dist/homebridge-ui/homebridge-ui/utils/logger.js +17 -0
- package/dist/homebridge-ui/homebridge-ui/utils/logger.js.map +1 -0
- package/dist/homebridge-ui/public/css/styles.css +483 -0
- package/dist/homebridge-ui/public/index.html +197 -621
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts +3 -0
- package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/advanced-settings.js +95 -0
- package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -0
- package/dist/homebridge-ui/public/js/advanced-settings.ts +94 -0
- package/dist/homebridge-ui/public/js/api.d.ts +66 -0
- package/dist/homebridge-ui/public/js/api.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/api.js +295 -0
- package/dist/homebridge-ui/public/js/api.js.map +1 -0
- package/dist/homebridge-ui/public/js/api.ts +355 -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 +3722 -0
- package/dist/homebridge-ui/public/js/app.js.map +7 -0
- package/dist/homebridge-ui/public/js/app.ts +22 -0
- package/dist/homebridge-ui/public/js/constants.d.ts +2 -0
- package/dist/homebridge-ui/public/js/constants.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/constants.js +2 -0
- package/dist/homebridge-ui/public/js/constants.js.map +1 -0
- package/dist/homebridge-ui/public/js/constants.ts +1 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts +3 -0
- package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.js +99 -0
- package/dist/homebridge-ui/public/js/credentials.js.map +1 -0
- package/dist/homebridge-ui/public/js/credentials.ts +105 -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 +199 -0
- package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices-delete.ts +227 -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 +98 -0
- package/dist/homebridge-ui/public/js/devices.js.map +1 -0
- package/dist/homebridge-ui/public/js/devices.ts +106 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts +9 -0
- package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.js +1201 -0
- package/dist/homebridge-ui/public/js/discovery.js.map +1 -0
- package/dist/homebridge-ui/public/js/discovery.ts +1335 -0
- package/dist/homebridge-ui/public/js/logger.d.ts +7 -0
- package/dist/homebridge-ui/public/js/logger.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/logger.js +17 -0
- package/dist/homebridge-ui/public/js/logger.js.map +1 -0
- package/dist/homebridge-ui/public/js/logger.ts +17 -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 +35 -0
- package/dist/homebridge-ui/public/js/modal.js.map +1 -0
- package/dist/homebridge-ui/public/js/modal.ts +35 -0
- package/dist/homebridge-ui/public/js/modals.d.ts +15 -0
- package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/modals.js +675 -0
- package/dist/homebridge-ui/public/js/modals.js.map +1 -0
- package/dist/homebridge-ui/public/js/modals.ts +765 -0
- package/dist/homebridge-ui/public/js/render.d.ts +71 -0
- package/dist/homebridge-ui/public/js/render.d.ts.map +1 -0
- package/dist/homebridge-ui/public/js/render.js +960 -0
- package/dist/homebridge-ui/public/js/render.js.map +1 -0
- package/dist/homebridge-ui/public/js/render.ts +1084 -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 +38 -0
- package/dist/homebridge-ui/public/js/toast.js.map +1 -0
- package/dist/homebridge-ui/public/js/toast.ts +44 -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.d.ts +1 -3
- package/dist/homebridge-ui/server.d.ts.map +1 -1
- package/dist/homebridge-ui/server.js +8 -450
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/homebridge-ui/settings.js +8 -0
- package/dist/homebridge-ui/settings.js.map +1 -0
- package/dist/homebridge-ui/switchbotClient.js +247 -0
- package/dist/homebridge-ui/switchbotClient.js.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts +39 -0
- package/dist/homebridge-ui/utils/config-parser.d.ts.map +1 -0
- package/dist/homebridge-ui/utils/config-parser.js +108 -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 +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +1 -0
- package/dist/settings.js.map +1 -1
- package/dist/switchbotClient.d.ts +12 -10
- package/dist/switchbotClient.d.ts.map +1 -1
- package/dist/switchbotClient.js +156 -103
- package/dist/switchbotClient.js.map +1 -1
- package/dist/utils.d.ts +76 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1121 -4
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +16 -2
- package/docs/assets/main.js +1 -1
- package/docs/index.html +82 -5
- package/docs/variables/default.html +3 -1
- package/eslint.config.js +9 -5
- package/nodemon.json +2 -2
- package/package.json +34 -21
- package/scripts/build-ui.js +37 -0
- package/scripts/free-dev-ports.mjs +105 -0
- package/scripts/generate-matter-maps.js +34 -17
- package/scripts/sync-device-types.mjs +31 -0
- package/src/SwitchBotHAPPlatform.ts +558 -0
- package/src/SwitchBotMatterPlatform.ts +538 -0
- package/src/device-types.js +246 -0
- package/src/device-types.js.map +1 -0
- package/src/device-types.ts +261 -0
- package/src/deviceCommandMapper.js +319 -0
- package/src/deviceCommandMapper.js.map +1 -0
- package/src/deviceCommandMapper.ts +333 -0
- package/src/deviceFactory.ts +125 -45
- package/src/devices/genericDevice.ts +411 -69
- package/src/errors.js +32 -0
- package/src/errors.js.map +1 -0
- package/src/errors.ts +35 -0
- package/src/homebridge-ui/endpoints/config.ts +110 -0
- package/src/homebridge-ui/endpoints/devices.ts +153 -0
- package/src/homebridge-ui/endpoints/discovery.ts +240 -0
- package/src/homebridge-ui/public/css/styles.css +483 -0
- package/src/homebridge-ui/public/index.html +197 -621
- package/src/homebridge-ui/public/js/advanced-settings.ts +94 -0
- package/src/homebridge-ui/public/js/api.ts +355 -0
- package/src/homebridge-ui/public/js/app.ts +22 -0
- package/src/homebridge-ui/public/js/constants.ts +1 -0
- package/src/homebridge-ui/public/js/credentials.ts +105 -0
- package/src/homebridge-ui/public/js/devices-delete.ts +227 -0
- package/src/homebridge-ui/public/js/devices.ts +106 -0
- package/src/homebridge-ui/public/js/discovery.ts +1335 -0
- package/src/homebridge-ui/public/js/logger.ts +17 -0
- package/src/homebridge-ui/public/js/modal.ts +35 -0
- package/src/homebridge-ui/public/js/modals.ts +765 -0
- package/src/homebridge-ui/public/js/render.ts +1084 -0
- package/src/homebridge-ui/public/js/toast.ts +44 -0
- package/src/homebridge-ui/public/js/types.ts +26 -0
- package/src/homebridge-ui/server.ts +9 -526
- package/src/homebridge-ui/utils/config-parser.ts +125 -0
- package/src/homebridge-ui/utils/device-migration.ts +144 -0
- package/src/homebridge-ui/utils/logger.ts +17 -0
- package/src/index.ts +12 -2
- package/src/settings.js +8 -0
- package/src/settings.js.map +1 -0
- package/src/settings.ts +2 -0
- package/src/switchbotClient.js +247 -0
- package/src/switchbotClient.js.map +1 -0
- package/src/switchbotClient.ts +177 -114
- package/src/utils.ts +1133 -5
- package/test/client/switchbot-client-debounce.spec.ts +35 -0
- package/test/client/switchbot-client-openapi.spec.ts +19 -0
- package/test/client/switchbotClient.spec.ts +64 -0
- package/test/device/device-mapping.spec.ts +23 -0
- package/test/device/deviceBase.spec.ts +26 -0
- package/test/device/deviceFactory-edge.spec.ts +15 -0
- package/test/device/deviceFactory.spec.ts +33 -0
- package/test/device/fan-swing.spec.ts +34 -0
- package/test/device/genericDevice-blepoll.spec.ts +47 -0
- package/test/device/irdevice.spec.ts +9 -0
- package/test/device/lock-users.spec.ts +35 -0
- package/test/device/matter-descriptors.spec.ts +22 -0
- package/test/device/matter-device-state.spec.ts +37 -0
- package/test/e2e/run-e2e.spec.ts +18 -19
- package/test/errors/errors.spec.ts +10 -0
- package/test/helpers/matter-harness.ts +20 -9
- package/test/homebridge-ui/server.spec.ts +9 -0
- package/test/platform/accessory-restore.spec.ts +37 -0
- package/test/platform/matter-childbridge.spec.ts +34 -0
- package/test/platform/matter-integration.spec.ts +33 -0
- package/test/platform/platform-edge.spec.ts +73 -0
- package/test/platform/platform.integration.spec.ts +34 -0
- package/test/utils/utils-extra.spec.ts +10 -0
- package/test/utils/utils.spec.ts +53 -0
- package/todo/TODO.md +80 -0
- package/tsconfig.ui.json +11 -0
- package/.github/npm-version-script-esm.js +0 -97
- package/.github/workflows/beta-release.yml +0 -52
- package/dist/platform.d.ts +0 -35
- package/dist/platform.d.ts.map +0 -1
- package/dist/platform.js +0 -850
- package/dist/platform.js.map +0 -1
- package/src/platform.ts +0 -867
- package/test/accessory-restore.spec.ts +0 -73
- package/test/device-mapping.spec.ts +0 -37
- package/test/deviceFactory.spec.ts +0 -18
- package/test/fan-swing.spec.ts +0 -29
- package/test/lock-users.spec.ts +0 -44
- package/test/matter-childbridge.spec.ts +0 -55
- package/test/matter-descriptors.spec.ts +0 -97
- package/test/matter-device-state.spec.ts +0 -101
- package/test/matter-integration.spec.ts +0 -70
- package/test/platform.integration.spec.ts +0 -55
- package/test/switchbot-client-debounce.spec.ts +0 -131
- package/test/switchbot-client-openapi.spec.ts +0 -56
- package/test/switchbotClient.spec.ts +0 -10
- package/test/utils.spec.ts +0 -20
package/config.schema.json
CHANGED
|
@@ -27,14 +27,29 @@
|
|
|
27
27
|
"description": "Optional OpenAPI secret for certain account setups.",
|
|
28
28
|
"format": "password"
|
|
29
29
|
},
|
|
30
|
+
"enableBLE": {
|
|
31
|
+
"type": "boolean",
|
|
32
|
+
"title": "Enable BLE (Bluetooth)",
|
|
33
|
+
"description": "Enable or disable BLE (Bluetooth Low Energy) support. If disabled, only OpenAPI (cloud) will be used.",
|
|
34
|
+
"default": true
|
|
35
|
+
},
|
|
30
36
|
"devices": {
|
|
31
37
|
"type": "array",
|
|
32
38
|
"title": "Devices",
|
|
33
39
|
"description": "List of SwitchBot devices to manage. Use the UI to add devices and copy device IDs.",
|
|
34
40
|
"items": {
|
|
35
41
|
"type": "object",
|
|
36
|
-
"required": [
|
|
42
|
+
"required": [
|
|
43
|
+
"deviceId",
|
|
44
|
+
"configDeviceType"
|
|
45
|
+
],
|
|
37
46
|
"properties": {
|
|
47
|
+
"enabled": {
|
|
48
|
+
"type": "boolean",
|
|
49
|
+
"title": "Enabled",
|
|
50
|
+
"description": "Enable or disable this device without removing it from the config.",
|
|
51
|
+
"default": true
|
|
52
|
+
},
|
|
38
53
|
"configDeviceName": {
|
|
39
54
|
"type": "string",
|
|
40
55
|
"title": "Name",
|
|
@@ -50,55 +65,222 @@
|
|
|
50
65
|
"title": "Device Type",
|
|
51
66
|
"description": "Select the device type so the plugin can expose the correct HomeKit/Matter services and characteristics.",
|
|
52
67
|
"enum": [
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
"Blind Tilt",
|
|
69
|
+
"Curtain",
|
|
70
|
+
"Curtain3",
|
|
71
|
+
"Roller Shade",
|
|
72
|
+
"Keypad",
|
|
73
|
+
"Keypad Touch",
|
|
74
|
+
"Keypad Vision",
|
|
75
|
+
"Keypad Vision Pro",
|
|
76
|
+
"Lock Vision Pro",
|
|
77
|
+
"Lock Lite",
|
|
78
|
+
"Smart Lock",
|
|
79
|
+
"Smart Lock Pro",
|
|
80
|
+
"Smart Lock Ultra",
|
|
81
|
+
"Video Doorbell",
|
|
82
|
+
"Contact Sensor",
|
|
83
|
+
"Motion Sensor",
|
|
84
|
+
"Presence Sensor",
|
|
85
|
+
"Water Detector",
|
|
86
|
+
"Candle Warmer Lamp",
|
|
87
|
+
"Ceiling Light",
|
|
88
|
+
"Ceiling Light Pro",
|
|
89
|
+
"Color Bulb",
|
|
90
|
+
"Floor Lamp",
|
|
91
|
+
"RGBIC Neon Rope Light",
|
|
92
|
+
"RGBIC Neon Wire Rope Light",
|
|
93
|
+
"RGBICWW Floor Lamp",
|
|
94
|
+
"RGBICWW Strip Light",
|
|
95
|
+
"Strip Light",
|
|
96
|
+
"Strip Light 3",
|
|
97
|
+
"Air Purifier PM2.5",
|
|
98
|
+
"Air Purifier Table PM2.5",
|
|
99
|
+
"Air Purifier VOC",
|
|
100
|
+
"Air Purifier Table VOC",
|
|
101
|
+
"Battery Circulator Fan",
|
|
102
|
+
"Circulator Fan",
|
|
103
|
+
"Humidifier",
|
|
104
|
+
"Humidifier2",
|
|
105
|
+
"Meter",
|
|
106
|
+
"MeterPlus",
|
|
107
|
+
"Meter Plus",
|
|
108
|
+
"MeterPro",
|
|
109
|
+
"Meter Pro",
|
|
110
|
+
"MeterPro(CO2)",
|
|
111
|
+
"Meter Pro (CO2)",
|
|
112
|
+
"Smart Radiator Thermostat",
|
|
113
|
+
"Standing Circulator Fan",
|
|
114
|
+
"WoIOSensor",
|
|
115
|
+
"Garage Door Opener",
|
|
116
|
+
"Plug",
|
|
117
|
+
"Plug Mini (EU)",
|
|
118
|
+
"Plug Mini (JP)",
|
|
119
|
+
"Plug Mini (US)",
|
|
120
|
+
"Relay Switch 1",
|
|
121
|
+
"Relay Switch 1PM",
|
|
122
|
+
"Relay Switch 2PM",
|
|
123
|
+
"K10+",
|
|
124
|
+
"K10+ Pro",
|
|
125
|
+
"Robot Vacuum Cleaner K10+ Pro Combo",
|
|
126
|
+
"Robot Vacuum Cleaner K11+",
|
|
127
|
+
"Robot Vacuum Cleaner K20 Plus Pro",
|
|
128
|
+
"Robot Vacuum Cleaner S1",
|
|
129
|
+
"Robot Vacuum Cleaner S1 Plus",
|
|
130
|
+
"Robot Vacuum Cleaner S10",
|
|
131
|
+
"Robot Vacuum Cleaner S20",
|
|
132
|
+
"AI Hub",
|
|
133
|
+
"Hub",
|
|
134
|
+
"Hub 2",
|
|
135
|
+
"Hub 3",
|
|
136
|
+
"Hub Mini",
|
|
137
|
+
"Hub Plus",
|
|
138
|
+
"Indoor Cam",
|
|
139
|
+
"Pan/Tilt Cam",
|
|
140
|
+
"Pan/Tilt Cam 2K",
|
|
141
|
+
"Pan/Tilt Cam Plus 2K",
|
|
142
|
+
"Pan/Tilt Cam Plus 3K",
|
|
143
|
+
"Air Conditioner",
|
|
144
|
+
"Air Purifier",
|
|
145
|
+
"Camera",
|
|
146
|
+
"DVD",
|
|
147
|
+
"Fan",
|
|
148
|
+
"Light",
|
|
149
|
+
"Others",
|
|
150
|
+
"Projector",
|
|
151
|
+
"Set Top Box",
|
|
152
|
+
"Speaker",
|
|
153
|
+
"Streamer",
|
|
154
|
+
"TV",
|
|
155
|
+
"Vacuum Cleaner",
|
|
156
|
+
"Water Heater",
|
|
157
|
+
"AI Art Frame",
|
|
158
|
+
"Bot",
|
|
159
|
+
"Home Climate Panel",
|
|
160
|
+
"Remote",
|
|
161
|
+
"remote with screen"
|
|
162
|
+
]
|
|
76
163
|
},
|
|
77
164
|
"connectionPreference": {
|
|
78
165
|
"type": "string",
|
|
79
166
|
"title": "Connection Preference",
|
|
80
167
|
"description": "Select whether this device should prefer BLE, OpenAPI, or auto-detect (hybrid).",
|
|
81
|
-
"enum": [
|
|
168
|
+
"enum": [
|
|
169
|
+
"auto",
|
|
170
|
+
"ble",
|
|
171
|
+
"openapi"
|
|
172
|
+
],
|
|
82
173
|
"default": "auto"
|
|
83
174
|
},
|
|
84
175
|
"room": {
|
|
85
176
|
"type": "string",
|
|
86
177
|
"title": "Room",
|
|
87
178
|
"description": "Optional room/location metadata for the device."
|
|
179
|
+
},
|
|
180
|
+
"encryptionKey": {
|
|
181
|
+
"type": "string",
|
|
182
|
+
"title": "BLE Encryption Key",
|
|
183
|
+
"description": "(Advanced) Optional BLE encryption key for this device. Required for some locks, relays, air purifiers, and light strips. See plugin docs for how to obtain this key.",
|
|
184
|
+
"format": "password"
|
|
185
|
+
},
|
|
186
|
+
"keyId": {
|
|
187
|
+
"type": "string",
|
|
188
|
+
"title": "BLE Key ID",
|
|
189
|
+
"description": "(Advanced) Optional BLE key ID for this device (usually 2 hex characters, e.g. 'ff'). Only required for some locks."
|
|
190
|
+
},
|
|
191
|
+
"refreshRate": {
|
|
192
|
+
"type": "integer",
|
|
193
|
+
"title": "OpenAPI Polling Interval (seconds)",
|
|
194
|
+
"description": "How often to poll this device via OpenAPI for status (in seconds). Overrides platform value if set. Default: 300 (5 minutes). Minimum: 30.",
|
|
195
|
+
"default": 300,
|
|
196
|
+
"minimum": 30
|
|
88
197
|
}
|
|
89
198
|
}
|
|
90
199
|
}
|
|
91
|
-
},
|
|
92
|
-
"enableMatter": {
|
|
93
|
-
"type": "boolean",
|
|
94
|
-
"title": "Enable Matter Support (Override)",
|
|
95
|
-
"description": "Manually enable Matter support. By default, Matter is auto-detected from the child bridge configuration. Only change this if you need to override the auto-detection."
|
|
96
|
-
},
|
|
97
|
-
"preferMatter": {
|
|
98
|
-
"type": "boolean",
|
|
99
|
-
"title": "Prefer Matter when available",
|
|
100
|
-
"description": "If enabled and Matter is available, devices will be presented as Matter accessories where supported (instead of HAP)."
|
|
101
200
|
}
|
|
201
|
+
},
|
|
202
|
+
"openApiRefreshRate": {
|
|
203
|
+
"type": "integer",
|
|
204
|
+
"title": "OpenAPI Polling Interval (seconds)",
|
|
205
|
+
"description": "How often to poll devices via OpenAPI for status (in seconds). Default: 300 (5 minutes). Minimum: 30. Can be overridden per device.",
|
|
206
|
+
"default": 300,
|
|
207
|
+
"minimum": 30
|
|
208
|
+
},
|
|
209
|
+
"matterBatchEnabled": {
|
|
210
|
+
"type": "boolean",
|
|
211
|
+
"title": "Enable Batched OpenAPI Polling",
|
|
212
|
+
"description": "If enabled, the platform will poll all OpenAPI devices in a single batch at the configured interval. Devices with per-device refreshRate are excluded from the batch.",
|
|
213
|
+
"default": true
|
|
214
|
+
},
|
|
215
|
+
"matterBatchRefreshRate": {
|
|
216
|
+
"type": "integer",
|
|
217
|
+
"title": "OpenAPI Batch Polling Interval (seconds)",
|
|
218
|
+
"description": "Interval for batched OpenAPI polling (in seconds). Falls back to openApiRefreshRate if not set. Default: 300.",
|
|
219
|
+
"default": 300,
|
|
220
|
+
"minimum": 30
|
|
221
|
+
},
|
|
222
|
+
"dailyApiLimit": {
|
|
223
|
+
"type": "integer",
|
|
224
|
+
"title": "OpenAPI Daily Request Limit",
|
|
225
|
+
"description": "Maximum OpenAPI requests per day allowed by the plugin. Default: 10000.",
|
|
226
|
+
"default": 10000,
|
|
227
|
+
"minimum": 1000
|
|
228
|
+
},
|
|
229
|
+
"dailyApiReserveForCommands": {
|
|
230
|
+
"type": "integer",
|
|
231
|
+
"title": "OpenAPI Reserve for Commands",
|
|
232
|
+
"description": "Requests reserved for user actions (commands/webhooks). When remaining budget reaches this value, background polling pauses. Default: 1000.",
|
|
233
|
+
"default": 1000,
|
|
234
|
+
"minimum": 0
|
|
235
|
+
},
|
|
236
|
+
"dailyApiResetLocalMidnight": {
|
|
237
|
+
"type": "boolean",
|
|
238
|
+
"title": "Reset OpenAPI Counter at Local Midnight",
|
|
239
|
+
"description": "If true, resets the daily OpenAPI request counter at local midnight. If false, resets at UTC midnight.",
|
|
240
|
+
"default": false
|
|
241
|
+
},
|
|
242
|
+
"webhookOnlyOnReserve": {
|
|
243
|
+
"type": "boolean",
|
|
244
|
+
"title": "Only Allow Webhooks on Reserve",
|
|
245
|
+
"description": "When remaining OpenAPI budget reaches the reserve, only webhooks and user commands are allowed. Background polling/discovery pauses.",
|
|
246
|
+
"default": false
|
|
247
|
+
},
|
|
248
|
+
"matterBatchConcurrency": {
|
|
249
|
+
"type": "integer",
|
|
250
|
+
"title": "OpenAPI Batch Concurrency",
|
|
251
|
+
"description": "Maximum number of parallel OpenAPI status calls during a batch. Default: 5.",
|
|
252
|
+
"default": 5,
|
|
253
|
+
"minimum": 1
|
|
254
|
+
},
|
|
255
|
+
"matterBatchJitter": {
|
|
256
|
+
"type": "integer",
|
|
257
|
+
"title": "OpenAPI Batch Jitter (seconds)",
|
|
258
|
+
"description": "Random startup delay before the first batch to reduce synchronized spikes. Default: 0.",
|
|
259
|
+
"default": 0,
|
|
260
|
+
"minimum": 0
|
|
261
|
+
},
|
|
262
|
+
"enableMatter": {
|
|
263
|
+
"type": "boolean",
|
|
264
|
+
"title": "Enable Matter Support (Override)",
|
|
265
|
+
"description": "Manually enable Matter support. By default, Matter is auto-detected from the child bridge configuration. Only change this if you need to override the auto-detection."
|
|
266
|
+
},
|
|
267
|
+
"preferMatter": {
|
|
268
|
+
"type": "boolean",
|
|
269
|
+
"title": "Prefer Matter when available",
|
|
270
|
+
"description": "If enabled and Matter is available, devices will be presented as Matter accessories where supported (instead of HAP)."
|
|
271
|
+
},
|
|
272
|
+
"blePollingEnabled": {
|
|
273
|
+
"type": "boolean",
|
|
274
|
+
"title": "Enable BLE Polling Fallback",
|
|
275
|
+
"description": "If enabled, the plugin will periodically poll BLE devices for status as a safety net in addition to real-time notifications. This helps recover from missed notifications or connection loss. Recommended for reliability. Can be overridden per device.",
|
|
276
|
+
"default": true
|
|
277
|
+
},
|
|
278
|
+
"blePollIntervalMs": {
|
|
279
|
+
"type": "integer",
|
|
280
|
+
"title": "BLE Polling Interval (ms)",
|
|
281
|
+
"description": "How often to poll BLE devices for status (in milliseconds). Default is 600000 (10 minutes). Set higher to reduce battery drain. Minimum 60000 (1 minute). Can be overridden per device.",
|
|
282
|
+
"default": 600000,
|
|
283
|
+
"minimum": 60000
|
|
102
284
|
}
|
|
103
285
|
},
|
|
104
286
|
"layout": [
|
|
@@ -127,7 +309,18 @@
|
|
|
127
309
|
"expanded": false,
|
|
128
310
|
"items": [
|
|
129
311
|
"enableMatter",
|
|
130
|
-
"preferMatter"
|
|
312
|
+
"preferMatter",
|
|
313
|
+
"blePollingEnabled",
|
|
314
|
+
"blePollIntervalMs",
|
|
315
|
+
"openApiRefreshRate",
|
|
316
|
+
"matterBatchEnabled",
|
|
317
|
+
"matterBatchRefreshRate",
|
|
318
|
+
"dailyApiLimit",
|
|
319
|
+
"dailyApiReserveForCommands",
|
|
320
|
+
"dailyApiResetLocalMidnight",
|
|
321
|
+
"webhookOnlyOnReserve",
|
|
322
|
+
"matterBatchConcurrency",
|
|
323
|
+
"matterBatchJitter"
|
|
131
324
|
]
|
|
132
325
|
}
|
|
133
326
|
]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { SwitchBotPluginConfig } from './settings.js';
|
|
2
|
+
import type { API, Logger, PlatformConfig } from 'homebridge';
|
|
3
|
+
/**
|
|
4
|
+
* Homebridge platform class for SwitchBot HAP (HomeKit Accessory Protocol) integration.
|
|
5
|
+
* Handles device discovery, registration, polling, and accessory lifecycle for HAP-enabled SwitchBot devices.
|
|
6
|
+
*
|
|
7
|
+
* @class SwitchBotHAPPlatform
|
|
8
|
+
* @param {Logger} log - Homebridge logger instance
|
|
9
|
+
* @param {PlatformConfig} config - Platform configuration object
|
|
10
|
+
* @param {API} [api] - Optional Homebridge API instance
|
|
11
|
+
* @property {API | undefined} api - Homebridge API instance
|
|
12
|
+
* @property {Logger} log - Homebridge logger instance
|
|
13
|
+
* @property {SwitchBotPluginConfig} config - Parsed plugin config
|
|
14
|
+
* @property {any[]} devices - All created device instances
|
|
15
|
+
* @property {Map<string, any>} accessories - Map of accessory UUID to accessory object
|
|
16
|
+
* @property {string} lastConfigHash - Hash of last loaded config for change detection
|
|
17
|
+
* @property {NodeJS.Timeout | null} configReloadInterval - Interval for periodic config reload
|
|
18
|
+
* @property {Map<string, NodeJS.Timeout>} openApiPollTimers - Timers for per-device OpenAPI polling
|
|
19
|
+
* @property {NodeJS.Timeout | null} openApiBatchTimer - Timer for batched OpenAPI polling
|
|
20
|
+
* @property {number} openApiRequestsToday - Count of OpenAPI requests made today
|
|
21
|
+
* @property {number} openApiLastReset - Timestamp (ms) of last OpenAPI daily counter reset
|
|
22
|
+
*/
|
|
23
|
+
export declare class SwitchBotHAPPlatform {
|
|
24
|
+
/** Homebridge API instance */
|
|
25
|
+
api: API | undefined;
|
|
26
|
+
/** Homebridge logger instance */
|
|
27
|
+
log: Logger;
|
|
28
|
+
/** Parsed plugin config */
|
|
29
|
+
config: SwitchBotPluginConfig;
|
|
30
|
+
/** All created device instances */
|
|
31
|
+
devices: any[];
|
|
32
|
+
/** Map of accessory UUID to accessory object */
|
|
33
|
+
accessories: Map<string, any>;
|
|
34
|
+
/** Hash of last loaded config for change detection */
|
|
35
|
+
private lastConfigHash;
|
|
36
|
+
/** Interval for periodic config reload */
|
|
37
|
+
private configReloadInterval;
|
|
38
|
+
/** Timers for per-device OpenAPI polling */
|
|
39
|
+
private openApiPollTimers;
|
|
40
|
+
/** Timer for batched OpenAPI polling */
|
|
41
|
+
private openApiBatchTimer;
|
|
42
|
+
/** Count of OpenAPI requests made today */
|
|
43
|
+
private openApiRequestsToday;
|
|
44
|
+
/** Timestamp (ms) of last OpenAPI daily counter reset */
|
|
45
|
+
private openApiLastReset;
|
|
46
|
+
/**
|
|
47
|
+
* Construct the SwitchBot HAP platform.
|
|
48
|
+
* @param log Homebridge logger
|
|
49
|
+
* @param config Platform config
|
|
50
|
+
* @param api Homebridge API instance
|
|
51
|
+
*/
|
|
52
|
+
constructor(log: Logger, config: PlatformConfig, api?: API);
|
|
53
|
+
/**
|
|
54
|
+
* Discover and create all device instances from config.
|
|
55
|
+
* Populates this.devices and registers HAP accessories for each device.
|
|
56
|
+
* Ensures Matter API is loaded before loading devices if available.
|
|
57
|
+
*
|
|
58
|
+
* @returns {Promise<void>} Resolves when all devices are loaded and registered
|
|
59
|
+
*/
|
|
60
|
+
loadDevices(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Registers all HAP accessories with the Homebridge HAP API.
|
|
63
|
+
*
|
|
64
|
+
* This method is called after all device instances have been created. It handles both new and restored
|
|
65
|
+
* accessories, updating their context and adding or updating HAP services and characteristics as needed.
|
|
66
|
+
* Accessories are registered with Homebridge using the HAP API, and the internal accessory map is updated accordingly.
|
|
67
|
+
*
|
|
68
|
+
* @param {Array<{created: any, d: any, type: string}>} createdDevices - Array of device descriptors:
|
|
69
|
+
* - created: The created device instance
|
|
70
|
+
* - d: The normalized device config object
|
|
71
|
+
* - type: The normalized device type string
|
|
72
|
+
* @returns {Promise<void>} Resolves when registration is complete
|
|
73
|
+
*
|
|
74
|
+
* Differences from Matter registration:
|
|
75
|
+
* - Uses the HAP API (not Matter API) for accessory registration.
|
|
76
|
+
* - Adds HAP services and characteristics to each accessory based on the device descriptor.
|
|
77
|
+
* - Does not require or check for Matter support or availability.
|
|
78
|
+
* - Accessory context and service wiring are HAP-specific.
|
|
79
|
+
*
|
|
80
|
+
* If the Homebridge HAP API is not available, registration is skipped and a log message is emitted.
|
|
81
|
+
*/
|
|
82
|
+
private registerHAPAccessories;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the timestamp (ms) of the last OpenAPI daily counter reset.
|
|
85
|
+
* @returns {number} Timestamp in ms
|
|
86
|
+
*/
|
|
87
|
+
getOpenApiLastReset(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Logs the last OpenAPI reset time in a human-readable format.
|
|
90
|
+
* @returns {void}
|
|
91
|
+
*/
|
|
92
|
+
logOpenApiLastReset(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Compute a hash of the current device config for change detection.
|
|
95
|
+
* @returns {string} JSON string hash of device config
|
|
96
|
+
*/
|
|
97
|
+
private getConfigHash;
|
|
98
|
+
/**
|
|
99
|
+
* Reload devices if config has changed since last load.
|
|
100
|
+
* Unregisters accessories and removes devices no longer in config.
|
|
101
|
+
* Calls loadDevices to repopulate devices and accessories.
|
|
102
|
+
*
|
|
103
|
+
* @returns {Promise<void>} Resolves when reload is complete
|
|
104
|
+
*/
|
|
105
|
+
private checkAndReloadDevices;
|
|
106
|
+
/**
|
|
107
|
+
* Cleanup method to clear config reload interval on shutdown.
|
|
108
|
+
* Called by Homebridge on shutdown event.
|
|
109
|
+
* @returns {void}
|
|
110
|
+
*/
|
|
111
|
+
shutdown(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Setup OpenAPI polling for all devices according to config (global, per-device, batch, rate limit).
|
|
114
|
+
* Handles daily request limits, per-device and batch polling, and resets.
|
|
115
|
+
*
|
|
116
|
+
* @returns {void}
|
|
117
|
+
*/
|
|
118
|
+
private _setupOpenApiPolling;
|
|
119
|
+
/**
|
|
120
|
+
* Called by Homebridge to restore cached HAP accessories on startup.
|
|
121
|
+
* @param {any} accessory - The cached accessory object
|
|
122
|
+
* @returns {Promise<void>} Resolves when accessory is restored
|
|
123
|
+
*/
|
|
124
|
+
configureAccessory(accessory: any): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Called by Homebridge when a cached Matter accessory is restored (optional signature).
|
|
127
|
+
* @param {any} accessory - The cached accessory object
|
|
128
|
+
* @returns {void}
|
|
129
|
+
*/
|
|
130
|
+
configureMatterAccessory?(accessory: any): void;
|
|
131
|
+
}
|
|
132
|
+
export default SwitchBotHAPPlatform;
|
|
133
|
+
//# sourceMappingURL=SwitchBotHAPPlatform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwitchBotHAPPlatform.d.ts","sourceRoot":"","sources":["../src/SwitchBotHAPPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAO7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,oBAAoB;IAC/B,8BAA8B;IAC9B,GAAG,EAAE,GAAG,GAAG,SAAS,CAAA;IACpB,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,2BAA2B;IAC3B,MAAM,EAAE,qBAAqB,CAAA;IAC7B,mCAAmC;IACnC,OAAO,EAAE,GAAG,EAAE,CAAK;IACnB,gDAAgD;IAChD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,sDAAsD;IACtD,OAAO,CAAC,cAAc,CAAa;IACnC,0CAA0C;IAC1C,OAAO,CAAC,oBAAoB,CAA8B;IAC1D,4CAA4C;IAC5C,OAAO,CAAC,iBAAiB,CAAyC;IAClE,wCAAwC;IACxC,OAAO,CAAC,iBAAiB,CAA8B;IACvD,2CAA2C;IAC3C,OAAO,CAAC,oBAAoB,CAAI;IAChC,yDAAyD;IACzD,OAAO,CAAC,gBAAgB,CAAI;IAE5B;;;;;OAKG;gBACS,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,GAAG;IA2C1D;;;;;;OAMG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA6DlC;;;;;;;;;;;;;;;;;;;;OAoBG;YACW,sBAAsB;IAgHpC;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAI7B;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAS3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAUrB;;;;;;OAMG;YACW,qBAAqB;IAiCnC;;;;OAIG;IACH,QAAQ,IAAI,IAAI;IAQhB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAkI5B;;;;OAIG;IACG,kBAAkB,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD;;;;OAIG;IACH,wBAAwB,CAAC,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI;CAShD;AAED,eAAe,oBAAoB,CAAA"}
|