@switchbot/homebridge-switchbot 3.8.3-beta.30 → 3.8.3-beta.31
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/workflows/release.yml +1 -1
- package/CHANGELOG.md +2 -1
- package/config.schema.json +24 -0
- package/dist/device/blindtilt.js +15 -15
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +15 -15
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +15 -15
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +27 -27
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +11 -11
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +15 -15
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.js +7 -7
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +15 -15
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +11 -11
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +15 -15
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +11 -11
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +23 -23
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +16 -16
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +11 -11
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.js +11 -11
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +15 -15
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +15 -15
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +11 -11
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +80 -76
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +15 -15
- package/src/device/bot.ts +15 -15
- package/src/device/ceilinglight.ts +15 -15
- package/src/device/colorbulb.ts +27 -27
- package/src/device/contact.ts +11 -11
- package/src/device/curtain.ts +15 -15
- package/src/device/device.ts +7 -7
- package/src/device/fan.ts +15 -15
- package/src/device/hub.ts +11 -11
- package/src/device/humidifier.ts +15 -15
- package/src/device/iosensor.ts +11 -11
- package/src/device/lightstrip.ts +23 -23
- package/src/device/lock.ts +16 -16
- package/src/device/meter.ts +11 -11
- package/src/device/meterplus.ts +11 -11
- package/src/device/motion.ts +11 -11
- package/src/device/plug.ts +15 -15
- package/src/device/robotvacuumcleaner.ts +15 -15
- package/src/device/waterdetector.ts +11 -11
- package/src/platform.ts +81 -77
- package/src/settings.ts +3 -0
package/src/platform.ts
CHANGED
|
@@ -126,42 +126,44 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
126
126
|
this.verifyConfig()
|
|
127
127
|
this.debugLog('Config OK')
|
|
128
128
|
} catch (e: any) {
|
|
129
|
-
this.errorLog(`Verify Config, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
130
|
-
this.debugErrorLog(`Verify Config, Error: ${e}`)
|
|
129
|
+
this.errorLog(`Verify Config, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
130
|
+
this.debugErrorLog(`Verify Config, Error: ${e.message ?? e}`)
|
|
131
131
|
return
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// SwitchBot OpenAPI
|
|
135
135
|
this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials?.token, this.config.credentials?.secret)
|
|
136
136
|
// Listen for log events
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
137
|
+
if (!this.config.options?.disableLogsforOpenAPI) {
|
|
138
|
+
this.switchBotAPI.on('log', (log) => {
|
|
139
|
+
switch (log.level) {
|
|
140
|
+
case LogLevel.SUCCESS:
|
|
141
|
+
this.successLog(log.message)
|
|
142
|
+
break
|
|
143
|
+
case LogLevel.DEBUGSUCCESS:
|
|
144
|
+
this.debugSuccessLog(log.message)
|
|
145
|
+
break
|
|
146
|
+
case LogLevel.WARN:
|
|
147
|
+
this.warnLog(log.message)
|
|
148
|
+
break
|
|
149
|
+
case LogLevel.DEBUGWARN:
|
|
150
|
+
this.debugWarnLog(log.message)
|
|
151
|
+
break
|
|
152
|
+
case LogLevel.ERROR:
|
|
153
|
+
this.errorLog(log.message)
|
|
154
|
+
break
|
|
155
|
+
case LogLevel.DEBUGERROR:
|
|
156
|
+
this.debugErrorLog(log.message)
|
|
157
|
+
break
|
|
158
|
+
case LogLevel.DEBUG:
|
|
159
|
+
this.debugLog(log.message)
|
|
160
|
+
break
|
|
161
|
+
case LogLevel.INFO:
|
|
162
|
+
default:
|
|
163
|
+
this.infoLog(log.message)
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
}
|
|
165
167
|
// import fakegato-history module and EVE characteristics
|
|
166
168
|
this.fakegatoAPI = fakegato(api)
|
|
167
169
|
this.eve = new EveHomeKitTypes(api)
|
|
@@ -182,25 +184,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
182
184
|
await this.discoverDevices()
|
|
183
185
|
}
|
|
184
186
|
} catch (e: any) {
|
|
185
|
-
await this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
186
|
-
await this.debugErrorLog(`Failed to Discover, Error: ${e}`)
|
|
187
|
+
await this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
188
|
+
await this.debugErrorLog(`Failed to Discover, Error: ${e.message ?? e}`)
|
|
187
189
|
}
|
|
188
190
|
})
|
|
189
191
|
|
|
190
192
|
try {
|
|
191
193
|
this.setupMqtt()
|
|
192
194
|
} catch (e: any) {
|
|
193
|
-
this.errorLog(`Setup MQTT, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
195
|
+
this.errorLog(`Setup MQTT, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
194
196
|
}
|
|
195
197
|
try {
|
|
196
198
|
this.setupwebhook()
|
|
197
199
|
} catch (e: any) {
|
|
198
|
-
this.errorLog(`Setup Webhook, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
200
|
+
this.errorLog(`Setup Webhook, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
199
201
|
}
|
|
200
202
|
try {
|
|
201
203
|
this.setupBlE()
|
|
202
204
|
} catch (e: any) {
|
|
203
|
-
this.errorLog(`Setup Platform BLE, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
205
|
+
this.errorLog(`Setup Platform BLE, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
|
|
@@ -211,7 +213,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
211
213
|
this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {})
|
|
212
214
|
await this.debugLog('MQTT connection has been established successfully.')
|
|
213
215
|
this.mqttClient.on('error', async (e: Error) => {
|
|
214
|
-
await this.errorLog(`Failed to publish MQTT messages. ${e}`)
|
|
216
|
+
await this.errorLog(`Failed to publish MQTT messages. ${e.message ?? e}`)
|
|
215
217
|
})
|
|
216
218
|
if (!this.config.options?.webhookURL) {
|
|
217
219
|
// receive webhook events via MQTT
|
|
@@ -223,13 +225,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
223
225
|
const context = JSON.parse(message.toString())
|
|
224
226
|
this.webhookEventHandler[context.deviceMac]?.(context)
|
|
225
227
|
} catch (e: any) {
|
|
226
|
-
await this.errorLog(`Failed to handle webhook event. Error:${e}`)
|
|
228
|
+
await this.errorLog(`Failed to handle webhook event. Error:${e.message ?? e}`)
|
|
227
229
|
}
|
|
228
230
|
})
|
|
229
231
|
}
|
|
230
|
-
} catch (e) {
|
|
232
|
+
} catch (e: any) {
|
|
231
233
|
this.mqttClient = null
|
|
232
|
-
await this.errorLog(`Failed to establish MQTT connection. ${e}`)
|
|
234
|
+
await this.errorLog(`Failed to establish MQTT connection. ${e.message ?? e}`)
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
}
|
|
@@ -250,14 +252,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
250
252
|
this.webhookEventHandler[body.context.deviceMac]?.(body.context)
|
|
251
253
|
})
|
|
252
254
|
} catch (e: any) {
|
|
253
|
-
await this.errorLog(`Failed to setup webhook. Error:${e.message}`)
|
|
255
|
+
await this.errorLog(`Failed to setup webhook. Error:${e.message ?? e}`)
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
this.api.on('shutdown', async () => {
|
|
257
259
|
try {
|
|
258
260
|
this.switchBotAPI.deleteWebhook(url)
|
|
259
261
|
} catch (e: any) {
|
|
260
|
-
await this.errorLog(`Failed to delete webhook. Error:${e.message}`)
|
|
262
|
+
await this.errorLog(`Failed to delete webhook. Error:${e.message ?? e}`)
|
|
261
263
|
}
|
|
262
264
|
})
|
|
263
265
|
}
|
|
@@ -266,38 +268,40 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
266
268
|
async setupBlE() {
|
|
267
269
|
this.switchBotBLE = new SwitchBotBLE()
|
|
268
270
|
// Listen for log events
|
|
269
|
-
this.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
271
|
+
if (!this.config.options?.disableLogsforBLE) {
|
|
272
|
+
this.switchBotBLE.on('log', (log) => {
|
|
273
|
+
switch (log.level) {
|
|
274
|
+
case LogLevel.SUCCESS:
|
|
275
|
+
this.successLog(log.message)
|
|
276
|
+
break
|
|
277
|
+
case LogLevel.DEBUGSUCCESS:
|
|
278
|
+
this.debugSuccessLog(log.message)
|
|
279
|
+
break
|
|
280
|
+
case LogLevel.WARN:
|
|
281
|
+
this.warnLog(log.message)
|
|
282
|
+
break
|
|
283
|
+
case LogLevel.DEBUGWARN:
|
|
284
|
+
this.debugWarnLog(log.message)
|
|
285
|
+
break
|
|
286
|
+
case LogLevel.ERROR:
|
|
287
|
+
this.errorLog(log.message)
|
|
288
|
+
break
|
|
289
|
+
case LogLevel.DEBUGERROR:
|
|
290
|
+
this.debugErrorLog(log.message)
|
|
291
|
+
break
|
|
292
|
+
case LogLevel.DEBUG:
|
|
293
|
+
this.debugLog(log.message)
|
|
294
|
+
break
|
|
295
|
+
case LogLevel.INFO:
|
|
296
|
+
default:
|
|
297
|
+
this.infoLog(log.message)
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
}
|
|
297
301
|
if (this.config.options?.BLE) {
|
|
298
302
|
await this.debugLog('setupBLE')
|
|
299
303
|
if (this.switchBotBLE === undefined) {
|
|
300
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${this.switchBotBLE}`)
|
|
304
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(this.switchBotBLE)}`)
|
|
301
305
|
} else {
|
|
302
306
|
// Start to monitor advertisement packets
|
|
303
307
|
(async () => {
|
|
@@ -306,24 +310,24 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
306
310
|
try {
|
|
307
311
|
await this.switchBotBLE.startScan()
|
|
308
312
|
} catch (e: any) {
|
|
309
|
-
await this.errorLog(`Failed to start BLE scanning. Error:${e}`)
|
|
313
|
+
await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
|
|
310
314
|
}
|
|
311
315
|
// Set an event handler to monitor advertisement packets
|
|
312
316
|
this.switchBotBLE.onadvertisement = async (ad: any) => {
|
|
313
317
|
try {
|
|
314
318
|
this.bleEventHandler[ad.address]?.(ad.serviceData)
|
|
315
319
|
} catch (e: any) {
|
|
316
|
-
await this.errorLog(`Failed to handle BLE event. Error:${e}`)
|
|
320
|
+
await this.errorLog(`Failed to handle BLE event. Error:${e.message ?? e}`)
|
|
317
321
|
}
|
|
318
322
|
}
|
|
319
323
|
})()
|
|
320
324
|
|
|
321
325
|
this.api.on('shutdown', async () => {
|
|
322
326
|
try {
|
|
323
|
-
this.switchBotBLE.stopScan()
|
|
327
|
+
// this.switchBotBLE.stopScan()
|
|
324
328
|
await this.infoLog('Stopped BLE scanning to close listening.')
|
|
325
329
|
} catch (e: any) {
|
|
326
|
-
await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`)
|
|
330
|
+
await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message ?? e}`)
|
|
327
331
|
}
|
|
328
332
|
})
|
|
329
333
|
}
|
|
@@ -493,7 +497,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
493
497
|
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4))
|
|
494
498
|
await this.verifyConfig()
|
|
495
499
|
} catch (e: any) {
|
|
496
|
-
await this.errorLog(`Update Token: ${e}`)
|
|
500
|
+
await this.errorLog(`Update Token: ${e.message ?? e}`)
|
|
497
501
|
}
|
|
498
502
|
}
|
|
499
503
|
|
|
@@ -525,7 +529,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
525
529
|
} catch (e: any) {
|
|
526
530
|
retryCount++
|
|
527
531
|
await this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`)
|
|
528
|
-
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`)
|
|
532
|
+
await this.debugErrorLog(`Failed to Discover Devices, Error: ${e.message ?? e}`)
|
|
529
533
|
}
|
|
530
534
|
}
|
|
531
535
|
}
|
|
@@ -2608,7 +2612,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2608
2612
|
await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${this.switchBotBLE}`)
|
|
2609
2613
|
return this.switchBotBLE
|
|
2610
2614
|
} catch (e: any) {
|
|
2611
|
-
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e}`)
|
|
2615
|
+
await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e.message ?? e}`)
|
|
2612
2616
|
return false
|
|
2613
2617
|
}
|
|
2614
2618
|
}
|
package/src/settings.ts
CHANGED
|
@@ -64,6 +64,9 @@ export interface options {
|
|
|
64
64
|
mqttOptions?: IClientOptions
|
|
65
65
|
mqttPubOptions?: IClientOptions
|
|
66
66
|
BLE?: boolean
|
|
67
|
+
discoverBLE?: boolean
|
|
68
|
+
disableLogsforBLE?: boolean
|
|
69
|
+
disableLogsforOpenAPI?: boolean
|
|
67
70
|
webhookURL?: string
|
|
68
71
|
maxRetries?: number
|
|
69
72
|
delayBetweenRetries?: number
|