@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/dist/platform.js CHANGED
@@ -91,41 +91,43 @@ export class SwitchBotPlatform {
91
91
  this.debugLog('Config OK');
92
92
  }
93
93
  catch (e) {
94
- this.errorLog(`Verify Config, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
95
- this.debugErrorLog(`Verify Config, Error: ${e}`);
94
+ this.errorLog(`Verify Config, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
95
+ this.debugErrorLog(`Verify Config, Error: ${e.message ?? e}`);
96
96
  return;
97
97
  }
98
98
  // SwitchBot OpenAPI
99
99
  this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials?.token, this.config.credentials?.secret);
100
100
  // Listen for log events
101
- this.switchBotAPI.on('log', (log) => {
102
- switch (log.level) {
103
- case LogLevel.SUCCESS:
104
- this.successLog(log.message);
105
- break;
106
- case LogLevel.DEBUGSUCCESS:
107
- this.debugSuccessLog(log.message);
108
- break;
109
- case LogLevel.WARN:
110
- this.warnLog(log.message);
111
- break;
112
- case LogLevel.DEBUGWARN:
113
- this.debugWarnLog(log.message);
114
- break;
115
- case LogLevel.ERROR:
116
- this.errorLog(log.message);
117
- break;
118
- case LogLevel.DEBUGERROR:
119
- this.debugErrorLog(log.message);
120
- break;
121
- case LogLevel.DEBUG:
122
- this.debugLog(log.message);
123
- break;
124
- case LogLevel.INFO:
125
- default:
126
- this.infoLog(log.message);
127
- }
128
- });
101
+ if (!this.config.options?.disableLogsforOpenAPI) {
102
+ this.switchBotAPI.on('log', (log) => {
103
+ switch (log.level) {
104
+ case LogLevel.SUCCESS:
105
+ this.successLog(log.message);
106
+ break;
107
+ case LogLevel.DEBUGSUCCESS:
108
+ this.debugSuccessLog(log.message);
109
+ break;
110
+ case LogLevel.WARN:
111
+ this.warnLog(log.message);
112
+ break;
113
+ case LogLevel.DEBUGWARN:
114
+ this.debugWarnLog(log.message);
115
+ break;
116
+ case LogLevel.ERROR:
117
+ this.errorLog(log.message);
118
+ break;
119
+ case LogLevel.DEBUGERROR:
120
+ this.debugErrorLog(log.message);
121
+ break;
122
+ case LogLevel.DEBUG:
123
+ this.debugLog(log.message);
124
+ break;
125
+ case LogLevel.INFO:
126
+ default:
127
+ this.infoLog(log.message);
128
+ }
129
+ });
130
+ }
129
131
  // import fakegato-history module and EVE characteristics
130
132
  this.fakegatoAPI = fakegato(api);
131
133
  this.eve = new EveHomeKitTypes(api);
@@ -148,27 +150,27 @@ export class SwitchBotPlatform {
148
150
  }
149
151
  }
150
152
  catch (e) {
151
- await this.errorLog(`Failed to Discover, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
152
- await this.debugErrorLog(`Failed to Discover, Error: ${e}`);
153
+ await this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
154
+ await this.debugErrorLog(`Failed to Discover, Error: ${e.message ?? e}`);
153
155
  }
154
156
  });
155
157
  try {
156
158
  this.setupMqtt();
157
159
  }
158
160
  catch (e) {
159
- this.errorLog(`Setup MQTT, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
161
+ this.errorLog(`Setup MQTT, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
160
162
  }
161
163
  try {
162
164
  this.setupwebhook();
163
165
  }
164
166
  catch (e) {
165
- this.errorLog(`Setup Webhook, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
167
+ this.errorLog(`Setup Webhook, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
166
168
  }
167
169
  try {
168
170
  this.setupBlE();
169
171
  }
170
172
  catch (e) {
171
- this.errorLog(`Setup Platform BLE, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
173
+ this.errorLog(`Setup Platform BLE, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
172
174
  }
173
175
  }
174
176
  async setupMqtt() {
@@ -178,7 +180,7 @@ export class SwitchBotPlatform {
178
180
  this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
179
181
  await this.debugLog('MQTT connection has been established successfully.');
180
182
  this.mqttClient.on('error', async (e) => {
181
- await this.errorLog(`Failed to publish MQTT messages. ${e}`);
183
+ await this.errorLog(`Failed to publish MQTT messages. ${e.message ?? e}`);
182
184
  });
183
185
  if (!this.config.options?.webhookURL) {
184
186
  // receive webhook events via MQTT
@@ -191,14 +193,14 @@ export class SwitchBotPlatform {
191
193
  this.webhookEventHandler[context.deviceMac]?.(context);
192
194
  }
193
195
  catch (e) {
194
- await this.errorLog(`Failed to handle webhook event. Error:${e}`);
196
+ await this.errorLog(`Failed to handle webhook event. Error:${e.message ?? e}`);
195
197
  }
196
198
  });
197
199
  }
198
200
  }
199
201
  catch (e) {
200
202
  this.mqttClient = null;
201
- await this.errorLog(`Failed to establish MQTT connection. ${e}`);
203
+ await this.errorLog(`Failed to establish MQTT connection. ${e.message ?? e}`);
202
204
  }
203
205
  }
204
206
  }
@@ -219,14 +221,14 @@ export class SwitchBotPlatform {
219
221
  });
220
222
  }
221
223
  catch (e) {
222
- await this.errorLog(`Failed to setup webhook. Error:${e.message}`);
224
+ await this.errorLog(`Failed to setup webhook. Error:${e.message ?? e}`);
223
225
  }
224
226
  this.api.on('shutdown', async () => {
225
227
  try {
226
228
  this.switchBotAPI.deleteWebhook(url);
227
229
  }
228
230
  catch (e) {
229
- await this.errorLog(`Failed to delete webhook. Error:${e.message}`);
231
+ await this.errorLog(`Failed to delete webhook. Error:${e.message ?? e}`);
230
232
  }
231
233
  });
232
234
  }
@@ -234,38 +236,40 @@ export class SwitchBotPlatform {
234
236
  async setupBlE() {
235
237
  this.switchBotBLE = new SwitchBotBLE();
236
238
  // Listen for log events
237
- this.switchBotBLE.on('log', (log) => {
238
- switch (log.level) {
239
- case LogLevel.SUCCESS:
240
- this.successLog(log.message);
241
- break;
242
- case LogLevel.DEBUGSUCCESS:
243
- this.debugSuccessLog(log.message);
244
- break;
245
- case LogLevel.WARN:
246
- this.warnLog(log.message);
247
- break;
248
- case LogLevel.DEBUGWARN:
249
- this.debugWarnLog(log.message);
250
- break;
251
- case LogLevel.ERROR:
252
- this.errorLog(log.message);
253
- break;
254
- case LogLevel.DEBUGERROR:
255
- this.debugErrorLog(log.message);
256
- break;
257
- case LogLevel.DEBUG:
258
- this.debugLog(log.message);
259
- break;
260
- case LogLevel.INFO:
261
- default:
262
- this.infoLog(log.message);
263
- }
264
- });
239
+ if (!this.config.options?.disableLogsforBLE) {
240
+ this.switchBotBLE.on('log', (log) => {
241
+ switch (log.level) {
242
+ case LogLevel.SUCCESS:
243
+ this.successLog(log.message);
244
+ break;
245
+ case LogLevel.DEBUGSUCCESS:
246
+ this.debugSuccessLog(log.message);
247
+ break;
248
+ case LogLevel.WARN:
249
+ this.warnLog(log.message);
250
+ break;
251
+ case LogLevel.DEBUGWARN:
252
+ this.debugWarnLog(log.message);
253
+ break;
254
+ case LogLevel.ERROR:
255
+ this.errorLog(log.message);
256
+ break;
257
+ case LogLevel.DEBUGERROR:
258
+ this.debugErrorLog(log.message);
259
+ break;
260
+ case LogLevel.DEBUG:
261
+ this.debugLog(log.message);
262
+ break;
263
+ case LogLevel.INFO:
264
+ default:
265
+ this.infoLog(log.message);
266
+ }
267
+ });
268
+ }
265
269
  if (this.config.options?.BLE) {
266
270
  await this.debugLog('setupBLE');
267
271
  if (this.switchBotBLE === undefined) {
268
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${this.switchBotBLE}`);
272
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(this.switchBotBLE)}`);
269
273
  }
270
274
  else {
271
275
  // Start to monitor advertisement packets
@@ -276,7 +280,7 @@ export class SwitchBotPlatform {
276
280
  await this.switchBotBLE.startScan();
277
281
  }
278
282
  catch (e) {
279
- await this.errorLog(`Failed to start BLE scanning. Error:${e}`);
283
+ await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`);
280
284
  }
281
285
  // Set an event handler to monitor advertisement packets
282
286
  this.switchBotBLE.onadvertisement = async (ad) => {
@@ -284,17 +288,17 @@ export class SwitchBotPlatform {
284
288
  this.bleEventHandler[ad.address]?.(ad.serviceData);
285
289
  }
286
290
  catch (e) {
287
- await this.errorLog(`Failed to handle BLE event. Error:${e}`);
291
+ await this.errorLog(`Failed to handle BLE event. Error:${e.message ?? e}`);
288
292
  }
289
293
  };
290
294
  })();
291
295
  this.api.on('shutdown', async () => {
292
296
  try {
293
- this.switchBotBLE.stopScan();
297
+ // this.switchBotBLE.stopScan()
294
298
  await this.infoLog('Stopped BLE scanning to close listening.');
295
299
  }
296
300
  catch (e) {
297
- await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message}`);
301
+ await this.errorLog(`Failed to stop Platform BLE scanning. Error:${e.message ?? e}`);
298
302
  }
299
303
  });
300
304
  }
@@ -449,7 +453,7 @@ export class SwitchBotPlatform {
449
453
  await this.verifyConfig();
450
454
  }
451
455
  catch (e) {
452
- await this.errorLog(`Update Token: ${e}`);
456
+ await this.errorLog(`Update Token: ${e.message ?? e}`);
453
457
  }
454
458
  }
455
459
  async discoverDevices() {
@@ -479,7 +483,7 @@ export class SwitchBotPlatform {
479
483
  catch (e) {
480
484
  retryCount++;
481
485
  await this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
482
- await this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
486
+ await this.debugErrorLog(`Failed to Discover Devices, Error: ${e.message ?? e}`);
483
487
  }
484
488
  }
485
489
  }
@@ -2498,7 +2502,7 @@ export class SwitchBotPlatform {
2498
2502
  return this.switchBotBLE;
2499
2503
  }
2500
2504
  catch (e) {
2501
- await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e}`);
2505
+ await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e.message ?? e}`);
2502
2506
  return false;
2503
2507
  }
2504
2508
  }