@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10

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 (197) hide show
  1. package/README.md +16 -0
  2. package/dist/device/blindtilt.d.ts +15 -6
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +224 -370
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +9 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +197 -221
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +10 -5
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +214 -292
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +10 -5
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +335 -421
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +9 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +121 -200
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +20 -7
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +229 -403
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +41 -22
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +212 -181
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +9 -4
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +204 -249
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +9 -5
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +107 -233
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +12 -4
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +193 -235
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +9 -4
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +92 -159
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +10 -5
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +288 -370
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +10 -5
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +172 -219
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +9 -4
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +94 -160
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +9 -4
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +95 -157
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +9 -4
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +85 -144
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +9 -4
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +100 -127
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +172 -259
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +12 -4
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +106 -131
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +2 -1
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +2 -3
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +2 -1
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +2 -3
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +2 -1
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +2 -3
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +2 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +2 -3
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +3 -1
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +5 -1
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts +2 -1
  99. package/dist/irdevice/light.d.ts.map +1 -1
  100. package/dist/irdevice/light.js +2 -3
  101. package/dist/irdevice/light.js.map +1 -1
  102. package/dist/irdevice/other.d.ts +2 -1
  103. package/dist/irdevice/other.d.ts.map +1 -1
  104. package/dist/irdevice/other.js +2 -3
  105. package/dist/irdevice/other.js.map +1 -1
  106. package/dist/irdevice/tv.d.ts +2 -1
  107. package/dist/irdevice/tv.d.ts.map +1 -1
  108. package/dist/irdevice/tv.js +2 -3
  109. package/dist/irdevice/tv.js.map +1 -1
  110. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  111. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.js +2 -3
  113. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  114. package/dist/irdevice/waterheater.d.ts +2 -1
  115. package/dist/irdevice/waterheater.d.ts.map +1 -1
  116. package/dist/irdevice/waterheater.js +2 -3
  117. package/dist/irdevice/waterheater.js.map +1 -1
  118. package/dist/platform.d.ts +14 -14
  119. package/dist/platform.d.ts.map +1 -1
  120. package/dist/platform.js +102 -86
  121. package/dist/platform.js.map +1 -1
  122. package/dist/settings.d.ts +49 -190
  123. package/dist/settings.d.ts.map +1 -1
  124. package/dist/settings.js +19 -0
  125. package/dist/settings.js.map +1 -1
  126. package/dist/types/bledevicestatus.d.ts +279 -0
  127. package/dist/types/bledevicestatus.d.ts.map +1 -0
  128. package/dist/types/bledevicestatus.js +2 -0
  129. package/dist/types/bledevicestatus.js.map +1 -0
  130. package/dist/types/devicelist.d.ts +89 -0
  131. package/dist/types/devicelist.d.ts.map +1 -0
  132. package/dist/types/devicelist.js +6 -0
  133. package/dist/types/devicelist.js.map +1 -0
  134. package/dist/types/deviceresponse.d.ts +13 -0
  135. package/dist/types/deviceresponse.d.ts.map +1 -0
  136. package/dist/types/deviceresponse.js +2 -0
  137. package/dist/types/deviceresponse.js.map +1 -0
  138. package/dist/types/devicestatus.d.ts +149 -0
  139. package/dist/types/devicestatus.d.ts.map +1 -0
  140. package/dist/types/devicestatus.js +3 -0
  141. package/dist/types/devicestatus.js.map +1 -0
  142. package/dist/types/devicewebhookstatus.d.ts +156 -0
  143. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  144. package/dist/types/devicewebhookstatus.js +2 -0
  145. package/dist/types/devicewebhookstatus.js.map +1 -0
  146. package/dist/types/irdevicelist.d.ts +10 -0
  147. package/dist/types/irdevicelist.d.ts.map +1 -0
  148. package/dist/types/irdevicelist.js +2 -0
  149. package/dist/types/irdevicelist.js.map +1 -0
  150. package/dist/types/pushbody.d.ts +6 -0
  151. package/dist/types/pushbody.d.ts.map +1 -0
  152. package/dist/types/pushbody.js +2 -0
  153. package/dist/types/pushbody.js.map +1 -0
  154. package/dist/utils.d.ts +25 -0
  155. package/dist/utils.d.ts.map +1 -1
  156. package/dist/utils.js +28 -0
  157. package/dist/utils.js.map +1 -1
  158. package/package.json +11 -11
  159. package/src/device/blindtilt.ts +254 -376
  160. package/src/device/bot.ts +209 -224
  161. package/src/device/ceilinglight.ts +227 -297
  162. package/src/device/colorbulb.ts +345 -435
  163. package/src/device/contact.ts +139 -200
  164. package/src/device/curtain.ts +254 -414
  165. package/src/device/device.ts +221 -190
  166. package/src/device/fan.ts +222 -253
  167. package/src/device/hub.ts +127 -248
  168. package/src/device/humidifier.ts +217 -246
  169. package/src/device/iosensor.ts +115 -168
  170. package/src/device/lightstrip.ts +303 -380
  171. package/src/device/lock.ts +188 -224
  172. package/src/device/meter.ts +117 -179
  173. package/src/device/meterplus.ts +118 -176
  174. package/src/device/motion.ts +100 -146
  175. package/src/device/plug.ts +111 -131
  176. package/src/device/robotvacuumcleaner.ts +191 -258
  177. package/src/device/waterdetector.ts +124 -141
  178. package/src/irdevice/airconditioner.ts +4 -4
  179. package/src/irdevice/airpurifier.ts +4 -4
  180. package/src/irdevice/camera.ts +4 -4
  181. package/src/irdevice/fan.ts +4 -4
  182. package/src/irdevice/irdevice.ts +8 -2
  183. package/src/irdevice/light.ts +4 -4
  184. package/src/irdevice/other.ts +4 -4
  185. package/src/irdevice/tv.ts +4 -4
  186. package/src/irdevice/vacuumcleaner.ts +4 -4
  187. package/src/irdevice/waterheater.ts +4 -4
  188. package/src/platform.ts +104 -87
  189. package/src/settings.ts +30 -238
  190. package/src/types/bledevicestatus.ts +305 -0
  191. package/src/types/devicelist.ts +124 -0
  192. package/src/types/deviceresponse.ts +15 -0
  193. package/src/types/devicestatus.ts +178 -0
  194. package/src/types/devicewebhookstatus.ts +196 -0
  195. package/src/types/irdevicelist.ts +15 -0
  196. package/src/types/pushbody.ts +9 -0
  197. package/src/utils.ts +33 -0
package/dist/platform.js CHANGED
@@ -32,13 +32,13 @@ import { AirConditioner } from './irdevice/airconditioner.js';
32
32
  import { Buffer } from 'buffer';
33
33
  import { request } from 'undici';
34
34
  import asyncmqtt from 'async-mqtt';
35
- import { sleep } from './utils.js';
36
35
  import { createServer } from 'http';
37
36
  import { queueScheduler } from 'rxjs';
38
37
  import fakegato from 'fakegato-history';
39
38
  import crypto, { randomUUID } from 'crypto';
40
39
  import { readFileSync, writeFileSync } from 'fs';
41
40
  import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
41
+ import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
42
42
  import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
43
43
  /**
44
44
  * HomebridgePlatform
@@ -128,29 +128,29 @@ export class SwitchBotPlatform {
128
128
  try {
129
129
  const { connectAsync } = asyncmqtt;
130
130
  this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
131
- this.debugLog('MQTT connection has been established successfully.');
132
- this.mqttClient.on('error', (e) => {
133
- this.errorLog(`Failed to publish MQTT messages. ${e}`);
131
+ await this.debugLog('MQTT connection has been established successfully.');
132
+ this.mqttClient.on('error', async (e) => {
133
+ await this.errorLog(`Failed to publish MQTT messages. ${e}`);
134
134
  });
135
135
  if (!this.config.options?.webhookURL) {
136
136
  // receive webhook events via MQTT
137
- this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
137
+ await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
138
138
  this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
139
139
  this.mqttClient.on('message', async (topic, message) => {
140
140
  try {
141
- this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
141
+ await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
142
142
  const context = JSON.parse(message.toString());
143
- await this.webhookEventHandler[context.deviceMac]?.(context);
143
+ this.webhookEventHandler[context.deviceMac]?.(context);
144
144
  }
145
145
  catch (e) {
146
- this.errorLog(`Failed to handle webhook event. Error:${e}`);
146
+ await this.errorLog(`Failed to handle webhook event. Error:${e}`);
147
147
  }
148
148
  });
149
149
  }
150
150
  }
151
151
  catch (e) {
152
152
  this.mqttClient = null;
153
- this.errorLog(`Failed to establish MQTT connection. ${e}`);
153
+ await this.errorLog(`Failed to establish MQTT connection. ${e}`);
154
154
  }
155
155
  }
156
156
  }
@@ -177,7 +177,7 @@ export class SwitchBotPlatform {
177
177
  const options = this.config.options?.mqttPubOptions || {};
178
178
  this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
179
179
  }
180
- await this.webhookEventHandler[body.context.deviceMac]?.(body.context);
180
+ this.webhookEventHandler[body.context.deviceMac]?.(body.context);
181
181
  }
182
182
  catch (e) {
183
183
  this.errorLog(`Failed to handle webhook event. Error:${e}`);
@@ -275,9 +275,7 @@ export class SwitchBotPlatform {
275
275
  }),
276
276
  });
277
277
  const response = await body.json();
278
- this.debugLog(`deleteWebhook: url:${url}`);
279
- this.debugLog(`deleteWebhook: body:${JSON.stringify(response)}`);
280
- this.debugLog(`deleteWebhook: statusCode:${statusCode}`);
278
+ this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
281
279
  if (statusCode !== 200 || response?.statusCode !== 100) {
282
280
  this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
283
281
  }
@@ -1330,16 +1328,18 @@ export class SwitchBotPlatform {
1330
1328
  if (!device.external) {
1331
1329
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1332
1330
  }
1333
- if (device.group && !device.curtain?.disable_group) {
1334
- this.debugLog('Your Curtains are grouped, ' +
1335
- `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1336
- }
1337
- else {
1338
- if (device.master) {
1339
- this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1331
+ if (isBlindTiltDevice(device)) {
1332
+ if (device.group && !device.curtain?.disable_group) {
1333
+ this.debugLog('Your Curtains are grouped, ' +
1334
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1340
1335
  }
1341
1336
  else {
1342
- this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1337
+ if (device.master) {
1338
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1339
+ }
1340
+ else {
1341
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1342
+ }
1343
1343
  }
1344
1344
  }
1345
1345
  // create a new accessory
@@ -1399,16 +1399,18 @@ export class SwitchBotPlatform {
1399
1399
  if (!device.external) {
1400
1400
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1401
1401
  }
1402
- if (device.group && !device.curtain?.disable_group) {
1403
- this.debugLog('Your Curtains are grouped, ' +
1404
- `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1405
- }
1406
- else {
1407
- if (device.master) {
1408
- this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1402
+ if (isCurtainDevice(device)) {
1403
+ if (device.group && !device.curtain?.disable_group) {
1404
+ this.debugLog('Your Curtains are grouped, ' +
1405
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1409
1406
  }
1410
1407
  else {
1411
- this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1408
+ if (device.master) {
1409
+ this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1410
+ }
1411
+ else {
1412
+ this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1413
+ }
1412
1414
  }
1413
1415
  }
1414
1416
  // create a new accessory
@@ -1844,9 +1846,6 @@ export class SwitchBotPlatform {
1844
1846
  existingAccessory.context.model = device.remoteType;
1845
1847
  existingAccessory.context.deviceID = device.deviceId;
1846
1848
  existingAccessory.displayName = device.configDeviceName || device.deviceName;
1847
- if (device.version && !device.firmware) {
1848
- existingAccessory.context.version = device.version;
1849
- }
1850
1849
  existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
1851
1850
  this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1852
1851
  existingAccessory.context.connectionType = device.connectionType;
@@ -2341,16 +2340,32 @@ export class SwitchBotPlatform {
2341
2340
  }
2342
2341
  }
2343
2342
  async registerCurtains(device) {
2344
- switch (device.deviceType) {
2345
- case 'Curtain':
2346
- case 'Curtain3':
2347
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: `
2348
- + `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
2349
- break;
2350
- default:
2351
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}, master:`
2352
- + ` ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
2343
+ /*function isCurtainDevice(device: device & devicesConfig): device is (curtain | curtain3) & devicesConfig {
2344
+ return device.deviceType === 'Curtain' || device.deviceType === 'Curtain3';
2345
+ }
2346
+
2347
+ function isBlindTiltDevice(device: device & devicesConfig): device is blindTilt & devicesConfig {
2348
+ return device.deviceType === 'Blind Tilt';
2349
+ }*/
2350
+ let registerWindowCovering;
2351
+ if (isCurtainDevice(device)) {
2352
+ this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: `
2353
+ + `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
2354
+ registerWindowCovering = await this.registerWindowCovering(device);
2355
+ }
2356
+ else if (isBlindTiltDevice(device)) {
2357
+ this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds},`
2358
+ + ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group},`
2359
+ + ` connectionType: ${device.connectionType}`);
2360
+ registerWindowCovering = await this.registerWindowCovering(device);
2361
+ }
2362
+ else {
2363
+ registerWindowCovering = false;
2353
2364
  }
2365
+ return registerWindowCovering;
2366
+ }
2367
+ async registerWindowCovering(device) {
2368
+ this.debugLog(device.master);
2354
2369
  let registerCurtain;
2355
2370
  if (device.master && device.group) {
2356
2371
  // OpenAPI: Master Curtains/Blind Tilt in Group
@@ -2524,67 +2539,67 @@ export class SwitchBotPlatform {
2524
2539
  async statusCode(statusCode) {
2525
2540
  switch (statusCode) {
2526
2541
  case 151:
2527
- this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
2542
+ await this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
2528
2543
  'https://tinyurl.com/SwitchBotFeatureRequest');
2529
2544
  break;
2530
2545
  case 152:
2531
- this.errorLog(`Device not found, statusCode: ${statusCode}`);
2546
+ await this.errorLog(`Device not found, statusCode: ${statusCode}`);
2532
2547
  break;
2533
2548
  case 160:
2534
- this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
2549
+ await this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
2535
2550
  break;
2536
2551
  case 161:
2537
- this.errorLog(`Device is offline, statusCode: ${statusCode}`);
2552
+ await this.errorLog(`Device is offline, statusCode: ${statusCode}`);
2538
2553
  break;
2539
2554
  case 171:
2540
- this.errorLog(`is offline, statusCode: ${statusCode}`);
2555
+ await this.errorLog(`is offline, statusCode: ${statusCode}`);
2541
2556
  break;
2542
2557
  case 190:
2543
- this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
2558
+ await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
2544
2559
  break;
2545
2560
  case 100:
2546
- this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2561
+ await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2547
2562
  break;
2548
2563
  case 200:
2549
- this.debugLog(`Request successful, statusCode: ${statusCode}`);
2564
+ await this.debugLog(`Request successful, statusCode: ${statusCode}`);
2550
2565
  break;
2551
2566
  case 400:
2552
- this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
2567
+ await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
2553
2568
  + `payload, statusCode: ${statusCode}`);
2554
2569
  break;
2555
2570
  case 401:
2556
- this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
2571
+ await this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
2557
2572
  + `statusCode: ${statusCode}`);
2558
2573
  break;
2559
2574
  case 403:
2560
- this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
2575
+ await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
2561
2576
  + `found, statusCode: ${statusCode}`);
2562
2577
  break;
2563
2578
  case 404:
2564
- this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
2579
+ await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
2565
2580
  break;
2566
2581
  case 406:
2567
- this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
2582
+ await this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
2568
2583
  + `statusCode: ${statusCode}`);
2569
2584
  break;
2570
2585
  case 415:
2571
- this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
2586
+ await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
2572
2587
  + `statusCode: ${statusCode}`);
2573
2588
  break;
2574
2589
  case 422:
2575
- this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
2590
+ await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
2576
2591
  + `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
2577
2592
  break;
2578
2593
  case 429:
2579
- this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
2594
+ await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
2580
2595
  + `statusCode: ${statusCode}`);
2581
2596
  break;
2582
2597
  case 500:
2583
- this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
2598
+ await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
2584
2599
  + `statusCode: ${statusCode}`);
2585
2600
  break;
2586
2601
  default:
2587
- this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
2602
+ await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
2588
2603
  }
2589
2604
  }
2590
2605
  async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries, url, options) {
@@ -2598,34 +2613,35 @@ export class SwitchBotPlatform {
2598
2613
  return { body, statusCode };
2599
2614
  }
2600
2615
  else {
2601
- this.debugLog(`Received status code: ${statusCode}`);
2616
+ await this.debugLog(`Received status code: ${statusCode}`);
2602
2617
  }
2603
2618
  }
2604
2619
  catch (error) {
2605
- this.errorLog(`Error making request: ${error.message}`);
2620
+ await this.errorLog(`Error making request: ${error.message}`);
2606
2621
  }
2607
2622
  retryCount++;
2608
- this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2623
+ await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2609
2624
  await sleep(delayBetweenRetries);
2610
2625
  }
2611
2626
  return { body: null, statusCode: -1 };
2612
2627
  }
2613
2628
  // BLE Connection
2614
- async connectBLE() {
2629
+ async connectBLE(accessory, device) {
2615
2630
  let switchbot;
2616
2631
  try {
2617
2632
  const SwitchBot = (await import('node-switchbot')).SwitchBot;
2618
2633
  queueScheduler.schedule(() => (switchbot = new SwitchBot()));
2634
+ await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
2619
2635
  }
2620
2636
  catch (e) {
2621
2637
  switchbot = false;
2622
- this.errorLog(`Was 'node-switchbot' found: ${switchbot}, Error: ${e}`);
2638
+ await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
2623
2639
  }
2624
2640
  return switchbot;
2625
2641
  }
2626
2642
  async getVersion() {
2627
2643
  const json = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
2628
- this.debugLog(`Plugin Version: ${json.version}`);
2644
+ await this.debugLog(`Plugin Version: ${json.version}`);
2629
2645
  this.version = json.version;
2630
2646
  }
2631
2647
  async getPlatformConfigSettings() {
@@ -2662,7 +2678,7 @@ export class SwitchBotPlatform {
2662
2678
  platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
2663
2679
  }
2664
2680
  if (Object.entries(platformConfig).length !== 0) {
2665
- this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2681
+ await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2666
2682
  }
2667
2683
  this.platformConfig = platformConfig;
2668
2684
  }
@@ -2671,64 +2687,64 @@ export class SwitchBotPlatform {
2671
2687
  this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
2672
2688
  if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
2673
2689
  this.platformLogging = this.config.options.logging;
2674
- this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2690
+ await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2675
2691
  }
2676
2692
  else if (this.debugMode) {
2677
2693
  this.platformLogging = 'debugMode';
2678
- this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2694
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2679
2695
  }
2680
2696
  else {
2681
2697
  this.platformLogging = 'standard';
2682
- this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2698
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2683
2699
  }
2684
2700
  }
2685
2701
  /**
2686
2702
  * If device level logging is turned on, log to log.warn
2687
2703
  * Otherwise send debug logs to log.debug
2688
2704
  */
2689
- infoLog(...log) {
2690
- if (this.enablingPlatformLogging()) {
2705
+ async infoLog(...log) {
2706
+ if (await this.enablingPlatformLogging()) {
2691
2707
  this.log.info(String(...log));
2692
2708
  }
2693
2709
  }
2694
- successLog(...log) {
2695
- if (this.enablingPlatformLogging()) {
2710
+ async successLog(...log) {
2711
+ if (await this.enablingPlatformLogging()) {
2696
2712
  this.log.success(String(...log));
2697
2713
  }
2698
2714
  }
2699
- debugSuccessLog(...log) {
2700
- if (this.enablingPlatformLogging()) {
2715
+ async debugSuccessLog(...log) {
2716
+ if (await this.enablingPlatformLogging()) {
2701
2717
  if (this.platformLogging?.includes('debug')) {
2702
2718
  this.log.success('[DEBUG]', String(...log));
2703
2719
  }
2704
2720
  }
2705
2721
  }
2706
- warnLog(...log) {
2707
- if (this.enablingPlatformLogging()) {
2722
+ async warnLog(...log) {
2723
+ if (await this.enablingPlatformLogging()) {
2708
2724
  this.log.warn(String(...log));
2709
2725
  }
2710
2726
  }
2711
- debugWarnLog(...log) {
2712
- if (this.enablingPlatformLogging()) {
2727
+ async debugWarnLog(...log) {
2728
+ if (await this.enablingPlatformLogging()) {
2713
2729
  if (this.platformLogging?.includes('debug')) {
2714
2730
  this.log.warn('[DEBUG]', String(...log));
2715
2731
  }
2716
2732
  }
2717
2733
  }
2718
- errorLog(...log) {
2719
- if (this.enablingPlatformLogging()) {
2734
+ async errorLog(...log) {
2735
+ if (await this.enablingPlatformLogging()) {
2720
2736
  this.log.error(String(...log));
2721
2737
  }
2722
2738
  }
2723
- debugErrorLog(...log) {
2724
- if (this.enablingPlatformLogging()) {
2739
+ async debugErrorLog(...log) {
2740
+ if (await this.enablingPlatformLogging()) {
2725
2741
  if (this.platformLogging?.includes('debug')) {
2726
2742
  this.log.error('[DEBUG]', String(...log));
2727
2743
  }
2728
2744
  }
2729
2745
  }
2730
- debugLog(...log) {
2731
- if (this.enablingPlatformLogging()) {
2746
+ async debugLog(...log) {
2747
+ if (await this.enablingPlatformLogging()) {
2732
2748
  if (this.platformLogging === 'debugMode') {
2733
2749
  this.log.debug(String(...log));
2734
2750
  }
@@ -2737,7 +2753,7 @@ export class SwitchBotPlatform {
2737
2753
  }
2738
2754
  }
2739
2755
  }
2740
- enablingPlatformLogging() {
2756
+ async enablingPlatformLogging() {
2741
2757
  return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
2742
2758
  }
2743
2759
  }