@switchbot/homebridge-switchbot 5.0.0-beta.1 → 5.0.0-beta.3
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/dist/devices-matter/ColorLightAccessory.d.ts +3 -1
- package/dist/devices-matter/ColorLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ColorLightAccessory.js +35 -36
- package/dist/devices-matter/ColorLightAccessory.js.map +1 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts +3 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.js +32 -37
- package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +1 -1
- package/dist/devices-matter/ContactSensorAccessory.d.ts +3 -1
- package/dist/devices-matter/ContactSensorAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ContactSensorAccessory.js +16 -13
- package/dist/devices-matter/ContactSensorAccessory.js.map +1 -1
- package/dist/devices-matter/DimmableLightAccessory.d.ts +3 -1
- package/dist/devices-matter/DimmableLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/DimmableLightAccessory.js +24 -27
- package/dist/devices-matter/DimmableLightAccessory.js.map +1 -1
- package/dist/devices-matter/DoorLockAccessory.d.ts +3 -1
- package/dist/devices-matter/DoorLockAccessory.d.ts.map +1 -1
- package/dist/devices-matter/DoorLockAccessory.js +25 -22
- package/dist/devices-matter/DoorLockAccessory.js.map +1 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts +3 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.js +40 -41
- package/dist/devices-matter/ExtendedColorLightAccessory.js.map +1 -1
- package/dist/devices-matter/FanAccessory.d.ts +3 -1
- package/dist/devices-matter/FanAccessory.d.ts.map +1 -1
- package/dist/devices-matter/FanAccessory.js +31 -23
- package/dist/devices-matter/FanAccessory.js.map +1 -1
- package/dist/devices-matter/HumiditySensorAccessory.d.ts +3 -1
- package/dist/devices-matter/HumiditySensorAccessory.d.ts.map +1 -1
- package/dist/devices-matter/HumiditySensorAccessory.js +16 -15
- package/dist/devices-matter/HumiditySensorAccessory.js.map +1 -1
- package/dist/devices-matter/LeakSensorAccessory.d.ts +3 -1
- package/dist/devices-matter/LeakSensorAccessory.d.ts.map +1 -1
- package/dist/devices-matter/LeakSensorAccessory.js +16 -13
- package/dist/devices-matter/LeakSensorAccessory.js.map +1 -1
- package/dist/devices-matter/LightSensorAccessory.d.ts +3 -1
- package/dist/devices-matter/LightSensorAccessory.d.ts.map +1 -1
- package/dist/devices-matter/LightSensorAccessory.js +16 -15
- package/dist/devices-matter/LightSensorAccessory.js.map +1 -1
- package/dist/devices-matter/OccupancySensorAccessory.d.ts +3 -1
- package/dist/devices-matter/OccupancySensorAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OccupancySensorAccessory.js +17 -21
- package/dist/devices-matter/OccupancySensorAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffLightAccessory.d.ts +3 -1
- package/dist/devices-matter/OnOffLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffLightAccessory.js +22 -21
- package/dist/devices-matter/OnOffLightAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +3 -3
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +24 -27
- package/dist/devices-matter/OnOffOutletAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffSwitchAccessory.d.ts +3 -1
- package/dist/devices-matter/OnOffSwitchAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffSwitchAccessory.js +18 -19
- package/dist/devices-matter/OnOffSwitchAccessory.js.map +1 -1
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts +3 -1
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +1 -1
- package/dist/devices-matter/RoboticVacuumAccessory.js +77 -145
- package/dist/devices-matter/RoboticVacuumAccessory.js.map +1 -1
- package/dist/devices-matter/TemperatureSensorAccessory.d.ts +3 -1
- package/dist/devices-matter/TemperatureSensorAccessory.d.ts.map +1 -1
- package/dist/devices-matter/TemperatureSensorAccessory.js +18 -15
- package/dist/devices-matter/TemperatureSensorAccessory.js.map +1 -1
- package/dist/devices-matter/ThermostatAccessory.d.ts +3 -1
- package/dist/devices-matter/ThermostatAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ThermostatAccessory.js +37 -29
- package/dist/devices-matter/ThermostatAccessory.js.map +1 -1
- package/dist/devices-matter/VenetianBlindAccessory.d.ts +3 -1
- package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +1 -1
- package/dist/devices-matter/VenetianBlindAccessory.js +39 -40
- package/dist/devices-matter/VenetianBlindAccessory.js.map +1 -1
- package/dist/devices-matter/WindowBlindAccessory.d.ts +3 -1
- package/dist/devices-matter/WindowBlindAccessory.d.ts.map +1 -1
- package/dist/devices-matter/WindowBlindAccessory.js +36 -37
- package/dist/devices-matter/WindowBlindAccessory.js.map +1 -1
- package/dist/platform-matter.d.ts +15 -0
- package/dist/platform-matter.d.ts.map +1 -1
- package/dist/platform-matter.js +82 -1
- package/dist/platform-matter.js.map +1 -1
- package/docs/variables/default.html +1 -1
- package/package.json +1 -1
- package/src/devices-matter/ColorLightAccessory.ts +37 -40
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +35 -41
- package/src/devices-matter/ContactSensorAccessory.ts +18 -14
- package/src/devices-matter/DimmableLightAccessory.ts +26 -30
- package/src/devices-matter/DoorLockAccessory.ts +28 -24
- package/src/devices-matter/ExtendedColorLightAccessory.ts +43 -47
- package/src/devices-matter/FanAccessory.ts +33 -25
- package/src/devices-matter/HumiditySensorAccessory.ts +18 -16
- package/src/devices-matter/LeakSensorAccessory.ts +18 -14
- package/src/devices-matter/LightSensorAccessory.ts +18 -16
- package/src/devices-matter/OccupancySensorAccessory.ts +18 -22
- package/src/devices-matter/OnOffLightAccessory.ts +23 -23
- package/src/devices-matter/OnOffOutletAccessory.ts +25 -31
- package/src/devices-matter/OnOffSwitchAccessory.ts +20 -21
- package/src/devices-matter/RoboticVacuumAccessory.ts +79 -156
- package/src/devices-matter/TemperatureSensorAccessory.ts +20 -16
- package/src/devices-matter/ThermostatAccessory.ts +39 -34
- package/src/devices-matter/VenetianBlindAccessory.ts +41 -44
- package/src/devices-matter/WindowBlindAccessory.ts +37 -39
- package/src/platform-matter.ts +92 -1
|
@@ -8,50 +8,48 @@ import type { API, Logger, MatterRequests } from 'homebridge'
|
|
|
8
8
|
import { BaseMatterAccessory } from './BaseMatterAccessory.js'
|
|
9
9
|
|
|
10
10
|
export class WindowBlindAccessory extends BaseMatterAccessory {
|
|
11
|
-
constructor(api: API, log: Logger) {
|
|
12
|
-
const serialNumber = 'BLIND-001'
|
|
11
|
+
constructor(api: API, log: Logger, opts?: Partial<import('./BaseMatterAccessory').BaseMatterAccessoryConfig & { deviceId?: string }>) {
|
|
12
|
+
const serialNumber = opts?.serialNumber ?? 'BLIND-001'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
operationalStatus: {
|
|
29
|
-
global: 0,
|
|
30
|
-
lift: 0,
|
|
31
|
-
tilt: 0,
|
|
32
|
-
},
|
|
33
|
-
endProductType: 0,
|
|
34
|
-
configStatus: {
|
|
35
|
-
operational: true,
|
|
36
|
-
onlineReserved: true,
|
|
37
|
-
liftMovementReversed: false,
|
|
38
|
-
liftPositionAware: true,
|
|
39
|
-
tiltPositionAware: false,
|
|
40
|
-
liftEncoderControlled: true,
|
|
41
|
-
tiltEncoderControlled: false,
|
|
42
|
-
},
|
|
14
|
+
const clusters = opts?.clusters ?? {
|
|
15
|
+
windowCovering: {
|
|
16
|
+
targetPositionLiftPercent100ths: 5000,
|
|
17
|
+
currentPositionLiftPercent100ths: 5000,
|
|
18
|
+
operationalStatus: { global: 0, lift: 0, tilt: 0 },
|
|
19
|
+
endProductType: 0,
|
|
20
|
+
configStatus: {
|
|
21
|
+
operational: true,
|
|
22
|
+
onlineReserved: true,
|
|
23
|
+
liftMovementReversed: false,
|
|
24
|
+
liftPositionAware: true,
|
|
25
|
+
tiltPositionAware: false,
|
|
26
|
+
liftEncoderControlled: true,
|
|
27
|
+
tiltEncoderControlled: false,
|
|
43
28
|
},
|
|
44
29
|
},
|
|
30
|
+
}
|
|
45
31
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
stopMotion: async () => this.handleStop(),
|
|
53
|
-
},
|
|
32
|
+
const handlers = opts?.handlers ?? {
|
|
33
|
+
windowCovering: {
|
|
34
|
+
goToLiftPercentage: async (request: MatterRequests.GoToLiftPercentage) => this.handleGoToLift(request),
|
|
35
|
+
upOrOpen: async () => this.handleUpOrOpen(),
|
|
36
|
+
downOrClose: async () => this.handleDownOrClose(),
|
|
37
|
+
stopMotion: async () => this.handleStop(),
|
|
54
38
|
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
super(api, log, {
|
|
42
|
+
uuid: opts?.uuid ?? api.matter.uuid.generate(serialNumber),
|
|
43
|
+
displayName: opts?.displayName ?? 'Window Blind',
|
|
44
|
+
deviceType: api.matter.deviceTypes.WindowCovering,
|
|
45
|
+
serialNumber,
|
|
46
|
+
manufacturer: opts?.manufacturer ?? 'Homebridge Matter',
|
|
47
|
+
model: opts?.model ?? 'HB-MATTER-BLIND-WINDOW',
|
|
48
|
+
firmwareRevision: opts?.firmwareRevision ?? '2.0.0',
|
|
49
|
+
hardwareRevision: opts?.hardwareRevision ?? '1.0.0',
|
|
50
|
+
clusters,
|
|
51
|
+
handlers,
|
|
52
|
+
context: { deviceId: opts?.deviceId, ...(opts?.context ?? {}) },
|
|
55
53
|
})
|
|
56
54
|
|
|
57
55
|
this.logInfo('initialized.')
|
package/src/platform-matter.ts
CHANGED
|
@@ -5,9 +5,12 @@ import type {
|
|
|
5
5
|
MatterAccessory,
|
|
6
6
|
SerializedMatterAccessory,
|
|
7
7
|
} from 'homebridge'
|
|
8
|
+
import type { bodyChange, device } from 'node-switchbot'
|
|
8
9
|
|
|
9
10
|
import type { SwitchBotPlatformConfig } from './settings.js'
|
|
10
11
|
|
|
12
|
+
import { SwitchBotBLE, SwitchBotOpenAPI } from 'node-switchbot'
|
|
13
|
+
|
|
11
14
|
import {
|
|
12
15
|
ColorLightAccessory,
|
|
13
16
|
ColorTemperatureLightAccessory,
|
|
@@ -32,7 +35,7 @@ import {
|
|
|
32
35
|
WindowBlindAccessory,
|
|
33
36
|
} from './devices-matter/index.js'
|
|
34
37
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
35
|
-
import { cleanDeviceConfig } from './utils.js'
|
|
38
|
+
import { cleanDeviceConfig, sleep } from './utils.js'
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
41
|
* MatterPlatform
|
|
@@ -47,6 +50,11 @@ export class SwitchBotMatterPlatform implements DynamicPlatformPlugin {
|
|
|
47
50
|
|
|
48
51
|
// Track restored Matter cached accessories
|
|
49
52
|
public readonly matterAccessories: Map<string, SerializedMatterAccessory> = new Map()
|
|
53
|
+
// node-switchbot clients
|
|
54
|
+
private switchBotAPI?: SwitchBotOpenAPI
|
|
55
|
+
private switchBotBLE?: SwitchBotBLE
|
|
56
|
+
// discovered devices cache
|
|
57
|
+
private discoveredDevices: device[] = []
|
|
50
58
|
|
|
51
59
|
constructor(
|
|
52
60
|
public readonly log: Logging,
|
|
@@ -87,10 +95,93 @@ export class SwitchBotMatterPlatform implements DynamicPlatformPlugin {
|
|
|
87
95
|
// Register Matter accessories when Homebridge has finished launching
|
|
88
96
|
this.api.on('didFinishLaunching', () => {
|
|
89
97
|
this.log.debug('Executed didFinishLaunching callback')
|
|
98
|
+
// Initialize SwitchBot API clients
|
|
99
|
+
try {
|
|
100
|
+
if (this.config.credentials?.token && this.config.credentials?.secret) {
|
|
101
|
+
this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials.token, this.config.credentials.secret, this.config.options?.hostname)
|
|
102
|
+
// forward basic logs
|
|
103
|
+
if (!this.config.options?.disableLogsforOpenAPI && this.switchBotAPI?.on) {
|
|
104
|
+
this.switchBotAPI.on('log', (l: any) => this.log.debug('[SwitchBot OpenAPI]', l.message))
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
this.log.debug('SwitchBot OpenAPI credentials not provided; cloud devices will be skipped')
|
|
108
|
+
}
|
|
109
|
+
} catch (e: any) {
|
|
110
|
+
this.log.error('Failed to initialize SwitchBot OpenAPI:', e?.message ?? e)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
this.switchBotBLE = new SwitchBotBLE()
|
|
115
|
+
if (!this.config.options?.disableLogsforBLE && this.switchBotBLE?.on) {
|
|
116
|
+
this.switchBotBLE.on('log', (l: any) => this.log.debug('[SwitchBot BLE]', l.message))
|
|
117
|
+
}
|
|
118
|
+
} catch (e: any) {
|
|
119
|
+
this.log.error('Failed to initialize SwitchBot BLE client:', e?.message ?? e)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// perform device discovery from SwitchBot OpenAPI (if configured)
|
|
123
|
+
void this.discoverDevices()
|
|
124
|
+
|
|
90
125
|
this.registerMatterAccessories()
|
|
91
126
|
})
|
|
92
127
|
}
|
|
93
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Discover devices via SwitchBot OpenAPI and cache them for later use
|
|
131
|
+
*/
|
|
132
|
+
private async discoverDevices(): Promise<void> {
|
|
133
|
+
if (!this.switchBotAPI) {
|
|
134
|
+
this.log.debug('SwitchBot OpenAPI not configured; skipping discovery')
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const { response, statusCode } = await this.switchBotAPI.getDevices()
|
|
140
|
+
this.log.debug(`SwitchBot getDevices response status: ${statusCode}`)
|
|
141
|
+
if (statusCode === 100 || statusCode === 200) {
|
|
142
|
+
const deviceList = Array.isArray(response?.body?.deviceList) ? response.body.deviceList : []
|
|
143
|
+
this.discoveredDevices = deviceList
|
|
144
|
+
this.log.info(`Discovered ${deviceList.length} SwitchBot device(s) from OpenAPI`)
|
|
145
|
+
for (const d of deviceList) {
|
|
146
|
+
this.log.debug(` - ${d.deviceName} (${d.deviceType}) id=${d.deviceId}`)
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
this.log.warn(`SwitchBot getDevices returned status ${statusCode}`)
|
|
150
|
+
}
|
|
151
|
+
} catch (e: any) {
|
|
152
|
+
this.log.error('Failed to discover SwitchBot devices:', e?.message ?? e)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Retry wrapper for control commands using SwitchBot OpenAPI
|
|
158
|
+
*/
|
|
159
|
+
async retryCommand(deviceObj: device, bodyChange: bodyChange, maxRetries = 1, delayBetweenRetries = 1000): Promise<{ response: any, statusCode: number }> {
|
|
160
|
+
let retryCount = 0
|
|
161
|
+
while (retryCount < maxRetries) {
|
|
162
|
+
try {
|
|
163
|
+
if (!this.switchBotAPI) {
|
|
164
|
+
throw new Error('SwitchBot OpenAPI not initialized')
|
|
165
|
+
}
|
|
166
|
+
const { response, statusCode } = await this.switchBotAPI.controlDevice(
|
|
167
|
+
deviceObj.deviceId,
|
|
168
|
+
bodyChange.command,
|
|
169
|
+
bodyChange.parameter,
|
|
170
|
+
bodyChange.commandType as import('node-switchbot').commandType | undefined,
|
|
171
|
+
this.config.credentials?.token,
|
|
172
|
+
this.config.credentials?.secret,
|
|
173
|
+
)
|
|
174
|
+
return { response, statusCode }
|
|
175
|
+
} catch (e: any) {
|
|
176
|
+
this.log.debug(`retryCommand error: ${e?.message ?? e}`)
|
|
177
|
+
}
|
|
178
|
+
retryCount++
|
|
179
|
+
|
|
180
|
+
await sleep(delayBetweenRetries)
|
|
181
|
+
}
|
|
182
|
+
return { response: {}, statusCode: 500 }
|
|
183
|
+
}
|
|
184
|
+
|
|
94
185
|
/**
|
|
95
186
|
* Required for DynamicPlatformPlugin
|
|
96
187
|
* Called when homebridge restores cached accessories from disk at startup
|