@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
@@ -3,12 +3,20 @@
3
3
  * robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
- import { Subject, interval, skipWhile } from 'rxjs';
7
- import { debounceTime, take, tap } from 'rxjs/operators';
6
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
7
+ import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
8
8
 
9
+ import type { devicesConfig } from '../settings.js';
10
+ import type { device } from '../types/devicelist.js';
9
11
  import type { SwitchBotPlatform } from '../platform.js';
12
+ import type { robotVacuumCleanerServiceData } from '../types/bledevicestatus.js';
10
13
  import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
11
- import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
14
+ import type { robotVacuumCleanerS1Status, robotVacuumCleanerS1PlusStatus, floorCleaningRobotS10Status } from '../types/devicestatus.js';
15
+ import type {
16
+ floorCleaningRobotS10WebhookContext,
17
+ robotVacuumCleanerS1PlusWebhookContext,
18
+ robotVacuumCleanerS1WebhookContext,
19
+ } from '../types/devicewebhookstatus.js';
12
20
 
13
21
  export class RobotVacuumCleaner extends deviceBase {
14
22
  // Services
@@ -108,9 +116,13 @@ export class RobotVacuumCleaner extends deviceBase {
108
116
 
109
117
  // Retrieve initial values and updateHomekit
110
118
  this.refreshStatus();
119
+
111
120
  // Update Homekit
112
121
  this.updateHomeKitCharacteristics();
113
122
 
123
+ //regisiter webhook event handler
124
+ this.registerWebhook();
125
+
114
126
  // Start an update interval
115
127
  interval(this.deviceRefreshRate * 1000)
116
128
  .pipe(skipWhile(() => this.robotVacuumCleanerUpdateInProgress))
@@ -118,9 +130,6 @@ export class RobotVacuumCleaner extends deviceBase {
118
130
  await this.refreshStatus();
119
131
  });
120
132
 
121
- //regisiter webhook event handler
122
- this.registerWebhook(accessory, device);
123
-
124
133
  // Watch for Plug change events
125
134
  // We put in a debounce of 100ms so we don't make duplicate calls
126
135
  this.doRobotVacuumCleanerUpdate
@@ -134,71 +143,48 @@ export class RobotVacuumCleaner extends deviceBase {
134
143
  try {
135
144
  await this.pushChanges();
136
145
  } catch (e: any) {
137
- this.apiError(e);
138
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed pushChanges with ${device.connectionType} Connection,`
139
- + ` Error Message: ${JSON.stringify(e.message)}`);
146
+ await this.apiError(e);
147
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
140
148
  }
141
149
  this.robotVacuumCleanerUpdateInProgress = false;
142
150
  });
143
151
  }
144
152
 
145
- async BLEparseStatus(serviceData: serviceData): Promise<void> {
146
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
147
-
148
- // Battery
153
+ async BLEparseStatus(serviceData: robotVacuumCleanerServiceData): Promise<void> {
154
+ await this.debugLog('BLEparseStatus');
155
+ // On
156
+ this.LightBulb.On = serviceData.state === 'on' ? true : false;
157
+ await this.debugLog(`On: ${this.LightBulb.On}`);
158
+ // BatteryLevel
149
159
  this.Battery.BatteryLevel = Number(serviceData.battery);
150
- if (this.Battery.BatteryLevel < 10) {
151
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
152
- } else {
153
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
154
- }
155
- this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
156
-
157
- // State
158
- switch (serviceData.state) {
159
- case 'on':
160
- this.LightBulb.On = true;
161
- break;
162
- default:
163
- this.LightBulb.On = false;
164
- }
165
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
160
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
161
+ // StatusLowBattery
162
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
163
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
164
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
166
165
  }
167
166
 
168
- async openAPIparseStatus(deviceStatus: deviceStatus) {
169
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
170
- switch (deviceStatus.body.power) {
171
- case 'on':
172
- this.LightBulb.On = true;
173
- break;
174
- default:
175
- this.LightBulb.On = false;
176
- }
177
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
178
-
167
+ async openAPIparseStatus(deviceStatus: robotVacuumCleanerS1Status | robotVacuumCleanerS1PlusStatus | floorCleaningRobotS10Status) {
168
+ await this.debugLog('openAPIparseStatus');
169
+ // On
170
+ this.LightBulb.On = deviceStatus.onlineStatus === 'online' ? true : false;
171
+ await this.debugLog(`On: ${this.LightBulb.On}`);
179
172
  // BatteryLevel
180
- this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
181
-
173
+ this.Battery.BatteryLevel = Number(deviceStatus.battery);
174
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
182
175
  // StatusLowBattery
183
- if (this.Battery.BatteryLevel < 10) {
184
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
185
- } else {
186
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
187
- }
188
- if (Number.isNaN(this.Battery.BatteryLevel)) {
189
- this.Battery.BatteryLevel = 100;
190
- }
176
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
177
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
178
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
191
179
  // ChargingState
192
- this.Battery.ChargingState = deviceStatus.body.workingStatus === 'Charging'
180
+ this.Battery.ChargingState = deviceStatus.workingStatus === 'Charging'
193
181
  ? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
194
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
195
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}, ChargingState: ${this.Battery.ChargingState}`);
196
-
182
+ await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
197
183
  // Firmware Version
198
- const version = deviceStatus.body.version?.toString();
199
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
200
- if (deviceStatus.body.version) {
201
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
184
+ if (deviceStatus.version) {
185
+ const version = deviceStatus.version.toString();
186
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
187
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
202
188
  this.accessory
203
189
  .getService(this.hap.Service.AccessoryInformation)!
204
190
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -206,29 +192,49 @@ export class RobotVacuumCleaner extends deviceBase {
206
192
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
207
193
  .updateValue(deviceVersion);
208
194
  this.accessory.context.deviceVersion = deviceVersion;
209
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
195
+ await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
210
196
  }
211
197
  }
212
198
 
199
+ async parseStatusWebhook(context: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext
200
+ | floorCleaningRobotS10WebhookContext): Promise<void> {
201
+ await this.debugLog('parseStatusWebhook');
202
+ await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${context.onlineStatus}, ${context.battery}, ${context.workingStatus}),`
203
+ + ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
204
+ // On
205
+ this.LightBulb.On = context.onlineStatus === 'online' ? true : false;
206
+ await this.debugLog(`On: ${this.LightBulb.On}`);
207
+ // BatteryLevel
208
+ this.Battery.BatteryLevel = Number(context.battery);
209
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
210
+ // StatusLowBattery
211
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
212
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
213
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
214
+ // ChargingState
215
+ this.Battery.ChargingState = context.workingStatus === 'Charging'
216
+ ? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
217
+ await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
218
+ }
219
+
213
220
  /**
214
221
  * Asks the SwitchBot API for the latest device information
215
222
  */
216
223
  async refreshStatus(): Promise<void> {
217
224
  if (!this.device.enableCloudService && this.OpenAPI) {
218
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
225
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
219
226
  } else if (this.BLE) {
220
227
  await this.BLERefreshStatus();
221
228
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
222
229
  await this.openAPIRefreshStatus();
223
230
  } else {
224
231
  await this.offlineOff();
225
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
226
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
232
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
227
233
  }
228
234
  }
229
235
 
230
236
  async BLERefreshStatus(): Promise<void> {
231
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
237
+ await this.debugLog('BLERefreshStatus');
232
238
  const switchbot = await this.switchbotBLE();
233
239
 
234
240
  if (switchbot === undefined) {
@@ -237,13 +243,13 @@ export class RobotVacuumCleaner extends deviceBase {
237
243
  // Start to monitor advertisement packets
238
244
  (async () => {
239
245
  // Start to monitor advertisement packets
240
- const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
246
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
241
247
  // Update HomeKit
242
- if (serviceData.model !== '' && serviceData.modelName !== '') {
248
+ if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
243
249
  await this.BLEparseStatus(serviceData);
244
250
  await this.updateHomeKitCharacteristics();
245
251
  } else {
246
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
252
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
247
253
  await this.BLERefreshConnection(switchbot);
248
254
  }
249
255
  })();
@@ -251,47 +257,40 @@ export class RobotVacuumCleaner extends deviceBase {
251
257
  }
252
258
 
253
259
  async openAPIRefreshStatus(): Promise<void> {
254
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
260
+ await this.debugLog('openAPIRefreshStatus');
255
261
  try {
256
262
  const { body, statusCode } = await this.deviceRefreshStatus();
257
263
  const deviceStatus: any = await body.json();
258
- await this.refreshStatusCodes(statusCode, deviceStatus);;
259
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
260
- await this.successfulRefreshStatus(statusCode, deviceStatus);
261
- await this.openAPIparseStatus(deviceStatus);
264
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
265
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
266
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
267
+ await this.openAPIparseStatus(deviceStatus.body);
262
268
  await this.updateHomeKitCharacteristics();
263
269
  } else {
264
- await this.statusCodes(statusCode, deviceStatus);
270
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
271
+ await this.debugWarnLog(statusCode, deviceStatus);
265
272
  }
266
273
  } catch (e: any) {
267
- this.apiError(e);
268
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
269
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
274
+ await this.apiError(e);
275
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
270
276
  }
271
277
  }
272
278
 
273
- async registerWebhook(accessory: PlatformAccessory, device: device & devicesConfig) {
274
- if (device.webhook) {
275
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
276
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
279
+ async registerWebhook() {
280
+ if (this.device.webhook) {
281
+ await this.debugLog('is listening webhook.');
282
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context: robotVacuumCleanerS1WebhookContext
283
+ | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
277
284
  try {
278
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
279
- const { onlineStatus, battery, workingStatus } = context;
280
- const { On } = this.LightBulb;
281
- const { BatteryLevel, ChargingState } = this.Battery;
282
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (onlineStatus, battery, workingStatus) = `
283
- + `Webhook: (${onlineStatus}, ${battery}, ${workingStatus}), current: (${On}, ${BatteryLevel}, ${ChargingState})`);
284
- this.LightBulb.On = onlineStatus === 'online' ? true : false;
285
- this.Battery.ChargingState = workingStatus === 'Charging'
286
- ? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
287
- this.Battery.BatteryLevel = battery;
288
- this.updateHomeKitCharacteristics();
285
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
286
+ await this.parseStatusWebhook(context);
287
+ await this.updateHomeKitCharacteristics();
289
288
  } catch (e: any) {
290
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
289
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
291
290
  }
292
291
  };
293
292
  } else {
294
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
293
+ await this.debugLog('is not listening webhook.');
295
294
  }
296
295
  }
297
296
 
@@ -303,18 +302,16 @@ export class RobotVacuumCleaner extends deviceBase {
303
302
  * Robot Vacuum Cleaner S1 "command" "dock" "default" = return to charging dock
304
303
  * Robot Vacuum Cleaner S1 "command" "PowLevel" "{0-3}" = set suction power level: 0 (Quiet), 1 (Standard), 2 (Strong), 3 (MAX)
305
304
  */
306
-
307
305
  async pushChanges(): Promise<void> {
308
306
  if (!this.device.enableCloudService && this.OpenAPI) {
309
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
307
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
310
308
  } else if (this.BLE) {
311
309
  await this.BLEpushChanges();
312
310
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
313
311
  await this.openAPIpushChanges();
314
312
  } else {
315
313
  await this.offlineOff();
316
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
317
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
314
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
318
315
  }
319
316
  // Refresh the status from the API
320
317
  interval(15000)
@@ -326,153 +323,115 @@ export class RobotVacuumCleaner extends deviceBase {
326
323
  }
327
324
 
328
325
  async BLEpushChanges(): Promise<void> {
329
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
326
+ await this.debugLog('BLEpushChanges');
330
327
  if (this.LightBulb.On !== this.accessory.context.On) {
331
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`
332
- + ` On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
333
- const switchbot = await this.platform.connectBLE();
334
- // Convert to BLE Address
328
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
335
329
  await this.convertBLEAddress();
336
- switchbot
337
- .discover({
338
- model: '?',
339
- id: this.device.bleMac,
340
- })
341
- .then(async (device_list: any) => {
342
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
343
- return await this.retryBLE({
344
- max: await this.maxRetryBLE(),
345
- fn: async () => {
346
- if (this.LightBulb.On) {
347
- return await device_list[0].turnOn({ id: this.device.bleMac });
348
- } else {
349
- return await device_list[0].turnOff({ id: this.device.bleMac });
350
- }
351
- },
330
+ if (switchbot !== false) {
331
+ switchbot
332
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
333
+ .then(async (device_list: any) => {
334
+ await this.infoLog(`On: ${this.LightBulb.On}`);
335
+ return await this.retryBLE({
336
+ max: await this.maxRetryBLE(),
337
+ fn: async () => {
338
+ if (this.LightBulb.On) {
339
+ return await device_list[0].turnOn({ id: this.device.bleMac });
340
+ } else {
341
+ return await device_list[0].turnOff({ id: this.device.bleMac });
342
+ }
343
+ },
344
+ });
345
+ })
346
+ .then(async () => {
347
+ await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
348
+ await this.updateHomeKitCharacteristics();
349
+ })
350
+ .catch(async (e: any) => {
351
+ await this.apiError(e);
352
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
353
+ await this.BLEPushConnection();
352
354
  });
353
- })
354
- .then(() => {
355
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
356
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
357
- + `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
358
- this.LightBulb.On = false;
359
- })
360
- .catch(async (e: any) => {
361
- this.apiError(e);
362
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
363
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
364
- await this.BLEPushConnection();
365
- });
355
+ } else {
356
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
357
+ await this.BLEPushConnection();
358
+ }
366
359
  } else {
367
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges,`
368
- + ` On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
360
+ await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
369
361
  }
370
362
  }
371
363
 
372
364
  async openAPIpushChanges() {
373
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
365
+ await this.debugLog('openAPIpushChanges');
374
366
  if (this.LightBulb.On !== this.accessory.context.On) {
375
- const bodyChange = await this.commands();
376
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
367
+ const command = this.LightBulb.On ? 'start' : 'dock';
368
+ const bodyChange = JSON.stringify({
369
+ command: `${command}`,
370
+ parameter: 'default',
371
+ commandType: 'command',
372
+ });
373
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
377
374
  try {
378
375
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
379
376
  const deviceStatus: any = await body.json();
380
- await this.pushStatusCodes(statusCode, deviceStatus);
381
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
382
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
383
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
384
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
385
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
377
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
378
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
379
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
380
+ await this.updateHomeKitCharacteristics();
386
381
  } else {
387
- this.statusCode(statusCode);
388
- this.statusCode(deviceStatus.statusCode);
382
+ await this.statusCode(statusCode);
383
+ await this.statusCode(deviceStatus.statusCode);
389
384
  }
390
385
  } catch (e: any) {
391
- this.apiError(e);
392
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
393
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
386
+ await this.apiError(e);
387
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
394
388
  }
395
389
  } else {
396
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges, On: ${this.LightBulb.On}, `
397
- + `OnCached: ${this.accessory.context.On}`);
390
+ await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
398
391
  }
399
392
  }
400
393
 
401
394
  async openAPIpushBrightnessChanges() {
402
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushBrightnessChanges`);
403
- const bodyChange = await this.brightnessCommands();
404
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
405
- try {
406
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
407
- const deviceStatus: any = await body.json();
408
- await this.refreshStatusCodes(statusCode, deviceStatus);;
409
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
410
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
411
- await this.updateHomeKitCharacteristics();
412
- } else {
413
- await this.statusCode(statusCode);
414
- await this.statusCode(deviceStatus.statusCode);
395
+ await this.debugLog('openAPIpushBrightnessChanges');
396
+ if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
397
+ const command = this.LightBulb.Brightness === 0 ? 'dock' : 'PowLevel';
398
+ const parameter = this.LightBulb.Brightness === 25 ? '0' : this.LightBulb.Brightness === 50 ? '1' : this.LightBulb.Brightness === 75
399
+ ? '2' : this.LightBulb.Brightness === 100 ? '3' : 'default';
400
+ const bodyChange = JSON.stringify({
401
+ command: `${command}`,
402
+ parameter: `${parameter}`,
403
+ commandType: 'command',
404
+ });
405
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
406
+ try {
407
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange);
408
+ const deviceStatus: any = await body.json();
409
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
410
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
411
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
412
+ await this.updateHomeKitCharacteristics();
413
+ } else {
414
+ await this.statusCode(statusCode);
415
+ await this.statusCode(deviceStatus.statusCode);
416
+ }
417
+ } catch (e: any) {
418
+ await this.apiError(e);
419
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
415
420
  }
416
- } catch (e: any) {
417
- this.apiError(e);
418
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
419
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
420
- }
421
- }
422
-
423
- async commands() {
424
- let command: string;
425
- let parameter: string;
426
- if (this.LightBulb.On) {
427
- command = 'start';
428
- parameter = 'default';
429
421
  } else {
430
- command = 'dock';
431
- parameter = 'default';
422
+ await this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
423
+ + ` BrightnessCached: ${this.accessory.context.Brightness}`);
432
424
  }
433
- const body = JSON.stringify({
434
- command: `${command}`,
435
- parameter: `${parameter}`,
436
- commandType: 'command',
437
- });
438
- return body;
439
- }
440
-
441
- async brightnessCommands(): Promise<string> {
442
- let command: string;
443
- let parameter: string;
444
- if (this.LightBulb.Brightness === 25) {
445
- command = 'PowLevel';
446
- parameter = '0';
447
- } else if (this.LightBulb.Brightness === 50) {
448
- command = 'PowLevel';
449
- parameter = '1';
450
- } else if (this.LightBulb.Brightness === 75) {
451
- command = 'PowLevel';
452
- parameter = '2';
453
- } else if (this.LightBulb.Brightness === 100) {
454
- command = 'PowLevel';
455
- parameter = '3';
456
- } else {
457
- command = 'dock';
458
- parameter = 'default';
459
- }
460
- const bodyChange = JSON.stringify({
461
- command: `${command}`,
462
- parameter: `${parameter}`,
463
- commandType: 'command',
464
- });
465
- return bodyChange;
466
425
  }
467
426
 
468
427
  /**
469
428
  * Handle requests to set the value of the "On" characteristic
470
429
  */
471
430
  async OnSet(value: CharacteristicValue): Promise<void> {
472
- if (this.LightBulb.On === this.accessory.context.On) {
473
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
431
+ if (this.LightBulb.On !== this.accessory.context.On) {
432
+ this.infoLog(`Set On: ${value}`);
474
433
  } else {
475
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
434
+ this.debugLog(`No Changes, On: ${value}`);
476
435
  }
477
436
 
478
437
  this.LightBulb.On = value;
@@ -483,12 +442,14 @@ export class RobotVacuumCleaner extends deviceBase {
483
442
  * Handle requests to set the value of the "Brightness" characteristic
484
443
  */
485
444
  async BrightnessSet(value: CharacteristicValue): Promise<void> {
486
- if (this.LightBulb.Brightness === this.accessory.context.Brightness) {
487
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
488
- } else if (this.LightBulb.On) {
489
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
445
+ if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
446
+ await this.infoLog(`Set Brightness: ${value}`);
490
447
  } else {
491
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
448
+ if (this.LightBulb.On) {
449
+ this.debugLog(`No Changes, Brightness: ${value}`);
450
+ } else {
451
+ this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`);
452
+ }
492
453
  }
493
454
 
494
455
  this.LightBulb.Brightness = value;
@@ -497,61 +458,33 @@ export class RobotVacuumCleaner extends deviceBase {
497
458
 
498
459
  async updateHomeKitCharacteristics(): Promise<void> {
499
460
  // On
500
- if (this.LightBulb.On === undefined) {
501
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
502
- } else {
503
- this.accessory.context.On = this.LightBulb.On;
504
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
505
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
506
- }
461
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
462
+ this.LightBulb.On, 'On');
507
463
  // Brightness
508
- if (this.LightBulb.Brightness === undefined) {
509
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
510
- } else {
511
- this.accessory.context.Brightness = this.LightBulb.Brightness;
512
- this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
513
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
514
- }
464
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
465
+ this.LightBulb.Brightness, 'Brightness');
515
466
  // BatteryLevel
516
- if (this.Battery.BatteryLevel === undefined) {
517
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
518
- } else {
519
- this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
520
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
521
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
522
- }
467
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
468
+ this.Battery.BatteryLevel, 'BatteryLevel');
523
469
  // StatusLowBattery
524
- if (this.Battery.StatusLowBattery === undefined) {
525
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
526
- } else {
527
- this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
528
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
529
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
530
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
531
- }
470
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
471
+ this.Battery.StatusLowBattery, 'StatusLowBattery');
532
472
  // ChargingState
533
- if (this.Battery.ChargingState === undefined) {
534
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
535
- } else {
536
- this.accessory.context.ChargingState = this.Battery.ChargingState;
537
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
538
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
539
- + ` ChargingState: ${this.Battery.ChargingState}`);
540
- }
473
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
474
+ this.Battery.ChargingState, 'ChargingState');
541
475
  }
542
476
 
543
477
  async BLEPushConnection() {
544
478
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
545
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
479
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
546
480
  await this.openAPIpushChanges();
547
481
  }
548
482
  }
549
483
 
550
484
  async BLERefreshConnection(switchbot: any): Promise<void> {
551
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
552
- + ` ${JSON.stringify(switchbot)}`);
485
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
553
486
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
554
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
487
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
555
488
  await this.openAPIRefreshStatus();
556
489
  }
557
490
  }