@switchbot/homebridge-switchbot 2.0.0-beta.8 → 2.0.0

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 (120) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +3 -2
  3. package/config.schema.json +91 -19
  4. package/dist/device/bot.d.ts +34 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +657 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +137 -0
  9. package/dist/device/ceilinglight.d.ts.map +1 -0
  10. package/dist/device/ceilinglight.js +1127 -0
  11. package/dist/device/ceilinglight.js.map +1 -0
  12. package/dist/device/colorbulb.d.ts +36 -19
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +486 -309
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.d.ts +18 -8
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +306 -237
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +23 -16
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +566 -502
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.d.ts +24 -18
  25. package/dist/device/humidifier.d.ts.map +1 -1
  26. package/dist/device/humidifier.js +453 -369
  27. package/dist/device/humidifier.js.map +1 -1
  28. package/dist/device/lock.d.ts +27 -8
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +305 -148
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.d.ts +22 -16
  33. package/dist/device/meter.d.ts.map +1 -1
  34. package/dist/device/meter.js +367 -267
  35. package/dist/device/meter.js.map +1 -1
  36. package/dist/device/meterplus.d.ts +24 -12
  37. package/dist/device/meterplus.d.ts.map +1 -1
  38. package/dist/device/meterplus.js +381 -213
  39. package/dist/device/meterplus.js.map +1 -1
  40. package/dist/device/motion.d.ts +18 -8
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +279 -216
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts +27 -17
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +295 -251
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/striplight.d.ts +43 -19
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +506 -262
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airconditioner.d.ts +9 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +278 -230
  55. package/dist/irdevice/airconditioner.js.map +1 -1
  56. package/dist/irdevice/airpurifier.d.ts +5 -3
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +154 -104
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts +11 -8
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +133 -86
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts +10 -7
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +160 -109
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts +11 -8
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +137 -103
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +11 -8
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +145 -98
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts +12 -9
  77. package/dist/irdevice/tv.d.ts.map +1 -1
  78. package/dist/irdevice/tv.js +143 -93
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +9 -10
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/vacuumcleaner.js +132 -89
  83. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  84. package/dist/irdevice/waterheater.d.ts +8 -9
  85. package/dist/irdevice/waterheater.d.ts.map +1 -1
  86. package/dist/irdevice/waterheater.js +132 -89
  87. package/dist/irdevice/waterheater.js.map +1 -1
  88. package/dist/platform.d.ts +13 -12
  89. package/dist/platform.d.ts.map +1 -1
  90. package/dist/platform.js +524 -418
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +19 -11
  93. package/dist/settings.d.ts.map +1 -1
  94. package/dist/settings.js.map +1 -1
  95. package/homebridge-ui/public/index.html +1 -0
  96. package/package.json +11 -9
  97. package/src/device/bot.ts +656 -659
  98. package/src/device/ceilinglight.ts +1208 -0
  99. package/src/device/colorbulb.ts +490 -344
  100. package/src/device/contact.ts +309 -241
  101. package/src/device/curtain.ts +571 -516
  102. package/src/device/humidifier.ts +456 -403
  103. package/src/device/lock.ts +314 -149
  104. package/src/device/meter.ts +378 -280
  105. package/src/device/meterplus.ts +391 -219
  106. package/src/device/motion.ts +285 -222
  107. package/src/device/plug.ts +299 -260
  108. package/src/device/striplight.ts +522 -289
  109. package/src/irdevice/airconditioner.ts +282 -241
  110. package/src/irdevice/airpurifier.ts +151 -103
  111. package/src/irdevice/camera.ts +131 -85
  112. package/src/irdevice/fan.ts +157 -106
  113. package/src/irdevice/light.ts +135 -103
  114. package/src/irdevice/other.ts +143 -97
  115. package/src/irdevice/tv.ts +142 -93
  116. package/src/irdevice/vacuumcleaner.ts +131 -89
  117. package/src/irdevice/waterheater.ts +130 -89
  118. package/src/platform.ts +522 -446
  119. package/src/settings.ts +20 -11
  120. package/.github/npm-version-script.js +0 -81
@@ -3,10 +3,11 @@ import crypto from 'crypto';
3
3
  import { Context } from 'vm';
4
4
  import { IncomingMessage } from 'http';
5
5
  import { interval, Subject } from 'rxjs';
6
+ import superStringify from 'super-stringify';
6
7
  import { SwitchBotPlatform } from '../platform';
7
- import { debounceTime, skipWhile, tap } from 'rxjs/operators';
8
+ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
9
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
9
- import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath, ad, serviceData } from '../settings';
10
+ import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath, ad, serviceData, m2hs } from '../settings';
10
11
 
11
12
  /**
12
13
  * Platform Accessory
@@ -19,13 +20,10 @@ export class StripLight {
19
20
 
20
21
  // Characteristic Values
21
22
  On!: CharacteristicValue;
22
- OnCached!: CharacteristicValue;
23
23
  Hue!: CharacteristicValue;
24
- HueCached!: CharacteristicValue;
25
24
  Saturation!: CharacteristicValue;
26
- SaturationCached!: CharacteristicValue;
27
25
  Brightness!: CharacteristicValue;
28
- BrightnessCached!: CharacteristicValue;
26
+ ColorTemperature?: CharacteristicValue;
29
27
 
30
28
  // OpenAPI Others
31
29
  power: deviceStatus['power'];
@@ -37,7 +35,6 @@ export class StripLight {
37
35
  connected?: boolean;
38
36
  switchbot!: switchbot;
39
37
  address!: ad['address'];
40
- SwitchToOpenAPI?: boolean;
41
38
  serviceData!: serviceData;
42
39
  state: serviceData['state'];
43
40
  delay: serviceData['delay'];
@@ -59,8 +56,12 @@ export class StripLight {
59
56
  cacheKelvin!: number;
60
57
 
61
58
  // Updates
62
- colorBulbUpdateInProgress!: boolean;
63
- doColorBulbUpdate!: Subject<void>;
59
+ stripLightUpdateInProgress!: boolean;
60
+ doStripLightUpdate!: Subject<void>;
61
+
62
+ // Connection
63
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
64
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
64
65
 
65
66
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
66
67
  // default placeholders
@@ -68,19 +69,10 @@ export class StripLight {
68
69
  this.scan(device);
69
70
  this.refreshRate(device);
70
71
  this.config(device);
71
- if (this.On === undefined) {
72
- this.On = false;
73
- } else {
74
- this.On = this.accessory.context.On;
75
- }
76
- this.Hue = 0;
77
- this.Brightness = 0;
78
- this.Saturation = 0;
79
- this.minKelvin = 2000;
80
- this.maxKelvin = 9000;
72
+ this.context();
81
73
  // this is subject we use to track when we need to POST changes to the SwitchBot API
82
- this.doColorBulbUpdate = new Subject();
83
- this.colorBulbUpdateInProgress = false;
74
+ this.doStripLightUpdate = new Subject();
75
+ this.stripLightUpdateInProgress = false;
84
76
 
85
77
  // Retrieve initial values and updateHomekit
86
78
  this.refreshStatus();
@@ -98,7 +90,15 @@ export class StripLight {
98
90
  // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
99
91
  // you can create multiple services for each accessory
100
92
  (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
101
- `${accessory.displayName} Strip Light`;
93
+ `${accessory.displayName} ${device.deviceType}`;
94
+
95
+
96
+ if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
97
+ this.accessory.removeService(this.lightBulbService);
98
+ this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
99
+ this.accessory.context.adaptiveLighting = false;
100
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
101
+ }
102
102
 
103
103
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
104
104
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -125,6 +125,19 @@ export class StripLight {
125
125
  })
126
126
  .onSet(this.BrightnessSet.bind(this));
127
127
 
128
+ // handle ColorTemperature events using the ColorTemperature characteristic
129
+ this.lightBulbService
130
+ .getCharacteristic(this.platform.Characteristic.ColorTemperature)
131
+ .setProps({
132
+ minValue: 140,
133
+ maxValue: 500,
134
+ validValueRanges: [140, 500],
135
+ })
136
+ .onGet(() => {
137
+ return this.ColorTemperature!;
138
+ })
139
+ .onSet(this.ColorTemperatureSet.bind(this));
140
+
128
141
  // handle Hue events using the Hue characteristic
129
142
  this.lightBulbService
130
143
  .getCharacteristic(this.platform.Characteristic.Hue)
@@ -151,22 +164,35 @@ export class StripLight {
151
164
  })
152
165
  .onSet(this.SaturationSet.bind(this));
153
166
 
167
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
168
+ if (this.adaptiveLightingShift !== -1) {
169
+ this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
170
+ customTemperatureAdjustment: this.adaptiveLightingShift,
171
+ });
172
+ this.accessory.configureController(this.AdaptiveLightingController);
173
+ this.accessory.context.adaptiveLighting = true;
174
+ this.debugLog(
175
+ `${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
176
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
177
+ );
178
+ }
179
+
154
180
  // Update Homekit
155
181
  this.updateHomeKitCharacteristics();
156
182
 
157
183
  // Start an update interval
158
184
  interval(this.deviceRefreshRate * 1000)
159
- .pipe(skipWhile(() => this.colorBulbUpdateInProgress))
185
+ .pipe(skipWhile(() => this.stripLightUpdateInProgress))
160
186
  .subscribe(async () => {
161
187
  await this.refreshStatus();
162
188
  });
163
189
 
164
190
  // Watch for Bulb change events
165
- // We put in a debounce of 100ms so we don't make duplicate calls
166
- this.doColorBulbUpdate
191
+ // We put in a debounce of 1000ms so we don't make duplicate calls
192
+ this.doStripLightUpdate
167
193
  .pipe(
168
194
  tap(() => {
169
- this.colorBulbUpdateInProgress = true;
195
+ this.stripLightUpdateInProgress = true;
170
196
  }),
171
197
  debounceTime(this.platform.config.options!.pushRate! * 1000),
172
198
  )
@@ -174,26 +200,37 @@ export class StripLight {
174
200
  try {
175
201
  await this.pushChanges();
176
202
  } catch (e: any) {
177
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges`);
178
- if (this.deviceLogging.includes('debug')) {
179
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
180
- }
181
203
  this.apiError(e);
204
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
205
+ + ` Error Message: ${superStringify(e.message)}`);
182
206
  }
183
- this.colorBulbUpdateInProgress = false;
207
+ this.stripLightUpdateInProgress = false;
208
+ // Refresh the status from the API
209
+ interval(15000)
210
+ .pipe(skipWhile(() => this.stripLightUpdateInProgress))
211
+ .pipe(take(1))
212
+ .subscribe(async () => {
213
+ await this.refreshStatus();
214
+ });
184
215
  });
185
216
  }
186
217
 
218
+ /**
219
+ * Parse the device status from the SwitchBot api
220
+ */
187
221
  async parseStatus(): Promise<void> {
188
- if (this.SwitchToOpenAPI || !this.device.ble) {
222
+ /*if (this.BLE) {
223
+ await this.BLEparseStatus();
224
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
189
225
  await this.openAPIparseStatus();
190
226
  } else {
191
- await this.BLEparseStatus();
227
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
228
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
192
229
  }
193
230
  }
194
231
 
195
232
  async BLEparseStatus(): Promise<void> {
196
- this.debugLog(`Strip Light: ${this.accessory.displayName} BLE parseStatus`);
233
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
197
234
  // State
198
235
  switch (this.state) {
199
236
  case 'on':
@@ -202,10 +239,11 @@ export class StripLight {
202
239
  default:
203
240
  this.On = false;
204
241
  }
205
- this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
242
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
206
243
  }
207
244
 
208
245
  async openAPIparseStatus(): Promise<void> {
246
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
209
247
  switch (this.power) {
210
248
  case 'on':
211
249
  this.On = true;
@@ -213,50 +251,57 @@ export class StripLight {
213
251
  default:
214
252
  this.On = false;
215
253
  }
216
- this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
254
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
217
255
 
218
256
  // Brightness
219
257
  this.Brightness = Number(this.brightness);
220
- this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
258
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
221
259
 
222
260
  // Color, Hue & Brightness
223
261
  if (this.color) {
224
- this.debugLog(`Strip Light: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
262
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${superStringify(this.color)}`);
225
263
  const [red, green, blue] = this.color!.split(':');
226
- this.debugLog(`Strip Light: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
227
- this.debugLog(`Strip Light: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
228
- this.debugLog(`Strip Light: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
264
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${superStringify(red)}`);
265
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${superStringify(green)}`);
266
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${superStringify(blue)}`);
229
267
 
230
268
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
231
- this.debugLog(`Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
269
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
270
+ +` hs: ${superStringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
232
271
 
233
272
  // Hue
234
273
  this.Hue = hue;
235
- this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${this.Hue}`);
274
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
236
275
 
237
276
  // Saturation
238
277
  this.Saturation = saturation;
239
- this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
278
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
240
279
  }
241
280
  }
242
281
 
282
+ /**
283
+ * Asks the SwitchBot API for the latest device information
284
+ */
243
285
  async refreshStatus(): Promise<void> {
244
- if (this.device.ble) {
286
+ /*if (this.BLE) {
245
287
  await this.BLERefreshStatus();
246
- } else {
288
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
247
289
  await this.openAPIRefreshStatus();
290
+ } else {
291
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
292
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
248
293
  }
249
294
  }
250
295
 
251
296
  async BLERefreshStatus(): Promise<void> {
252
- this.debugLog(`Strip Light: ${this.accessory.displayName} BLE refreshStatus`);
297
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
253
298
  const switchbot = await this.platform.connectBLE();
254
299
  // Convert to BLE Address
255
300
  this.device.bleMac = this.device
256
301
  .deviceId!.match(/.{1,2}/g)!
257
302
  .join(':')
258
303
  .toLowerCase();
259
- this.debugLog(`Strip Light: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
304
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
260
305
  this.getCustomBLEAddress(switchbot);
261
306
  // Start to monitor advertisement packets
262
307
  if (switchbot !== false) {
@@ -269,13 +314,9 @@ export class StripLight {
269
314
  // Set an event hander
270
315
  switchbot.onadvertisement = (ad: any) => {
271
316
  this.address = ad.address;
272
- if (this.deviceLogging.includes('debug')) {
273
- this.infoLog(this.address);
274
- this.infoLog(this.device.bleMac);
275
- this.infoLog(`Strip Light: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
276
- this.infoLog(`Strip Light: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
277
- }
278
- this.errorLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
317
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
318
+ + ` BLE Address Found: ${this.address}`);
319
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
279
320
  this.serviceData = ad.serviceData;
280
321
  //this.state = ad.serviceData.state;
281
322
  //this.delay = ad.serviceData.delay;
@@ -284,19 +325,19 @@ export class StripLight {
284
325
  //this.wifiRssi = ad.serviceData.wifiRssi;
285
326
  //this.overload = ad.serviceData.overload;
286
327
  //this.currentPower = ad.serviceData.currentPower;
287
- this.debugLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
328
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
288
329
  /*this.debugLog(
289
- `Strip Light: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
330
+ `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
290
331
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
291
332
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
292
333
  );*/
293
334
 
294
335
  if (this.serviceData) {
295
336
  this.connected = true;
296
- this.debugLog(`Strip Light: ${this.accessory.displayName} connected: ${this.connected}`);
337
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
297
338
  } else {
298
339
  this.connected = false;
299
- this.debugLog(`Strip Light: ${this.accessory.displayName} connected: ${this.connected}`);
340
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
300
341
  }
301
342
  };
302
343
  // Wait 2 seconds
@@ -306,72 +347,32 @@ export class StripLight {
306
347
  // Stop to monitor
307
348
  switchbot.stopScan();
308
349
  if (this.connected) {
309
- this.parseStatus();
350
+ this.BLEparseStatus();
310
351
  this.updateHomeKitCharacteristics();
311
352
  } else {
312
- this.errorLog(`Strip Light: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
313
- if (this.platform.config.credentials?.token) {
314
- this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
315
- this.SwitchToOpenAPI = true;
316
- await this.openAPIRefreshStatus();
317
- }
353
+ await this.BLERefreshConnection(switchbot);
318
354
  }
319
355
  })
320
356
  .catch(async (e: any) => {
321
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
322
- if (this.deviceLogging.includes('debug')) {
323
- this.errorLog(
324
- `Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
325
- );
326
- }
327
- if (this.platform.config.credentials?.token) {
328
- this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
329
- this.SwitchToOpenAPI = true;
330
- await this.openAPIRefreshStatus();
331
- }
332
357
  this.apiError(e);
358
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
359
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
360
+ await this.BLERefreshConnection(switchbot);
333
361
  });
334
362
  } else {
335
- await this.BLEconnection(switchbot);
336
- }
337
- }
338
-
339
- async getCustomBLEAddress(switchbot: any) {
340
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
341
- this.debugLog(`Strip Light: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
342
- (async () => {
343
- // Start to monitor advertisement packets
344
- await switchbot.startScan({
345
- model: 'r',
346
- });
347
- // Set an event handler
348
- switchbot.onadvertisement = (ad: any) => {
349
- this.warnLog(`Strip Light: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
350
- };
351
- await switchbot.wait(10000);
352
- // Stop to monitor
353
- switchbot.stopScan();
354
- })();
355
- }
356
- }
357
-
358
- async BLEconnection(switchbot: any): Promise<void> {
359
- this.errorLog(`Strip Light: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
360
- if (this.platform.config.credentials?.token) {
361
- this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
362
- this.SwitchToOpenAPI = true;
363
- await this.openAPIRefreshStatus();
363
+ await this.BLERefreshConnection(switchbot);
364
364
  }
365
365
  }
366
366
 
367
367
  async openAPIRefreshStatus(): Promise<void> {
368
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
368
369
  try {
369
370
  const t = Date.now();
370
371
  const nonce = 'requestID';
371
372
  const data = this.platform.config.credentials?.token + t + nonce;
372
373
  const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
373
374
  const sign = signTerm.toString('base64');
374
- this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
375
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
375
376
  const options = {
376
377
  hostname: HostDomain,
377
378
  port: 443,
@@ -386,38 +387,35 @@ export class StripLight {
386
387
  },
387
388
  };
388
389
  const req = https.request(options, (res) => {
389
- this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
390
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
391
+ this.statusCode({ res });
390
392
  let rawData = '';
391
393
  res.on('data', (d) => {
392
394
  rawData += d;
393
- this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
395
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
394
396
  });
395
397
  res.on('end', () => {
396
398
  try {
397
399
  this.deviceStatus = JSON.parse(rawData);
398
- this.debugLog(`Strip Light: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
400
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
399
401
  this.power = this.deviceStatus.body.power;
400
402
  this.color = this.deviceStatus.body.color;
401
403
  this.brightness = this.deviceStatus.body.brightness;
402
- this.parseStatus();
404
+ this.openAPIparseStatus();
403
405
  this.updateHomeKitCharacteristics();
404
406
  } catch (e: any) {
405
- this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
407
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
406
408
  }
407
409
  });
408
410
  });
409
411
  req.on('error', (e: any) => {
410
- this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
412
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
411
413
  });
412
414
  req.end();
413
415
  } catch (e: any) {
414
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
415
- if (this.deviceLogging.includes('debug')) {
416
- this.errorLog(
417
- `Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
418
- );
419
- }
420
416
  this.apiError(e);
417
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
418
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
421
419
  }
422
420
  }
423
421
 
@@ -432,8 +430,61 @@ export class StripLight {
432
430
  *
433
431
  */
434
432
  async pushChanges(): Promise<void> {
433
+ /*if (this.BLE) {
434
+ await this.BLEpushChanges();
435
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
436
+ await this.openAPIpushChanges();
437
+ } else {
438
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
439
+ + ` ${this.device.connectionType}, pushChanges will not happen.`);
440
+ }
441
+ interval(5000)
442
+ .pipe(take(1))
443
+ .subscribe(async () => {
444
+ await this.refreshStatus();
445
+ });
446
+ }
447
+
448
+ async BLEpushChanges(): Promise<void> {
449
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
450
+ if (this.On !== this.accessory.context.On) {
451
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
452
+ const switchbot = await this.platform.connectBLE();
453
+ // Convert to BLE Address
454
+ this.device.bleMac = this.device
455
+ .deviceId!.match(/.{1,2}/g)!
456
+ .join(':')
457
+ .toLowerCase();
458
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
459
+ switchbot
460
+ .discover({
461
+ model: 'r',
462
+ id: this.device.bleMac,
463
+ })
464
+ .then((device_list: any) => {
465
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
466
+ return this.turnOnOff(device_list);
467
+ })
468
+ .then(() => {
469
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
470
+ this.On = false;
471
+ })
472
+ .catch(async (e: any) => {
473
+ this.apiError(e);
474
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
475
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
476
+ await this.BLEPushConnection();
477
+ });
478
+ } else {
479
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
480
+ +`OnCached: ${this.accessory.context.On}`);
481
+ }
482
+ }
483
+
484
+ async openAPIpushChanges() {
435
485
  try {
436
- if (this.On !== this.OnCached) {
486
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
487
+ if (this.On !== this.accessory.context.On) {
437
488
  // Make Push On request to the API
438
489
  const t = Date.now();
439
490
  const nonce = 'requestID';
@@ -442,7 +493,7 @@ export class StripLight {
442
493
  .update(Buffer.from(data, 'utf-8'))
443
494
  .digest();
444
495
  const sign = signTerm.toString('base64');
445
- this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
496
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
446
497
 
447
498
  let command = '';
448
499
  if (this.On) {
@@ -450,12 +501,12 @@ export class StripLight {
450
501
  } else {
451
502
  command = 'turnOff';
452
503
  }
453
- const body = JSON.stringify({
504
+ const body = superStringify({
454
505
  'command': `${command}`,
455
506
  'parameter': 'default',
456
507
  'commandType': 'command',
457
508
  });
458
- this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
509
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
459
510
  const options = {
460
511
  hostname: HostDomain,
461
512
  port: 443,
@@ -471,49 +522,49 @@ export class StripLight {
471
522
  },
472
523
  };
473
524
  const req = https.request(options, res => {
474
- this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
525
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
475
526
  this.statusCode({ res });
476
527
  res.on('data', d => {
477
- this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
528
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
478
529
  });
479
530
  });
480
531
  req.on('error', (e: any) => {
481
- this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
532
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
482
533
  });
483
534
  req.write(body);
484
535
  req.end();
485
- this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
486
- this.OnCached = this.On;
487
- this.accessory.context.On = this.OnCached;
536
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
537
+ } else {
538
+ this.debugLog(
539
+ `${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
540
+ +`OnCached: ${this.accessory.context.On}`,
541
+ );
488
542
  }
489
543
  // Push Brightness Update
490
544
  if (this.On) {
491
545
  await this.pushBrightnessChanges();
492
546
  }
493
-
494
547
  // Push Hue & Saturation Update
495
548
  if (this.On) {
496
549
  await this.pushHueSaturationChanges();
497
550
  }
498
551
  } catch (e: any) {
499
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
500
- if (this.deviceLogging.includes('debug')) {
501
- this.errorLog(
502
- `Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
503
- );
504
- }
505
552
  this.apiError(e);
553
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
554
+ + ` Connection, Error Message: ${superStringify(e.message)}`,
555
+ );
506
556
  }
507
557
  }
508
558
 
509
559
  async pushHueSaturationChanges(): Promise<void> {
510
560
  try {
511
- if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
512
- this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
513
- this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
561
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
562
+ if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
563
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
564
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
514
565
 
515
566
  const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
516
- this.debugLog(`Strip Light: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
567
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
517
568
  // Make Push On request to the API
518
569
  const t = Date.now();
519
570
  const nonce = 'requestID';
@@ -522,13 +573,13 @@ export class StripLight {
522
573
  .update(Buffer.from(data, 'utf-8'))
523
574
  .digest();
524
575
  const sign = signTerm.toString('base64');
525
- this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
526
- const body = JSON.stringify({
576
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
577
+ const body = superStringify({
527
578
  'command': 'setColor',
528
579
  'parameter': `${red}:${green}:${blue}`,
529
580
  'commandType': 'command',
530
581
  });
531
- this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
582
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
532
583
  const options = {
533
584
  hostname: HostDomain,
534
585
  port: 443,
@@ -544,41 +595,33 @@ export class StripLight {
544
595
  },
545
596
  };
546
597
  const req = https.request(options, res => {
547
- this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
598
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
548
599
  this.statusCode({ res });
549
600
  res.on('data', d => {
550
- this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
601
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
551
602
  });
552
603
  });
553
604
  req.on('error', (e: any) => {
554
- this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
605
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
555
606
  });
556
607
  req.write(body);
557
608
  req.end();
558
- this.debugLog(`Strip Light: ${this.accessory.displayName} pushHueSaturationChanges: ${JSON.stringify(req)}`);
559
- this.HueCached = this.Hue;
560
- this.SaturationCached = this.Saturation;
609
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${superStringify(req)}`);
561
610
  } else {
562
- this.debugLog(
563
- `Strip Light: ${this.accessory.displayName} No Changes.` +
564
- `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`,
565
- );
611
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
612
+ + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
566
613
  }
567
614
  } catch (e: any) {
568
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection`);
569
- if (this.deviceLogging.includes('debug')) {
570
- this.errorLog(
571
- `Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection,`
572
- + ` Error Message: ${JSON.stringify(e.message)}`,
573
- );
574
- }
575
615
  this.apiError(e);
616
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
617
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
576
618
  }
577
619
  }
578
620
 
579
621
  async pushBrightnessChanges(): Promise<void> {
580
622
  try {
581
- if (this.Brightness !== this.BrightnessCached) {
623
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
624
+ if (this.Brightness !== this.accessory.context.Brightness) {
582
625
  // Make Push On request to the API
583
626
  const t = Date.now();
584
627
  const nonce = 'requestID';
@@ -587,13 +630,13 @@ export class StripLight {
587
630
  .update(Buffer.from(data, 'utf-8'))
588
631
  .digest();
589
632
  const sign = signTerm.toString('base64');
590
- this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
591
- const body = JSON.stringify({
633
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
634
+ const body = superStringify({
592
635
  'command': 'setBrightness',
593
636
  'parameter': `${this.Brightness}`,
594
637
  'commandType': 'command',
595
638
  });
596
- this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
639
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
597
640
  const options = {
598
641
  hostname: HostDomain,
599
642
  port: 443,
@@ -609,104 +652,299 @@ export class StripLight {
609
652
  },
610
653
  };
611
654
  const req = https.request(options, res => {
612
- this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
655
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
613
656
  this.statusCode({ res });
614
657
  res.on('data', d => {
615
- this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
658
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
616
659
  });
617
660
  });
618
661
  req.on('error', (e: any) => {
619
- this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
662
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
620
663
  });
621
664
  req.write(body);
622
665
  req.end();
623
- this.debugLog(`Strip Light: ${this.accessory.displayName} pushBrightnessChanges: ${JSON.stringify(req)}`);
624
- this.BrightnessCached = this.Brightness;
666
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${superStringify(req)}`);
625
667
  } else {
626
- this.debugLog(
627
- `Strip Light: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
628
- );
668
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
669
+ +`BrightnessCached: ${this.accessory.context.Brightness}`);
629
670
  }
630
671
  } catch (e: any) {
631
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection`);
632
- if (this.deviceLogging.includes('debug')) {
633
- this.errorLog(
634
- `Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection,`
635
- + ` Error Message: ${JSON.stringify(e.message)}`,
636
- );
637
- }
638
672
  this.apiError(e);
673
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
674
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
675
+ }
676
+ }
677
+
678
+ /**
679
+ * Handle requests to set the value of the "On" characteristic
680
+ */
681
+ async OnSet(value: CharacteristicValue): Promise<void> {
682
+ if (this.On === this.accessory.context.On) {
683
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
684
+ } else {
685
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
686
+ }
687
+
688
+ this.On = value;
689
+ this.doStripLightUpdate.next();
690
+ }
691
+
692
+ /**
693
+ * Handle requests to set the value of the "Brightness" characteristic
694
+ */
695
+ async BrightnessSet(value: CharacteristicValue): Promise<void> {
696
+ if (this.Brightness === this.accessory.context.Brightness) {
697
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
698
+ } else if (this.On) {
699
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
700
+ } else {
701
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
702
+ }
703
+
704
+ this.Brightness = value;
705
+ this.doStripLightUpdate.next();
706
+ }
707
+
708
+ /**
709
+ * Handle requests to set the value of the "ColorTemperature" characteristic
710
+ */
711
+ async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
712
+ if (this.ColorTemperature === this.accessory.context.ColorTemperature) {
713
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
714
+ } else if (this.On) {
715
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
716
+ } else {
717
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
718
+ }
719
+
720
+ // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
721
+ const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
722
+
723
+ // Check and increase/decrease kelvin to range of device
724
+ const k = Math.min(Math.max(kelvin, this.minKelvin), this.maxKelvin);
725
+
726
+ if (!this.accessory.context.On || this.cacheKelvin === k) {
727
+ return;
639
728
  }
729
+
730
+ // Updating the hue/sat to the corresponding values mimics native adaptive lighting
731
+ const hs = m2hs(value);
732
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
733
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
734
+
735
+ this.ColorTemperature = value;
736
+ this.doStripLightUpdate.next();
737
+ }
738
+
739
+ /**
740
+ * Handle requests to set the value of the "Hue" characteristic
741
+ */
742
+ async HueSet(value: CharacteristicValue): Promise<void> {
743
+ if (this.Hue === this.accessory.context.Hue) {
744
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
745
+ } else if (this.On) {
746
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
747
+ } else {
748
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
749
+ }
750
+
751
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
752
+
753
+ this.Hue = value;
754
+ this.doStripLightUpdate.next();
755
+ }
756
+
757
+ /**
758
+ * Handle requests to set the value of the "Saturation" characteristic
759
+ */
760
+ async SaturationSet(value: CharacteristicValue): Promise<void> {
761
+ if (this.Saturation === this.accessory.context.Saturation) {
762
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
763
+ } else if (this.On) {
764
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
765
+ } else {
766
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
767
+ }
768
+
769
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
770
+
771
+ this.Saturation = value;
772
+ this.doStripLightUpdate.next();
640
773
  }
641
774
 
642
775
  async updateHomeKitCharacteristics(): Promise<void> {
643
776
  if (this.On === undefined) {
644
- this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
777
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
645
778
  } else {
779
+ this.accessory.context.On = this.On;
646
780
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
647
- this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
781
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
648
782
  }
649
783
  if (this.Brightness === undefined) {
650
- this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
784
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
651
785
  } else {
786
+ this.accessory.context.Brightness = this.Brightness;
652
787
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
653
- this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
788
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
789
+ }
790
+ if (this.ColorTemperature === undefined) {
791
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
792
+ } else {
793
+ this.accessory.context.ColorTemperature = this.ColorTemperature;
794
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
795
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
654
796
  }
655
797
  if (this.Hue === undefined) {
656
- this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${this.Hue}`);
798
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
657
799
  } else {
800
+ this.accessory.context.Hue = this.Hue;
658
801
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
659
- this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
802
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
660
803
  }
661
804
  if (this.Saturation === undefined) {
662
- this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
805
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
663
806
  } else {
807
+ this.accessory.context.Saturation = this.Saturation;
664
808
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
665
- this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
809
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
666
810
  }
667
811
  }
668
812
 
669
- apiError(e: any): void {
670
- this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
671
- this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
672
- this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
673
- this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
674
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
813
+ async getCustomBLEAddress(switchbot: any) {
814
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
815
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
816
+ (async () => {
817
+ // Start to monitor advertisement packets
818
+ await switchbot.startScan({
819
+ model: 'r',
820
+ });
821
+ // Set an event handler
822
+ switchbot.onadvertisement = (ad: any) => {
823
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
824
+ };
825
+ await switchbot.wait(10000);
826
+ // Stop to monitor
827
+ switchbot.stopScan();
828
+ })();
829
+ }
830
+ }
831
+
832
+ async BLEPushConnection() {
833
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
834
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
835
+ await this.openAPIpushChanges();
836
+ }
837
+ }
838
+
839
+ async BLERefreshConnection(switchbot: any): Promise<void> {
840
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
841
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
842
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
843
+ await this.openAPIRefreshStatus();
844
+ }
845
+ }
846
+
847
+ async turnOnOff(device_list: any): Promise<any> {
848
+ return await this.retry({
849
+ max: await this.maxRetry(),
850
+ fn: () => {
851
+ if (this.On) {
852
+ return device_list[0].turnOn({ id: this.device.bleMac });
853
+ } else {
854
+ return device_list[0].turnOff({ id: this.device.bleMac });
855
+ }
856
+ },
857
+ });
858
+ }
859
+
860
+ async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
861
+ return fn().catch(async (err: any) => {
862
+ if (max === 0) {
863
+ throw err;
864
+ }
865
+ this.infoLog(err);
866
+ this.infoLog('Retrying');
867
+ await this.switchbot.wait(1000);
868
+ return this.retry({ max: max - 1, fn });
869
+ });
870
+ }
871
+
872
+ async maxRetry(): Promise<number> {
873
+ let maxRetry: number;
874
+ if (this.device.bot?.maxRetry) {
875
+ maxRetry = this.device.bot?.maxRetry;
876
+ } else {
877
+ maxRetry = 5;
878
+ }
879
+ return maxRetry;
880
+ }
881
+
882
+ minStep(device: device & devicesConfig): number {
883
+ if (device.colorbulb?.set_minStep) {
884
+ this.set_minStep = device.colorbulb?.set_minStep;
885
+ } else {
886
+ this.set_minStep = 1;
887
+ }
888
+ return this.set_minStep;
889
+ }
890
+
891
+ async adaptiveLighting(device: device & devicesConfig): Promise<void> {
892
+ if (device.colorbulb?.adaptiveLightingShift) {
893
+ this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
894
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
895
+ } else {
896
+ this.adaptiveLightingShift = 0;
897
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
898
+ }
899
+ }
900
+
901
+ async scan(device: device & devicesConfig): Promise<void> {
902
+ if (device.scanDuration) {
903
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
904
+ if (this.BLE) {
905
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
906
+ }
907
+ } else {
908
+ this.scanDuration = this.accessory.context.scanDuration = 1;
909
+ if (this.BLE) {
910
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
911
+ }
912
+ }
675
913
  }
676
914
 
677
915
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
678
916
  switch (res.statusCode) {
679
917
  case 151:
680
- this.errorLog(`Strip Light: ${this.accessory.displayName} Command not supported by this device type.`);
918
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
681
919
  break;
682
920
  case 152:
683
- this.errorLog(`Strip Light: ${this.accessory.displayName} Device not found.`);
921
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
684
922
  break;
685
923
  case 160:
686
- this.errorLog(`Strip Light: ${this.accessory.displayName} Command is not supported.`);
924
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
687
925
  break;
688
926
  case 161:
689
- this.errorLog(`Strip Light: ${this.accessory.displayName} Device is offline.`);
927
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
690
928
  this.offlineOff();
691
929
  break;
692
930
  case 171:
693
- this.errorLog(`Strip Light: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
931
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
694
932
  this.offlineOff();
695
933
  break;
696
934
  case 190:
697
935
  this.errorLog(
698
- `Strip Light: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
699
- ` Or command: ${JSON.stringify(res)} format is invalid`,
936
+ `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
937
+ ` Or command: ${superStringify(res)} format is invalid`,
700
938
  );
701
939
  break;
702
940
  case 100:
703
941
  if (this.platform.debugMode) {
704
- this.debugLog(`Strip Light: ${this.accessory.displayName} Command successfully sent.`);
942
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
705
943
  }
706
944
  break;
707
945
  default:
708
946
  if (this.platform.debugMode) {
709
- this.debugLog(`Strip Light: ${this.accessory.displayName} Unknown statusCode.`);
947
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
710
948
  }
711
949
  }
712
950
  }
@@ -715,47 +953,71 @@ export class StripLight {
715
953
  if (this.device.offline) {
716
954
  this.On = false;
717
955
  this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
956
+ await this.updateHomeKitCharacteristics();
718
957
  }
719
958
  }
720
959
 
721
- /**
722
- * Handle requests to set the value of the "On" characteristic
723
- */
724
- async OnSet(value: CharacteristicValue): Promise<void> {
725
- this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${value}`);
726
-
727
- this.On = value;
728
- this.doColorBulbUpdate.next();
960
+ apiError(e: any): void {
961
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
962
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
963
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
964
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
729
965
  }
730
966
 
731
- /**
732
- * Handle requests to set the value of the "Brightness" characteristic
733
- */
734
- async BrightnessSet(value: CharacteristicValue): Promise<void> {
735
- this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${value}`);
736
-
737
- this.Brightness = value;
738
- this.doColorBulbUpdate.next();
967
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
968
+ let FirmwareRevision: string;
969
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
970
+ +`accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
971
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
972
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
973
+ if (accessory.context.FirmwareRevision) {
974
+ FirmwareRevision = accessory.context.FirmwareRevision;
975
+ } else if (device.firmware) {
976
+ FirmwareRevision = device.firmware;
977
+ } else {
978
+ FirmwareRevision = this.platform.version;
979
+ }
980
+ return FirmwareRevision;
739
981
  }
740
982
 
741
- /**
742
- * Handle requests to set the value of the "Hue" characteristic
743
- */
744
- async HueSet(value: CharacteristicValue): Promise<void> {
745
- this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${value}`);
746
-
747
- this.Hue = value;
748
- this.doColorBulbUpdate.next();
983
+ async context() {
984
+ if (this.On === undefined) {
985
+ this.On = false;
986
+ } else {
987
+ this.On = this.accessory.context.On;
988
+ }
989
+ if (this.Hue === undefined) {
990
+ this.Hue = 0;
991
+ } else {
992
+ this.Hue = this.accessory.context.Hue;
993
+ }
994
+ if (this.Brightness === undefined) {
995
+ this.Brightness = 0;
996
+ } else {
997
+ this.Brightness = this.accessory.context.Brightness;
998
+ }
999
+ if (this.Brightness === undefined) {
1000
+ this.Saturation = 0;
1001
+ } else {
1002
+ this.Saturation = this.accessory.context.Saturation;
1003
+ }
1004
+ if (this.ColorTemperature === undefined) {
1005
+ this.ColorTemperature = 140;
1006
+ } else {
1007
+ this.ColorTemperature = this.accessory.context.ColorTemperature;
1008
+ }
1009
+ this.minKelvin = 2000;
1010
+ this.maxKelvin = 9000;
749
1011
  }
750
1012
 
751
- /**
752
- * Handle requests to set the value of the "Saturation" characteristic
753
- */
754
- async SaturationSet(value: CharacteristicValue): Promise<void> {
755
- this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${value}`);
756
-
757
- this.Saturation = value;
758
- this.doColorBulbUpdate.next();
1013
+ async refreshRate(device: device & devicesConfig): Promise<void> {
1014
+ if (device.refreshRate) {
1015
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
1016
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
1017
+ } else if (this.platform.config.options!.refreshRate) {
1018
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
1019
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
1020
+ }
759
1021
  }
760
1022
 
761
1023
  async config(device: device & devicesConfig): Promise<void> {
@@ -763,8 +1025,11 @@ export class StripLight {
763
1025
  if (device.colorbulb) {
764
1026
  config = device.colorbulb;
765
1027
  }
766
- if (device.ble) {
767
- config['ble'] = device.ble;
1028
+ if (device.connectionType !== undefined) {
1029
+ config['connectionType'] = device.connectionType;
1030
+ }
1031
+ if (device.external !== undefined) {
1032
+ config['external'] = device.external;
768
1033
  }
769
1034
  if (device.logging !== undefined) {
770
1035
  config['logging'] = device.logging;
@@ -779,72 +1044,24 @@ export class StripLight {
779
1044
  config['offline'] = device.offline;
780
1045
  }
781
1046
  if (Object.entries(config).length !== 0) {
782
- this.infoLog(`Strip Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
783
- }
784
- }
785
-
786
- async refreshRate(device: device & devicesConfig): Promise<void> {
787
- if (device.refreshRate) {
788
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
789
- this.debugLog(`Strip Light: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
790
- } else if (this.platform.config.options!.refreshRate) {
791
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
792
- this.debugLog(`Strip Light: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
793
- }
794
- }
795
-
796
- async scan(device: device & devicesConfig): Promise<void> {
797
- if (device.scanDuration) {
798
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
799
- if (device.ble) {
800
- this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
801
- }
802
- } else {
803
- this.scanDuration = this.accessory.context.scanDuration = 1;
804
- if (this.device.ble) {
805
- this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
806
- }
1047
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
807
1048
  }
808
1049
  }
809
1050
 
810
1051
  async logs(device: device & devicesConfig): Promise<void> {
811
1052
  if (this.platform.debugMode) {
812
1053
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
813
- this.debugLog(`Strip Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
1054
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
814
1055
  } else if (device.logging) {
815
1056
  this.deviceLogging = this.accessory.context.logging = device.logging;
816
- this.debugLog(`Strip Light: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
1057
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
817
1058
  } else if (this.platform.config.options?.logging) {
818
1059
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
819
- this.debugLog(`Strip Light: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
1060
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
820
1061
  } else {
821
1062
  this.deviceLogging = this.accessory.context.logging = 'standard';
822
- this.debugLog(`Strip Light: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
823
- }
824
- }
825
-
826
- FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
827
- let FirmwareRevision: string;
828
- this.debugLog(`Strip Light: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
829
- this.debugLog(`Strip Light: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
830
- this.debugLog(`Strip Light: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
831
- if (accessory.context.FirmwareRevision) {
832
- FirmwareRevision = accessory.context.FirmwareRevision;
833
- } else if (device.firmware) {
834
- FirmwareRevision = device.firmware;
835
- } else {
836
- FirmwareRevision = this.platform.version;
1063
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
837
1064
  }
838
- return FirmwareRevision;
839
- }
840
-
841
- minStep(device: device & devicesConfig): number {
842
- if (device.colorbulb?.set_minStep) {
843
- this.set_minStep = device.colorbulb?.set_minStep;
844
- } else {
845
- this.set_minStep = 1;
846
- }
847
- return this.set_minStep;
848
1065
  }
849
1066
 
850
1067
  /**
@@ -862,12 +1079,28 @@ export class StripLight {
862
1079
  }
863
1080
  }
864
1081
 
1082
+ debugWarnLog(...log: any[]): void {
1083
+ if (this.enablingDeviceLogging()) {
1084
+ if (this.deviceLogging?.includes('debug')) {
1085
+ this.platform.log.warn('[DEBUG]', String(...log));
1086
+ }
1087
+ }
1088
+ }
1089
+
865
1090
  errorLog(...log: any[]): void {
866
1091
  if (this.enablingDeviceLogging()) {
867
1092
  this.platform.log.error(String(...log));
868
1093
  }
869
1094
  }
870
1095
 
1096
+ debugErrorLog(...log: any[]): void {
1097
+ if (this.enablingDeviceLogging()) {
1098
+ if (this.deviceLogging?.includes('debug')) {
1099
+ this.platform.log.error('[DEBUG]', String(...log));
1100
+ }
1101
+ }
1102
+ }
1103
+
871
1104
  debugLog(...log: any[]): void {
872
1105
  if (this.enablingDeviceLogging()) {
873
1106
  if (this.deviceLogging === 'debug') {