@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.
Files changed (69) hide show
  1. package/.github/workflows/release.yml +1 -1
  2. package/CHANGELOG.md +2 -1
  3. package/config.schema.json +24 -0
  4. package/dist/device/blindtilt.js +15 -15
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.js +15 -15
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.js +15 -15
  9. package/dist/device/ceilinglight.js.map +1 -1
  10. package/dist/device/colorbulb.js +27 -27
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.js +11 -11
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.js +15 -15
  15. package/dist/device/curtain.js.map +1 -1
  16. package/dist/device/device.js +7 -7
  17. package/dist/device/device.js.map +1 -1
  18. package/dist/device/fan.js +15 -15
  19. package/dist/device/fan.js.map +1 -1
  20. package/dist/device/hub.js +11 -11
  21. package/dist/device/hub.js.map +1 -1
  22. package/dist/device/humidifier.js +15 -15
  23. package/dist/device/humidifier.js.map +1 -1
  24. package/dist/device/iosensor.js +11 -11
  25. package/dist/device/iosensor.js.map +1 -1
  26. package/dist/device/lightstrip.js +23 -23
  27. package/dist/device/lightstrip.js.map +1 -1
  28. package/dist/device/lock.js +16 -16
  29. package/dist/device/lock.js.map +1 -1
  30. package/dist/device/meter.js +11 -11
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.js +11 -11
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.js +11 -11
  35. package/dist/device/motion.js.map +1 -1
  36. package/dist/device/plug.js +15 -15
  37. package/dist/device/plug.js.map +1 -1
  38. package/dist/device/robotvacuumcleaner.js +15 -15
  39. package/dist/device/robotvacuumcleaner.js.map +1 -1
  40. package/dist/device/waterdetector.js +11 -11
  41. package/dist/device/waterdetector.js.map +1 -1
  42. package/dist/platform.d.ts.map +1 -1
  43. package/dist/platform.js +80 -76
  44. package/dist/platform.js.map +1 -1
  45. package/dist/settings.d.ts +3 -0
  46. package/dist/settings.d.ts.map +1 -1
  47. package/dist/settings.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/device/blindtilt.ts +15 -15
  50. package/src/device/bot.ts +15 -15
  51. package/src/device/ceilinglight.ts +15 -15
  52. package/src/device/colorbulb.ts +27 -27
  53. package/src/device/contact.ts +11 -11
  54. package/src/device/curtain.ts +15 -15
  55. package/src/device/device.ts +7 -7
  56. package/src/device/fan.ts +15 -15
  57. package/src/device/hub.ts +11 -11
  58. package/src/device/humidifier.ts +15 -15
  59. package/src/device/iosensor.ts +11 -11
  60. package/src/device/lightstrip.ts +23 -23
  61. package/src/device/lock.ts +16 -16
  62. package/src/device/meter.ts +11 -11
  63. package/src/device/meterplus.ts +11 -11
  64. package/src/device/motion.ts +11 -11
  65. package/src/device/plug.ts +15 -15
  66. package/src/device/robotvacuumcleaner.ts +15 -15
  67. package/src/device/waterdetector.ts +11 -11
  68. package/src/platform.ts +81 -77
  69. 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.switchBotAPI.on('log', (log) => {
138
- switch (log.level) {
139
- case LogLevel.SUCCESS:
140
- this.successLog(log.message)
141
- break
142
- case LogLevel.DEBUGSUCCESS:
143
- this.debugSuccessLog(log.message)
144
- break
145
- case LogLevel.WARN:
146
- this.warnLog(log.message)
147
- break
148
- case LogLevel.DEBUGWARN:
149
- this.debugWarnLog(log.message)
150
- break
151
- case LogLevel.ERROR:
152
- this.errorLog(log.message)
153
- break
154
- case LogLevel.DEBUGERROR:
155
- this.debugErrorLog(log.message)
156
- break
157
- case LogLevel.DEBUG:
158
- this.debugLog(log.message)
159
- break
160
- case LogLevel.INFO:
161
- default:
162
- this.infoLog(log.message)
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.switchBotBLE.on('log', (log) => {
270
- switch (log.level) {
271
- case LogLevel.SUCCESS:
272
- this.successLog(log.message)
273
- break
274
- case LogLevel.DEBUGSUCCESS:
275
- this.debugSuccessLog(log.message)
276
- break
277
- case LogLevel.WARN:
278
- this.warnLog(log.message)
279
- break
280
- case LogLevel.DEBUGWARN:
281
- this.debugWarnLog(log.message)
282
- break
283
- case LogLevel.ERROR:
284
- this.errorLog(log.message)
285
- break
286
- case LogLevel.DEBUGERROR:
287
- this.debugErrorLog(log.message)
288
- break
289
- case LogLevel.DEBUG:
290
- this.debugLog(log.message)
291
- break
292
- case LogLevel.INFO:
293
- default:
294
- this.infoLog(log.message)
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