@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.3

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 (187) hide show
  1. package/dist/device/blindtilt.d.ts +15 -6
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +203 -255
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -4
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +196 -218
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +9 -4
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +202 -247
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +10 -5
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +329 -378
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +9 -4
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +99 -142
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +19 -7
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +203 -264
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +28 -32
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +186 -225
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +9 -4
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +198 -227
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +9 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +106 -231
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +12 -4
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +192 -232
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +9 -4
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +91 -157
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +10 -5
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +287 -367
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +10 -5
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +171 -216
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +9 -4
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +93 -158
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +9 -4
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +94 -155
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +9 -4
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +84 -142
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +9 -4
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +99 -124
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +170 -253
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +12 -4
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +102 -128
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/irdevice/airconditioner.d.ts +2 -1
  78. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  79. package/dist/irdevice/airconditioner.js.map +1 -1
  80. package/dist/irdevice/airpurifier.d.ts +2 -1
  81. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts +2 -1
  84. package/dist/irdevice/camera.d.ts.map +1 -1
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +2 -1
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js.map +1 -1
  89. package/dist/irdevice/irdevice.d.ts +2 -1
  90. package/dist/irdevice/irdevice.d.ts.map +1 -1
  91. package/dist/irdevice/irdevice.js +1 -1
  92. package/dist/irdevice/irdevice.js.map +1 -1
  93. package/dist/irdevice/light.d.ts +2 -1
  94. package/dist/irdevice/light.d.ts.map +1 -1
  95. package/dist/irdevice/light.js.map +1 -1
  96. package/dist/irdevice/other.d.ts +2 -1
  97. package/dist/irdevice/other.d.ts.map +1 -1
  98. package/dist/irdevice/other.js.map +1 -1
  99. package/dist/irdevice/tv.d.ts +2 -1
  100. package/dist/irdevice/tv.d.ts.map +1 -1
  101. package/dist/irdevice/tv.js.map +1 -1
  102. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  103. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  104. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  105. package/dist/irdevice/waterheater.d.ts +2 -1
  106. package/dist/irdevice/waterheater.d.ts.map +1 -1
  107. package/dist/irdevice/waterheater.js.map +1 -1
  108. package/dist/platform.d.ts +5 -7
  109. package/dist/platform.d.ts.map +1 -1
  110. package/dist/platform.js +51 -34
  111. package/dist/platform.js.map +1 -1
  112. package/dist/settings.d.ts +49 -191
  113. package/dist/settings.d.ts.map +1 -1
  114. package/dist/settings.js +19 -0
  115. package/dist/settings.js.map +1 -1
  116. package/dist/types/bledevicestatus.d.ts +279 -0
  117. package/dist/types/bledevicestatus.d.ts.map +1 -0
  118. package/dist/types/bledevicestatus.js +2 -0
  119. package/dist/types/bledevicestatus.js.map +1 -0
  120. package/dist/types/devicelist.d.ts +89 -0
  121. package/dist/types/devicelist.d.ts.map +1 -0
  122. package/dist/types/devicelist.js +6 -0
  123. package/dist/types/devicelist.js.map +1 -0
  124. package/dist/types/deviceresponse.d.ts +13 -0
  125. package/dist/types/deviceresponse.d.ts.map +1 -0
  126. package/dist/types/deviceresponse.js +2 -0
  127. package/dist/types/deviceresponse.js.map +1 -0
  128. package/dist/types/devicestatus.d.ts +149 -0
  129. package/dist/types/devicestatus.d.ts.map +1 -0
  130. package/dist/types/devicestatus.js +3 -0
  131. package/dist/types/devicestatus.js.map +1 -0
  132. package/dist/types/devicewebhookstatus.d.ts +156 -0
  133. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  134. package/dist/types/devicewebhookstatus.js +2 -0
  135. package/dist/types/devicewebhookstatus.js.map +1 -0
  136. package/dist/types/irdevicelist.d.ts +10 -0
  137. package/dist/types/irdevicelist.d.ts.map +1 -0
  138. package/dist/types/irdevicelist.js +2 -0
  139. package/dist/types/irdevicelist.js.map +1 -0
  140. package/dist/types/pushbody.d.ts +6 -0
  141. package/dist/types/pushbody.d.ts.map +1 -0
  142. package/dist/types/pushbody.js +2 -0
  143. package/dist/types/pushbody.js.map +1 -0
  144. package/dist/utils.d.ts +25 -0
  145. package/dist/utils.d.ts.map +1 -1
  146. package/dist/utils.js +28 -0
  147. package/dist/utils.js.map +1 -1
  148. package/package.json +10 -10
  149. package/src/device/blindtilt.ts +223 -263
  150. package/src/device/bot.ts +208 -221
  151. package/src/device/ceilinglight.ts +210 -257
  152. package/src/device/colorbulb.ts +334 -397
  153. package/src/device/contact.ts +111 -146
  154. package/src/device/curtain.ts +220 -283
  155. package/src/device/device.ts +194 -245
  156. package/src/device/fan.ts +214 -230
  157. package/src/device/hub.ts +126 -246
  158. package/src/device/humidifier.ts +216 -243
  159. package/src/device/iosensor.ts +114 -166
  160. package/src/device/lightstrip.ts +302 -377
  161. package/src/device/lock.ts +187 -221
  162. package/src/device/meter.ts +116 -177
  163. package/src/device/meterplus.ts +117 -174
  164. package/src/device/motion.ts +99 -144
  165. package/src/device/plug.ts +110 -128
  166. package/src/device/robotvacuumcleaner.ts +189 -252
  167. package/src/device/waterdetector.ts +120 -138
  168. package/src/irdevice/airconditioner.ts +2 -1
  169. package/src/irdevice/airpurifier.ts +2 -1
  170. package/src/irdevice/camera.ts +2 -1
  171. package/src/irdevice/fan.ts +2 -1
  172. package/src/irdevice/irdevice.ts +3 -2
  173. package/src/irdevice/light.ts +2 -1
  174. package/src/irdevice/other.ts +2 -1
  175. package/src/irdevice/tv.ts +2 -1
  176. package/src/irdevice/vacuumcleaner.ts +2 -1
  177. package/src/irdevice/waterheater.ts +2 -1
  178. package/src/platform.ts +52 -34
  179. package/src/settings.ts +30 -239
  180. package/src/types/bledevicestatus.ts +305 -0
  181. package/src/types/devicelist.ts +124 -0
  182. package/src/types/deviceresponse.ts +15 -0
  183. package/src/types/devicestatus.ts +178 -0
  184. package/src/types/devicewebhookstatus.ts +196 -0
  185. package/src/types/irdevicelist.ts +15 -0
  186. package/src/types/pushbody.ts +9 -0
  187. package/src/utils.ts +33 -0
@@ -3,9 +3,9 @@
3
3
  * blindtilt.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
- import { interval, Subject } from 'rxjs';
7
6
  import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
8
- import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
7
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
8
+ import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
9
9
  /**
10
10
  * Platform Accessory
11
11
  * An instance of this class is created for each accessory your platform registers
@@ -46,7 +46,7 @@ export class ColorBulb extends deviceBase {
46
46
  accessory.removeService(this.LightBulb.Service);
47
47
  this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
48
48
  accessory.context.adaptiveLighting = false;
49
- this.debugLog(`${device.deviceType}: ${accessory.displayName} adaptiveLighting: ${accessory.context.adaptiveLighting}`);
49
+ this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`);
50
50
  }
51
51
  if (this.adaptiveLightingShift !== -1) {
52
52
  this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
@@ -115,14 +115,14 @@ export class ColorBulb extends deviceBase {
115
115
  this.refreshStatus();
116
116
  // Update Homekit
117
117
  this.updateHomeKitCharacteristics();
118
+ //regisiter webhook event handler
119
+ this.registerWebhook();
118
120
  // Start an update interval
119
121
  interval(this.deviceRefreshRate * 1000)
120
122
  .pipe(skipWhile(() => this.colorBulbUpdateInProgress))
121
123
  .subscribe(async () => {
122
124
  await this.refreshStatus();
123
125
  });
124
- //regisiter webhook event handler
125
- this.registerWebhook(accessory, device);
126
126
  // Watch for Bulb change events
127
127
  // We put in a debounce of 100ms so we don't make duplicate calls
128
128
  this.doColorBulbUpdate
@@ -134,9 +134,8 @@ export class ColorBulb extends deviceBase {
134
134
  await this.pushChanges();
135
135
  }
136
136
  catch (e) {
137
- this.apiError(e);
138
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
139
- + ` Error Message: ${JSON.stringify(e.message)}`);
137
+ await this.apiError(e);
138
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
140
139
  }
141
140
  this.colorBulbUpdateInProgress = false;
142
141
  });
@@ -145,86 +144,59 @@ export class ColorBulb extends deviceBase {
145
144
  * Parse the device status from the SwitchBotBLE API
146
145
  */
147
146
  async BLEparseStatus(serviceData) {
148
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
149
- // State
150
- switch (serviceData.power) {
151
- case true:
152
- this.LightBulb.On = true;
153
- break;
154
- default:
155
- this.LightBulb.On = false;
156
- }
157
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
147
+ await this.debugLog('BLEparseStatus');
148
+ // On
149
+ this.LightBulb.On = serviceData.power;
150
+ await this.debugLog(`On: ${this.LightBulb.On}`);
158
151
  // Brightness
159
- this.LightBulb.Brightness = Number(serviceData.brightness);
160
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
152
+ this.LightBulb.Brightness = serviceData.brightness;
153
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
161
154
  // Color, Hue & Brightness
162
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${serviceData.red}`);
163
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${serviceData.green}`);
164
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${serviceData.blue}`);
165
- const [hue, saturation] = rgb2hs(Number(serviceData.red), Number(serviceData.green), Number(serviceData.blue));
166
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
167
- + ` hs: ${JSON.stringify(rgb2hs(Number(serviceData.red), Number(serviceData.green), Number(serviceData.blue)))}`);
155
+ await this.debugLog(`red: ${serviceData.red}, green: ${serviceData.green}, blue: ${serviceData.blue}`);
156
+ const [hue, saturation] = rgb2hs(serviceData.red, serviceData.green, serviceData.blue);
157
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(serviceData.red, serviceData.green, serviceData.blue))}`);
168
158
  // Hue
169
159
  this.LightBulb.Hue = hue;
170
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
160
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
171
161
  // Saturation
172
162
  this.LightBulb.Saturation = saturation;
173
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
163
+ await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
174
164
  // ColorTemperature
175
- if (serviceData.color_temperature) {
176
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${serviceData.color_temperature}`);
177
- this.LightBulb.ColorTemperature = serviceData.color_temperature;
178
- this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
179
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
180
- }
165
+ this.LightBulb.ColorTemperature = Math.max(Math.min(serviceData.color_temperature, 500), 140);
166
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
181
167
  }
182
168
  /**
183
169
  * Parse the device status from the SwitchBot OpenAPI
184
170
  */
185
171
  async openAPIparseStatus(deviceStatus) {
186
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
187
- switch (deviceStatus.body.power) {
188
- case 'on':
189
- this.LightBulb.On = true;
190
- break;
191
- default:
192
- this.LightBulb.On = false;
193
- }
194
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
172
+ await this.debugLog('openAPIparseStatus');
173
+ // On
174
+ this.LightBulb.On = deviceStatus.power === 'on' ? true : false;
175
+ await this.debugLog(`On: ${this.LightBulb.On}`);
195
176
  // Brightness
196
- this.LightBulb.Brightness = Number(deviceStatus.body.brightness);
197
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
177
+ this.LightBulb.Brightness = deviceStatus.brightness;
178
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
198
179
  // Color, Hue & Brightness
199
- if (deviceStatus.body.color) {
200
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(deviceStatus.body.color)}`);
201
- const [red, green, blue] = deviceStatus.body.color.split(':');
202
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
203
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
204
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
205
- const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
206
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
207
- + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
208
- // Hue
209
- this.LightBulb.Hue = hue;
210
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
211
- // Saturation
212
- this.LightBulb.Saturation = saturation;
213
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
214
- }
180
+ await this.debugLog(`color: ${JSON.stringify(deviceStatus.color)}`);
181
+ const [red, green, blue] = deviceStatus.color.split(':');
182
+ await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
183
+ const [hue, saturation] = rgb2hs(red, green, blue);
184
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
185
+ // Hue
186
+ this.LightBulb.Hue = hue;
187
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
188
+ // Saturation
189
+ this.LightBulb.Saturation = saturation;
190
+ await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
215
191
  // ColorTemperature
216
- if (!Number.isNaN(deviceStatus.body.colorTemperature)) {
217
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${deviceStatus.body.colorTemperature}`);
218
- const mired = Math.round(1000000 / deviceStatus.body.colorTemperature);
219
- this.LightBulb.ColorTemperature = Number(mired);
220
- this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
221
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
222
- }
192
+ const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
193
+ this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
194
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
223
195
  // Firmware Version
224
- const version = deviceStatus.body.version?.toString();
225
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
226
- if (deviceStatus.body.version) {
227
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
196
+ const version = deviceStatus.version.toString();
197
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
198
+ if (deviceStatus.version) {
199
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
228
200
  this.accessory
229
201
  .getService(this.hap.Service.AccessoryInformation)
230
202
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -232,15 +204,42 @@ export class ColorBulb extends deviceBase {
232
204
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
233
205
  .updateValue(deviceVersion);
234
206
  this.accessory.context.deviceVersion = deviceVersion;
235
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
207
+ await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
236
208
  }
237
209
  }
210
+ async parseStatusWebhook(context) {
211
+ await this.debugLog('parseStatusWebhook');
212
+ await this.debugLog(`(powerState, brightness, color, colorTemperature) = Webhook:(${context.powerState}, ${context.brightness}, ${context.color},`
213
+ + ` ${context.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
214
+ + ` ${this.LightBulb.Saturation}, ${this.LightBulb.ColorTemperature})`);
215
+ // On
216
+ this.LightBulb.On = context.powerState === 'ON' ? true : false;
217
+ await this.debugLog(`On: ${this.LightBulb.On}`);
218
+ // Brightness
219
+ this.LightBulb.Brightness = context.brightness;
220
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
221
+ // Color, Hue & Brightness
222
+ await this.debugLog(`color: ${JSON.stringify(context.color)}`);
223
+ const [red, green, blue] = context.color.split(':');
224
+ await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
225
+ const [hue, saturation] = rgb2hs(red, green, blue);
226
+ await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
227
+ // Hue
228
+ this.LightBulb.Hue = hue;
229
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
230
+ // Saturation
231
+ this.LightBulb.Saturation = saturation;
232
+ await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
233
+ // ColorTemperature
234
+ this.LightBulb.ColorTemperature = context.colorTemperature;
235
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
236
+ }
238
237
  /**
239
238
  * Asks the SwitchBot API for the latest device information
240
239
  */
241
240
  async refreshStatus() {
242
241
  if (!this.device.enableCloudService && this.OpenAPI) {
243
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
242
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
244
243
  }
245
244
  else if (this.BLE) {
246
245
  await this.BLERefreshStatus();
@@ -250,12 +249,11 @@ export class ColorBulb extends deviceBase {
250
249
  }
251
250
  else {
252
251
  await this.offlineOff();
253
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
254
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
252
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
255
253
  }
256
254
  }
257
255
  async BLERefreshStatus() {
258
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
256
+ await this.debugLog('BLERefreshStatus');
259
257
  const switchbot = await this.switchbotBLE();
260
258
  if (switchbot === undefined) {
261
259
  await this.BLERefreshConnection(switchbot);
@@ -266,107 +264,55 @@ export class ColorBulb extends deviceBase {
266
264
  // Start to monitor advertisement packets
267
265
  const serviceData = await this.monitorAdvertisementPackets(switchbot);
268
266
  // Update HomeKit
269
- if (serviceData.model !== '' && serviceData.modelName !== '') {
267
+ if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
270
268
  await this.BLEparseStatus(serviceData);
271
269
  await this.updateHomeKitCharacteristics();
272
270
  }
273
271
  else {
274
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
272
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
275
273
  await this.BLERefreshConnection(switchbot);
276
274
  }
277
275
  })();
278
276
  }
279
277
  }
280
278
  async openAPIRefreshStatus() {
281
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
279
+ await this.debugLog('openAPIRefreshStatus');
282
280
  try {
283
281
  const { body, statusCode } = await this.deviceRefreshStatus();
284
282
  const deviceStatus = await body.json();
285
- await this.refreshStatusCodes(statusCode, deviceStatus);
283
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
286
284
  ;
287
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
288
- await this.successfulRefreshStatus(statusCode, deviceStatus);
289
- await this.openAPIparseStatus(deviceStatus);
285
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
286
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
287
+ await this.openAPIparseStatus(deviceStatus.body);
290
288
  await this.updateHomeKitCharacteristics();
291
289
  }
292
290
  else {
293
- await this.statusCodes(statusCode, deviceStatus);
291
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
292
+ await this.debugWarnLog(statusCode, deviceStatus);
294
293
  }
295
294
  }
296
295
  catch (e) {
297
296
  await this.apiError(e);
298
- await this.openAPIRefreshError(e);
297
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
299
298
  }
300
299
  }
301
- async registerWebhook(accessory, device) {
302
- if (device.webhook) {
303
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
304
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
300
+ async registerWebhook() {
301
+ if (this.device.webhook) {
302
+ await this.debugLog('is listening webhook.');
303
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
305
304
  try {
306
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
307
- const { powerState, brightness, color, colorTemperature } = context;
308
- const { On, Brightness, Hue, Saturation, ColorTemperature } = this.LightBulb;
309
- this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
310
- '(powerState, brightness, color, colorTemperature) = ' +
311
- `Webhook:(${powerState}, ${brightness}, ${color}, ${colorTemperature}), `
312
- + `current:(${On}, ${Brightness}, ${Hue}, ${Saturation}, ${ColorTemperature})`);
313
- // On
314
- this.LightBulb.On = powerState === 'ON' ? true : false;
315
- if (accessory.context.Brightness !== this.LightBulb.On) {
316
- this.infoLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
317
- }
318
- else {
319
- this.debugLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
320
- }
321
- // Brightness
322
- this.LightBulb.Brightness = brightness;
323
- if (accessory.context.Brightness !== this.LightBulb.Brightness) {
324
- this.infoLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
325
- }
326
- else {
327
- this.debugLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
328
- }
329
- this.debugLog(`${device.deviceType}: ${accessory.displayName} color: ${JSON.stringify(color)}`);
330
- const [red, green, blue] = color.split(':');
331
- this.debugLog(`${device.deviceType}: ${accessory.displayName} red: ${JSON.stringify(red)}`);
332
- this.debugLog(`${device.deviceType}: ${accessory.displayName} green: ${JSON.stringify(green)}`);
333
- this.debugLog(`${device.deviceType}: ${accessory.displayName} blue: ${JSON.stringify(blue)}`);
334
- const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
335
- this.debugLog(`${device.deviceType}: ${accessory.displayName}`
336
- + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
337
- // Hue
338
- this.LightBulb.Hue = hue;
339
- if (accessory.context.Hue !== this.LightBulb.Hue) {
340
- this.infoLog(`${device.deviceType}: ${accessory.displayName} Hue: ${this.LightBulb.Hue}`);
341
- }
342
- else {
343
- this.debugLog(`${device.deviceType}: ${accessory.displayName} Hue: ${this.LightBulb.Hue}`);
344
- }
345
- // Saturation
346
- this.LightBulb.Saturation = saturation;
347
- if (accessory.context.Saturation !== this.LightBulb.Saturation) {
348
- this.infoLog(`${device.deviceType}: ${accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
349
- }
350
- else {
351
- this.debugLog(`${device.deviceType}: ${accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
352
- }
353
- this.LightBulb.ColorTemperature = colorTemperature;
354
- if (accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
355
- this.infoLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
356
- }
357
- else {
358
- this.debugLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
359
- }
360
- this.updateHomeKitCharacteristics();
305
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
306
+ await this.parseStatusWebhook(context);
307
+ await this.updateHomeKitCharacteristics();
361
308
  }
362
309
  catch (e) {
363
- this.errorLog(`${device.deviceType}: ${accessory.displayName} `
364
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
310
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
365
311
  }
366
312
  };
367
313
  }
368
314
  else {
369
- this.debugWarnLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
315
+ await this.debugLog('is not listening webhook.');
370
316
  }
371
317
  }
372
318
  /**
@@ -382,17 +328,45 @@ export class ColorBulb extends deviceBase {
382
328
  */
383
329
  async pushChanges() {
384
330
  if (!this.device.enableCloudService && this.OpenAPI) {
385
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
331
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
386
332
  }
387
333
  else if (this.BLE) {
388
334
  await this.BLEpushChanges();
335
+ if (this.LightBulb.On) {
336
+ // Push Brightness Update
337
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
338
+ await this.BLEpushBrightnessChanges();
339
+ // Push ColorTemperature Update
340
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
341
+ await this.BLEpushColorTemperatureChanges();
342
+ // Push Hue & Saturation Update
343
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
344
+ await this.BLEpushRGBChanges();
345
+ }
346
+ else {
347
+ await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
348
+ }
389
349
  }
390
350
  else if (this.OpenAPI && this.platform.config.credentials?.token) {
391
351
  await this.openAPIpushChanges();
352
+ if (this.LightBulb.On) {
353
+ // Push Brightness Update
354
+ await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
355
+ await this.pushBrightnessChanges();
356
+ // Push ColorTemperature Update
357
+ await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
358
+ await this.pushColorTemperatureChanges();
359
+ // Push Hue & Saturation Update
360
+ await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
361
+ await this.pushHueSaturationChanges();
362
+ }
363
+ else {
364
+ await this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
365
+ }
392
366
  }
393
367
  else {
394
368
  await this.offlineOff();
395
- await this.pushChangeDisabled();
369
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
396
370
  }
397
371
  // Refresh the status from the API
398
372
  interval(15000)
@@ -403,243 +377,218 @@ export class ColorBulb extends deviceBase {
403
377
  });
404
378
  }
405
379
  async BLEpushChanges() {
406
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
380
+ await this.debugLog('BLEpushChanges');
407
381
  if (this.LightBulb.On !== this.accessory.context.On) {
408
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`
409
- + ` On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
410
- const switchbot = await this.platform.connectBLE();
411
- // Convert to BLE Address
382
+ await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
383
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
412
384
  await this.convertBLEAddress();
413
- switchbot
414
- .discover({ model: this.device.bleModel, id: this.device.bleMac })
415
- .then(async (device_list) => {
416
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
417
- return await this.retryBLE({
418
- max: await this.maxRetryBLE(),
419
- fn: async () => {
420
- if (this.LightBulb.On) {
421
- return await device_list[0].turnOn({ id: this.device.bleMac });
422
- }
423
- else {
424
- return await device_list[0].turnOff({ id: this.device.bleMac });
425
- }
426
- },
385
+ if (switchbot !== false) {
386
+ switchbot
387
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
388
+ .then(async (device_list) => {
389
+ await this.infoLog(`On: ${this.LightBulb.On}`);
390
+ return await this.retryBLE({
391
+ max: await this.maxRetryBLE(),
392
+ fn: async () => {
393
+ if (this.LightBulb.On) {
394
+ return await device_list[0].turnOn({ id: this.device.bleMac });
395
+ }
396
+ else {
397
+ return await device_list[0].turnOff({ id: this.device.bleMac });
398
+ }
399
+ },
400
+ });
401
+ })
402
+ .then(async () => {
403
+ await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
404
+ await this.updateHomeKitCharacteristics();
405
+ })
406
+ .catch(async (e) => {
407
+ await this.apiError(e);
408
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
409
+ await this.BLEPushConnection();
427
410
  });
428
- })
429
- .then(() => {
430
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
431
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
432
- + `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
433
- this.LightBulb.On = false;
434
- })
435
- .catch(async (e) => {
436
- this.apiError(e);
437
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
438
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
439
- await this.BLEPushConnection();
440
- });
441
- // Push Brightness Update
442
- if (this.LightBulb.On) {
443
- await this.BLEpushBrightnessChanges();
444
- }
445
- // Push ColorTemperature Update
446
- if (this.LightBulb.On) {
447
- await this.BLEpushColorTemperatureChanges();
448
411
  }
449
- // Push Hue & Saturation Update
450
- if (this.LightBulb.On) {
451
- await this.BLEpushRGBChanges();
412
+ else {
413
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
414
+ await this.BLEPushConnection();
452
415
  }
453
- await this.updateHomeKitCharacteristics();
454
416
  }
455
417
  else {
456
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, On: ${this.LightBulb.On},`
457
- + ` OnCached: ${this.accessory.context.On}`);
418
+ await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
458
419
  }
459
420
  }
460
421
  async BLEpushBrightnessChanges() {
461
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushBrightnessChanges`);
422
+ await this.debugLog('BLEpushBrightnessChanges');
462
423
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
463
- const switchbot = await this.platform.connectBLE();
464
- // Convert to BLE Address
424
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
465
425
  await this.convertBLEAddress();
466
- switchbot
467
- .discover({ model: this.device.bleModel, id: this.device.bleMac })
468
- .then(async (device_list) => {
469
- this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.LightBulb.Brightness}`);
470
- return await device_list[0].setBrightness(this.LightBulb.Brightness);
471
- })
472
- .then(() => {
473
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
474
- this.LightBulb.On = false;
475
- })
476
- .catch(async (e) => {
477
- this.apiError(e);
478
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
479
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
426
+ if (switchbot !== false) {
427
+ switchbot
428
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
429
+ .then(async (device_list) => {
430
+ await this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.LightBulb.Brightness}`);
431
+ return await device_list[0].setBrightness(this.LightBulb.Brightness);
432
+ })
433
+ .then(async () => {
434
+ await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`);
435
+ await this.updateHomeKitCharacteristics();
436
+ })
437
+ .catch(async (e) => {
438
+ await this.apiError(e);
439
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
440
+ await this.BLEPushConnection();
441
+ });
442
+ }
443
+ else {
444
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
480
445
  await this.BLEPushConnection();
481
- });
446
+ }
482
447
  }
483
448
  else {
484
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.`
485
- + `Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
449
+ await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
450
+ + ` BrightnessCached: ${this.accessory.context.Brightness}`);
486
451
  }
487
452
  }
488
453
  async BLEpushColorTemperatureChanges() {
489
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushColorTemperatureChanges`);
454
+ await this.debugLog('BLEpushColorTemperatureChanges');
490
455
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
491
- const switchbot = await this.platform.connectBLE();
492
- // Convert to BLE Address
456
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
493
457
  await this.convertBLEAddress();
494
- switchbot
495
- .discover({ model: this.device.bleModel, id: this.device.bleMac })
496
- .then(async (device_list) => {
497
- this.infoLog(`${this.accessory.displayName} Target ColorTemperature: ${this.LightBulb.ColorTemperature}`);
498
- return await device_list[0].setColorTemperature(this.LightBulb.ColorTemperature);
499
- })
500
- .then(() => {
501
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
502
- this.LightBulb.On = false;
503
- })
504
- .catch(async (e) => {
505
- this.apiError(e);
506
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with `
507
- + `${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
458
+ if (switchbot !== false) {
459
+ switchbot
460
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
461
+ .then(async (device_list) => {
462
+ await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
463
+ return await device_list[0].setColorTemperature(this.LightBulb.ColorTemperature);
464
+ })
465
+ .then(async () => {
466
+ await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`);
467
+ await this.updateHomeKitCharacteristics();
468
+ })
469
+ .catch(async (e) => {
470
+ await this.apiError(e);
471
+ await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection,`
472
+ + ` Error Message: ${JSON.stringify(e.message)}`);
473
+ await this.BLEPushConnection();
474
+ });
475
+ }
476
+ else {
477
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
508
478
  await this.BLEPushConnection();
509
- });
479
+ }
510
480
  }
511
481
  else {
512
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.`
513
- + `ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
482
+ await this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
483
+ + ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
514
484
  }
515
485
  }
516
486
  async BLEpushRGBChanges() {
517
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
518
- if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
519
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
520
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
521
- const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
522
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
523
- const switchbot = await this.platform.connectBLE();
524
- // Convert to BLE Address
487
+ await this.debugLog('BLEpushRGBChanges');
488
+ if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
489
+ await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
490
+ const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
491
+ await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
492
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
525
493
  await this.convertBLEAddress();
526
- switchbot
527
- .discover({ model: this.device.bleModel, id: this.device.bleMac })
528
- .then(async (device_list) => {
529
- this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
530
- return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
531
- })
532
- .then(() => {
533
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
534
- this.LightBulb.On = false;
535
- })
536
- .catch(async (e) => {
537
- this.apiError(e);
538
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
539
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
494
+ if (switchbot !== false) {
495
+ switchbot
496
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
497
+ .then(async (device_list) => {
498
+ await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
499
+ return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
500
+ })
501
+ .then(async () => {
502
+ await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`);
503
+ await this.updateHomeKitCharacteristics();
504
+ })
505
+ .catch(async (e) => {
506
+ await this.apiError(e);
507
+ await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection,`
508
+ + ` Error Message: ${JSON.stringify(e.message)}`);
509
+ await this.BLEPushConnection();
510
+ });
511
+ }
512
+ else {
513
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
540
514
  await this.BLEPushConnection();
541
- });
515
+ }
542
516
  }
543
517
  else {
544
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.LightBulb.Hue}, HueCached: `
545
- + `${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
518
+ await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
519
+ + ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
546
520
  }
547
521
  }
548
522
  async openAPIpushChanges() {
549
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
523
+ await this.debugLog('openAPIpushChanges');
550
524
  if (this.LightBulb.On !== this.accessory.context.On) {
551
- let command = '';
552
- if (this.LightBulb.On) {
553
- command = 'turnOn';
554
- }
555
- else {
556
- command = 'turnOff';
557
- }
525
+ const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
558
526
  const bodyChange = JSON.stringify({
559
527
  command: `${command}`,
560
528
  parameter: 'default',
561
529
  commandType: 'command',
562
530
  });
563
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
531
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
564
532
  try {
565
533
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
566
534
  const deviceStatus = await body.json();
567
- await this.pushStatusCodes(statusCode, deviceStatus);
568
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
569
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
570
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
571
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
572
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
535
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
536
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
537
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
538
+ await this.updateHomeKitCharacteristics();
573
539
  }
574
540
  else {
575
- this.statusCode(statusCode);
576
- this.statusCode(deviceStatus.statusCode);
541
+ await this.statusCode(statusCode);
542
+ await this.statusCode(deviceStatus.statusCode);
577
543
  }
578
544
  }
579
545
  catch (e) {
580
- this.apiError(e);
581
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
582
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
546
+ await this.apiError(e);
547
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
583
548
  }
584
549
  }
585
550
  else {
586
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges,`
587
- + `On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
588
- }
589
- // Push Hue & Saturation Update
590
- if (this.LightBulb.On) {
591
- await this.pushHueSaturationChanges();
592
- }
593
- // Push ColorTemperature Update
594
- if (this.LightBulb.On) {
595
- await this.pushColorTemperatureChanges();
596
- }
597
- // Push Brightness Update
598
- if (this.LightBulb.On) {
599
- await this.pushBrightnessChanges();
551
+ await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
600
552
  }
601
553
  }
602
554
  async pushHueSaturationChanges() {
603
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
604
- if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
605
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
606
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
607
- const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
608
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
555
+ await this.debugLog('pushHueSaturationChanges');
556
+ if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
557
+ await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
558
+ const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
559
+ await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
609
560
  const bodyChange = JSON.stringify({
610
561
  command: 'setColor',
611
562
  parameter: `${red}:${green}:${blue}`,
612
563
  commandType: 'command',
613
564
  });
614
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
565
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
615
566
  try {
616
567
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
617
568
  const deviceStatus = await body.json();
618
- await this.pushStatusCodes(statusCode, deviceStatus);
619
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
620
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
621
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
622
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
623
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
569
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
570
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
571
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
572
+ await this.updateHomeKitCharacteristics();
624
573
  }
625
574
  else {
626
- this.statusCode(statusCode);
627
- this.statusCode(deviceStatus.statusCode);
575
+ await this.statusCode(statusCode);
576
+ await this.statusCode(deviceStatus.statusCode);
628
577
  }
629
578
  }
630
579
  catch (e) {
631
- this.apiError(e);
632
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
633
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
580
+ await this.apiError(e);
581
+ await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
582
+ + ` Error Message: ${JSON.stringify(e.message)}`);
634
583
  }
635
584
  }
636
585
  else {
637
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.LightBulb.Hue}, HueCached: `
638
- + `${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
586
+ await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
587
+ + ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
639
588
  }
640
589
  }
641
590
  async pushColorTemperatureChanges() {
642
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
591
+ await this.debugLog('pushColorTemperatureChanges');
643
592
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
644
593
  const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
645
594
  this.accessory.context.kelvin = kelvin;
@@ -648,77 +597,73 @@ export class ColorBulb extends deviceBase {
648
597
  parameter: `${kelvin}`,
649
598
  commandType: 'command',
650
599
  });
651
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
600
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
652
601
  try {
653
602
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
654
603
  const deviceStatus = await body.json();
655
- await this.pushStatusCodes(statusCode, deviceStatus);
656
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
657
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
658
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
659
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
660
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
604
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
605
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
606
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
607
+ await this.updateHomeKitCharacteristics();
661
608
  }
662
609
  else {
663
- this.statusCode(statusCode);
664
- this.statusCode(deviceStatus.statusCode);
610
+ await this.statusCode(statusCode);
611
+ await this.statusCode(deviceStatus.statusCode);
665
612
  }
666
613
  }
667
614
  catch (e) {
668
- this.apiError(e);
669
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
670
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
615
+ await this.apiError(e);
616
+ await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection,`
617
+ + ` Error Message: ${JSON.stringify(e.message)}`);
671
618
  }
672
619
  }
673
620
  else {
674
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.`
675
- + `ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
621
+ await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
622
+ + ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
676
623
  }
677
624
  }
678
625
  async pushBrightnessChanges() {
679
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
626
+ await this.debugLog('pushBrightnessChanges');
680
627
  if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
681
628
  const bodyChange = JSON.stringify({
682
629
  command: 'setBrightness',
683
630
  parameter: `${this.LightBulb.Brightness}`,
684
631
  commandType: 'command',
685
632
  });
686
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
633
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
687
634
  try {
688
635
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
689
636
  const deviceStatus = await body.json();
690
- await this.pushStatusCodes(statusCode, deviceStatus);
691
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
692
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
693
- + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
694
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
695
- + `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
637
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
638
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
639
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
640
+ await this.updateHomeKitCharacteristics();
696
641
  }
697
642
  else {
698
- this.statusCode(statusCode);
699
- this.statusCode(deviceStatus.statusCode);
643
+ await this.statusCode(statusCode);
644
+ await this.statusCode(deviceStatus.statusCode);
700
645
  }
701
646
  }
702
647
  catch (e) {
703
- this.apiError(e);
704
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
705
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
648
+ await this.apiError(e);
649
+ await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
650
+ + ` Error Message: ${JSON.stringify(e.message)}`);
706
651
  }
707
652
  }
708
653
  else {
709
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.`
710
- + `Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
654
+ await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
655
+ + ` BrightnessCached: ${this.accessory.context.Brightness}`);
711
656
  }
712
657
  }
713
658
  /**
714
659
  * Handle requests to set the value of the "On" characteristic
715
660
  */
716
661
  async OnSet(value) {
717
- if (this.LightBulb.On === this.accessory.context.On) {
718
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
662
+ if (this.LightBulb.On !== this.accessory.context.On) {
663
+ await this.infoLog(`Set On: ${value}`);
719
664
  }
720
665
  else {
721
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
666
+ await this.debugLog(`No Changes, On: ${value}`);
722
667
  }
723
668
  this.LightBulb.On = value;
724
669
  this.doColorBulbUpdate.next();
@@ -727,14 +672,16 @@ export class ColorBulb extends deviceBase {
727
672
  * Handle requests to set the value of the "Brightness" characteristic
728
673
  */
729
674
  async BrightnessSet(value) {
730
- if (this.LightBulb.Brightness === this.accessory.context.Brightness) {
731
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
732
- }
733
- else if (this.LightBulb.On) {
734
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
675
+ if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
676
+ await this.infoLog(`Set Brightness: ${value}`);
735
677
  }
736
678
  else {
737
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
679
+ if (this.LightBulb.On) {
680
+ this.debugLog(`No Changes, Brightness: ${value}`);
681
+ }
682
+ else {
683
+ this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`);
684
+ }
738
685
  }
739
686
  this.LightBulb.Brightness = value;
740
687
  this.doColorBulbUpdate.next();
@@ -743,14 +690,16 @@ export class ColorBulb extends deviceBase {
743
690
  * Handle requests to set the value of the "ColorTemperature" characteristic
744
691
  */
745
692
  async ColorTemperatureSet(value) {
746
- if (this.LightBulb.ColorTemperature === this.accessory.context.ColorTemperature) {
747
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
748
- }
749
- else if (this.LightBulb.On) {
750
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
693
+ if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
694
+ this.infoLog(`Set ColorTemperature: ${value}`);
751
695
  }
752
696
  else {
753
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
697
+ if (this.LightBulb.On) {
698
+ this.debugLog(`No Changes, ColorTemperature: ${value}`);
699
+ }
700
+ else {
701
+ this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`);
702
+ }
754
703
  }
755
704
  const minKelvin = 2000;
756
705
  const maxKelvin = 9000;
@@ -772,14 +721,16 @@ export class ColorBulb extends deviceBase {
772
721
  * Handle requests to set the value of the "Hue" characteristic
773
722
  */
774
723
  async HueSet(value) {
775
- if (this.LightBulb.Hue === this.accessory.context.Hue) {
776
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
777
- }
778
- else if (this.LightBulb.On) {
779
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
724
+ if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
725
+ this.infoLog(`Set Hue: ${value}`);
780
726
  }
781
727
  else {
782
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
728
+ if (this.LightBulb.On) {
729
+ this.debugLog(`No Changes, Hue: ${value}`);
730
+ }
731
+ else {
732
+ this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`);
733
+ }
783
734
  }
784
735
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
785
736
  this.LightBulb.Hue = value;
@@ -789,14 +740,16 @@ export class ColorBulb extends deviceBase {
789
740
  * Handle requests to set the value of the "Saturation" characteristic
790
741
  */
791
742
  async SaturationSet(value) {
792
- if (this.LightBulb.Saturation === this.accessory.context.Saturation) {
793
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
794
- }
795
- else if (this.LightBulb.On) {
796
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
743
+ if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
744
+ this.infoLog(`Set Saturation: ${value}`);
797
745
  }
798
746
  else {
799
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
747
+ if (this.LightBulb.On) {
748
+ this.debugLog(`No Changes, Saturation: ${value}`);
749
+ }
750
+ else {
751
+ this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`);
752
+ }
800
753
  }
801
754
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
802
755
  this.LightBulb.Saturation = value;
@@ -817,24 +770,22 @@ export class ColorBulb extends deviceBase {
817
770
  async adaptiveLighting(device) {
818
771
  if (device.colorbulb?.adaptiveLightingShift) {
819
772
  this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
820
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
821
773
  }
822
774
  else {
823
775
  this.adaptiveLightingShift = 0;
824
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
825
776
  }
777
+ await this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
826
778
  }
827
779
  async BLEPushConnection() {
828
780
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
829
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
781
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
830
782
  await this.openAPIpushChanges();
831
783
  }
832
784
  }
833
785
  async BLERefreshConnection(switchbot) {
834
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
835
- + ` ${JSON.stringify(switchbot)}`);
786
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
836
787
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
837
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
788
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
838
789
  await this.openAPIRefreshStatus();
839
790
  }
840
791
  }
@@ -843,7 +794,7 @@ export class ColorBulb extends deviceBase {
843
794
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
844
795
  }
845
796
  }
846
- apiError(e) {
797
+ async apiError(e) {
847
798
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
848
799
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
849
800
  this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);