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