@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/src/deviceFactory.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Logger } from 'homebridge'
|
|
2
|
+
|
|
3
|
+
import type { DeviceType, SwitchBotPluginConfig } from './settings.js'
|
|
4
|
+
|
|
5
|
+
import { DEVICE_TYPE_NORMALIZATION_MAP } from './device-types.js'
|
|
3
6
|
import {
|
|
4
|
-
|
|
7
|
+
BlindTiltDevice,
|
|
5
8
|
BotDevice,
|
|
9
|
+
ContactSensorDevice,
|
|
10
|
+
Curtain3Device,
|
|
6
11
|
CurtainDevice,
|
|
7
12
|
FanDevice,
|
|
13
|
+
GenericDevice,
|
|
14
|
+
Hub2Device,
|
|
15
|
+
HumidifierDevice,
|
|
8
16
|
LightDevice,
|
|
9
17
|
LightStripDevice,
|
|
10
|
-
MotionSensorDevice,
|
|
11
|
-
ContactSensorDevice,
|
|
12
|
-
VacuumDevice,
|
|
13
18
|
LockDevice,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
RelaySwitchDevice,
|
|
17
|
-
RelaySwitch1PMDevice,
|
|
19
|
+
MeterDevice,
|
|
20
|
+
MotionSensorDevice,
|
|
18
21
|
PlugDevice,
|
|
19
22
|
PlugMiniDevice,
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
RelaySwitch1PMDevice,
|
|
24
|
+
RelaySwitchDevice,
|
|
22
25
|
RollerShadeDevice,
|
|
23
|
-
Hub2Device,
|
|
24
|
-
MeterDevice,
|
|
25
|
-
WaterDetectorDevice,
|
|
26
26
|
SmartFanDevice,
|
|
27
27
|
StripLightDevice,
|
|
28
|
+
TemperatureSensorDevice,
|
|
29
|
+
VacuumDevice,
|
|
28
30
|
WalletFinderDevice,
|
|
31
|
+
WaterDetectorDevice,
|
|
29
32
|
WoSweeperDevice,
|
|
30
33
|
WoSweeperMiniDevice,
|
|
31
34
|
WoSweeperMiniProDevice,
|
|
32
35
|
} from './devices/genericDevice.js'
|
|
36
|
+
import { SwitchBotClient } from './switchbotClient.js'
|
|
33
37
|
|
|
34
38
|
export interface DeviceOptions {
|
|
35
39
|
id: string
|
|
@@ -39,52 +43,110 @@ export interface DeviceOptions {
|
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
const DEVICE_CLASS_MAP: Record<string, any> = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
|
|
46
|
+
// Primary device type keys (lowercase, simplified)
|
|
47
|
+
'bot': BotDevice,
|
|
48
|
+
'curtain': CurtainDevice,
|
|
49
|
+
'curtain3': Curtain3Device,
|
|
50
|
+
'fan': FanDevice,
|
|
51
|
+
'light': LightDevice,
|
|
52
|
+
'lightstrip': LightStripDevice,
|
|
53
|
+
'motion': MotionSensorDevice,
|
|
54
|
+
'contact': ContactSensorDevice,
|
|
55
|
+
'vacuum': VacuumDevice,
|
|
56
|
+
// Canonical, normalized device type keys (lowercase, mapped to device classes)
|
|
57
|
+
'video doorbell': GenericDevice,
|
|
58
|
+
'smart radiator thermostat': GenericDevice,
|
|
59
|
+
'woiosensor': GenericDevice,
|
|
60
|
+
'garage door opener': GenericDevice,
|
|
61
|
+
'air purifier table pm2.5': GenericDevice,
|
|
62
|
+
'air purifier voc': GenericDevice,
|
|
63
|
+
'air purifier table voc': GenericDevice,
|
|
64
|
+
'meterplus': MeterDevice,
|
|
65
|
+
'meterpro': MeterDevice,
|
|
66
|
+
'meterpro(co2)': MeterDevice,
|
|
67
|
+
'walletfinder': WalletFinderDevice,
|
|
68
|
+
'plug': PlugDevice,
|
|
69
|
+
'plug mini (eu)': PlugMiniDevice,
|
|
56
70
|
'plug mini (jp)': PlugMiniDevice,
|
|
57
71
|
'plug mini (us)': PlugMiniDevice,
|
|
72
|
+
'relay switch 1pm': RelaySwitch1PMDevice,
|
|
73
|
+
'relay switch 2pm': RelaySwitch1PMDevice,
|
|
74
|
+
'k10+ pro': WoSweeperDevice,
|
|
75
|
+
'robot vacuum cleaner k10+ pro combo': WoSweeperDevice,
|
|
76
|
+
'robot vacuum cleaner k11+': WoSweeperDevice,
|
|
77
|
+
'robot vacuum cleaner k20 plus pro': WoSweeperDevice,
|
|
78
|
+
'ai hub': GenericDevice,
|
|
79
|
+
'hub': GenericDevice,
|
|
80
|
+
'hub 2': Hub2Device,
|
|
81
|
+
'hub 3': GenericDevice,
|
|
82
|
+
'hub mini': GenericDevice,
|
|
83
|
+
'hub plus': GenericDevice,
|
|
84
|
+
'indoor cam': GenericDevice,
|
|
85
|
+
'pan/tilt cam': GenericDevice,
|
|
86
|
+
'pan/tilt cam 2k': GenericDevice,
|
|
87
|
+
'pan/tilt cam plus 2k': GenericDevice,
|
|
88
|
+
'pan/tilt cam plus 3k': GenericDevice,
|
|
89
|
+
'humidifier': HumidifierDevice, // Includes evaporative humidifier mapping
|
|
90
|
+
'roller shade': RollerShadeDevice,
|
|
91
|
+
'strip light 3': StripLightDevice,
|
|
92
|
+
'circulator fan': FanDevice,
|
|
93
|
+
'smart lock pro': LockDevice,
|
|
94
|
+
'lock lite': LockDevice,
|
|
95
|
+
'keypad': LockDevice,
|
|
96
|
+
'lock vision pro': LockDevice,
|
|
97
|
+
'floor lamp': LightDevice,
|
|
98
|
+
'rgbicww floor lamp': LightStripDevice,
|
|
99
|
+
'rgbicww strip light': LightStripDevice,
|
|
100
|
+
'home climate panel': GenericDevice, // Climate panel family
|
|
101
|
+
'lock': LockDevice,
|
|
102
|
+
'humidifier2': HumidifierDevice,
|
|
103
|
+
'temperature': TemperatureSensorDevice,
|
|
104
|
+
'relay switch 1': RelaySwitchDevice,
|
|
58
105
|
'blind tilt': BlindTiltDevice,
|
|
59
|
-
curtain3: Curtain3Device,
|
|
60
106
|
'worollershade': RollerShadeDevice,
|
|
61
107
|
'wo rollershade': RollerShadeDevice,
|
|
62
|
-
'roller shade': RollerShadeDevice,
|
|
63
108
|
'rollershade': RollerShadeDevice,
|
|
64
|
-
'
|
|
65
|
-
meter: MeterDevice,
|
|
66
|
-
'meterplus': MeterDevice,
|
|
109
|
+
'meter': MeterDevice,
|
|
67
110
|
'meter plus (jp)': MeterDevice,
|
|
68
|
-
'meterpro': MeterDevice,
|
|
69
|
-
'meterpro(co2)': MeterDevice,
|
|
70
111
|
'water detector': WaterDetectorDevice,
|
|
71
112
|
'smart fan': SmartFanDevice,
|
|
72
113
|
'strip light': StripLightDevice,
|
|
73
|
-
'walletfinder': WalletFinderDevice,
|
|
74
114
|
'wosweeper': WoSweeperDevice,
|
|
75
115
|
'wosweepermini': WoSweeperMiniDevice,
|
|
76
116
|
'wosweeperminipro': WoSweeperMiniProDevice,
|
|
77
117
|
'k10+': WoSweeperDevice,
|
|
78
|
-
'k10+ pro': WoSweeperDevice,
|
|
79
118
|
'k10+ pro (wosweeperminipro)': WoSweeperMiniProDevice,
|
|
119
|
+
'battery circulator fan': FanDevice,
|
|
120
|
+
'standing circulator fan': FanDevice,
|
|
121
|
+
'smart lock': LockDevice,
|
|
122
|
+
'smart lock ultra': LockDevice,
|
|
123
|
+
'keypad touch': LockDevice,
|
|
124
|
+
'keypad vision': LockDevice,
|
|
125
|
+
'keypad vision pro': LockDevice,
|
|
126
|
+
'color bulb': LightDevice,
|
|
127
|
+
'ceiling light': LightDevice,
|
|
128
|
+
'ceiling light pro': LightDevice,
|
|
129
|
+
'candle warmer lamp': LightDevice,
|
|
130
|
+
'rgbic neon rope light': LightStripDevice,
|
|
131
|
+
'rgbic neon wire rope light': LightStripDevice,
|
|
132
|
+
'robot vacuum cleaner s1': VacuumDevice,
|
|
133
|
+
'robot vacuum cleaner s1 plus': VacuumDevice,
|
|
134
|
+
'robot vacuum cleaner s10': VacuumDevice,
|
|
135
|
+
'robot vacuum cleaner s20': VacuumDevice,
|
|
80
136
|
}
|
|
81
137
|
|
|
82
138
|
function classForType(type: string) {
|
|
83
|
-
const
|
|
139
|
+
const rawKey = (type || '').toLowerCase()
|
|
140
|
+
const key = DEVICE_TYPE_NORMALIZATION_MAP[rawKey] ?? rawKey
|
|
84
141
|
return DEVICE_CLASS_MAP[key] ?? GenericDevice
|
|
85
142
|
}
|
|
86
143
|
|
|
87
|
-
export async function createDevice(opts: DeviceOptions, cfg: SwitchBotPluginConfig, useMatter: boolean) {
|
|
144
|
+
export async function createDevice(opts: DeviceOptions, cfg: SwitchBotPluginConfig, useMatter: boolean, log?: Logger) {
|
|
145
|
+
// Always pass the logger to both device opts and config
|
|
146
|
+
const logger = log || (cfg as any)?.logger || (cfg as any)?.log
|
|
147
|
+
if (opts && opts.name && logger && typeof logger.info === 'function') {
|
|
148
|
+
logger.info(`[Matter/Debug] createDevice: Passing opts for ${opts.name}:`, JSON.stringify(opts, null, 2))
|
|
149
|
+
}
|
|
88
150
|
// Reuse existing client when provided via config to avoid creating
|
|
89
151
|
// a new SwitchBotClient per device (which can be expensive).
|
|
90
152
|
let client: any = (cfg as any)?._client ?? null
|
|
@@ -92,12 +154,26 @@ export async function createDevice(opts: DeviceOptions, cfg: SwitchBotPluginConf
|
|
|
92
154
|
client = new SwitchBotClient(cfg)
|
|
93
155
|
await client.init()
|
|
94
156
|
}
|
|
95
|
-
|
|
96
157
|
// Pass client via config so devices can access it
|
|
97
158
|
const mergedCfg = { ...(cfg as any), _client: client }
|
|
98
|
-
|
|
159
|
+
// Always pass logger to mergedCfg
|
|
160
|
+
if (logger) {
|
|
161
|
+
mergedCfg.log = logger
|
|
162
|
+
}
|
|
163
|
+
// Pass encryptionKey and keyId to device opts if present
|
|
164
|
+
const deviceOpts = { ...opts }
|
|
165
|
+
if (opts.encryptionKey) {
|
|
166
|
+
deviceOpts.encryptionKey = opts.encryptionKey
|
|
167
|
+
}
|
|
168
|
+
if (opts.keyId) {
|
|
169
|
+
deviceOpts.keyId = opts.keyId
|
|
170
|
+
}
|
|
171
|
+
// Always pass logger to deviceOpts
|
|
172
|
+
if (logger) {
|
|
173
|
+
deviceOpts.log = logger
|
|
174
|
+
}
|
|
99
175
|
const DeviceCtor = classForType(opts.type)
|
|
100
|
-
const device = new DeviceCtor(
|
|
176
|
+
const device = new DeviceCtor(deviceOpts, mergedCfg)
|
|
101
177
|
await device.init()
|
|
102
178
|
|
|
103
179
|
// Attach a simple getState delegator to the client where appropriate
|
|
@@ -106,7 +182,9 @@ export async function createDevice(opts: DeviceOptions, cfg: SwitchBotPluginConf
|
|
|
106
182
|
try {
|
|
107
183
|
// Prefer client-backed getDevice when available
|
|
108
184
|
const dev = await client.getDevice(opts.id)
|
|
109
|
-
if (dev)
|
|
185
|
+
if (dev) {
|
|
186
|
+
return dev
|
|
187
|
+
}
|
|
110
188
|
} catch (e) {
|
|
111
189
|
// ignore and fallback to device implementation
|
|
112
190
|
}
|
|
@@ -116,7 +194,9 @@ export async function createDevice(opts: DeviceOptions, cfg: SwitchBotPluginConf
|
|
|
116
194
|
// Provide accessory factory based on platform selection
|
|
117
195
|
return {
|
|
118
196
|
instance: device,
|
|
119
|
-
createAccessory:
|
|
197
|
+
createAccessory: useMatter
|
|
198
|
+
? async (api: any) => await device.createMatterAccessory(api)
|
|
199
|
+
: (api: any) => device.createHAPAccessory(api),
|
|
120
200
|
protocol: useMatter ? 'matter' : 'hap',
|
|
121
201
|
}
|
|
122
202
|
}
|