@switchbot/homebridge-switchbot 1.12.7-beta.5 → 1.12.7

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 (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/config.schema.json +6 -6
  3. package/dist/device/bot.js +2 -2
  4. package/dist/device/bot.js.map +1 -1
  5. package/dist/device/colorbulb.d.ts +0 -6
  6. package/dist/device/colorbulb.d.ts.map +1 -1
  7. package/dist/device/colorbulb.js +74 -89
  8. package/dist/device/colorbulb.js.map +1 -1
  9. package/dist/device/curtain.js +1 -1
  10. package/dist/device/curtain.js.map +1 -1
  11. package/dist/device/humidifier.js +2 -2
  12. package/dist/device/humidifier.js.map +1 -1
  13. package/dist/device/lock.d.ts.map +1 -1
  14. package/dist/device/lock.js +1 -21
  15. package/dist/device/lock.js.map +1 -1
  16. package/dist/device/meter.d.ts +0 -1
  17. package/dist/device/meter.d.ts.map +1 -1
  18. package/dist/device/meter.js +1 -14
  19. package/dist/device/meter.js.map +1 -1
  20. package/dist/device/meterplus.d.ts +76 -0
  21. package/dist/device/meterplus.d.ts.map +1 -0
  22. package/dist/device/meterplus.js +464 -0
  23. package/dist/device/meterplus.js.map +1 -0
  24. package/dist/device/plug.js +1 -1
  25. package/dist/device/plug.js.map +1 -1
  26. package/dist/device/striplight.d.ts +90 -0
  27. package/dist/device/striplight.d.ts.map +1 -0
  28. package/dist/device/striplight.js +487 -0
  29. package/dist/device/striplight.js.map +1 -0
  30. package/dist/platform.d.ts +2 -0
  31. package/dist/platform.d.ts.map +1 -1
  32. package/dist/platform.js +119 -9
  33. package/dist/platform.js.map +1 -1
  34. package/package.json +76 -76
  35. package/src/device/bot.ts +2 -2
  36. package/src/device/colorbulb.ts +74 -89
  37. package/src/device/curtain.ts +1 -1
  38. package/src/device/humidifier.ts +2 -2
  39. package/src/device/lock.ts +1 -21
  40. package/src/device/meter.ts +1 -13
  41. package/src/device/meterplus.ts +518 -0
  42. package/src/device/plug.ts +1 -1
  43. package/src/device/striplight.ts +583 -0
  44. package/src/platform.ts +127 -9
@@ -0,0 +1,583 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { interval, Subject } from 'rxjs';
3
+ import { SwitchBotPlatform } from '../platform';
4
+ import { debounceTime, skipWhile, tap } from 'rxjs/operators';
5
+ import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
6
+ import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, deviceStatus } from '../settings';
7
+
8
+ /**
9
+ * Platform Accessory
10
+ * An instance of this class is created for each accessory your platform registers
11
+ * Each accessory may expose multiple services of different service types.
12
+ */
13
+ export class StripLight {
14
+ // Services
15
+ lightBulbService!: Service;
16
+
17
+ // Characteristic Values
18
+ On!: CharacteristicValue;
19
+ OnCached!: CharacteristicValue;
20
+ Hue!: CharacteristicValue;
21
+ HueCached!: CharacteristicValue;
22
+ Saturation!: CharacteristicValue;
23
+ SaturationCached!: CharacteristicValue;
24
+ Brightness!: CharacteristicValue;
25
+ BrightnessCached!: CharacteristicValue;
26
+
27
+ // OpenAPI Others
28
+ power: deviceStatus['power'];
29
+ color: deviceStatus['color'];
30
+ brightness: deviceStatus['brightness'];
31
+ deviceStatus!: deviceStatusResponse;
32
+
33
+ // BLE Others
34
+ switchbot!: switchbot;
35
+
36
+ // Config
37
+ set_minStep?: number;
38
+ deviceLogging!: string;
39
+ deviceRefreshRate!: number;
40
+ adaptiveLightingShift?: number;
41
+
42
+ // Adaptive Lighting
43
+ AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
44
+ minKelvin!: number;
45
+ maxKelvin!: number;
46
+
47
+ // Others
48
+ cacheKelvin!: number;
49
+
50
+ // Updates
51
+ colorBulbUpdateInProgress!: boolean;
52
+ doColorBulbUpdate!: Subject<void>;
53
+
54
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
55
+ // default placeholders
56
+ this.logs(device);
57
+ this.refreshRate(device);
58
+ this.config(device);
59
+ if (this.On === undefined) {
60
+ this.On = false;
61
+ } else {
62
+ this.On = this.accessory.context.On;
63
+ }
64
+ this.Hue = 0;
65
+ this.Brightness = 0;
66
+ this.Saturation = 0;
67
+ this.minKelvin = 2000;
68
+ this.maxKelvin = 9000;
69
+ // this is subject we use to track when we need to POST changes to the SwitchBot API
70
+ this.doColorBulbUpdate = new Subject();
71
+ this.colorBulbUpdateInProgress = false;
72
+
73
+ // Retrieve initial values and updateHomekit
74
+ this.refreshStatus();
75
+
76
+ // set accessory information
77
+ accessory
78
+ .getService(this.platform.Service.AccessoryInformation)!
79
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
80
+ .setCharacteristic(this.platform.Characteristic.Model, 'W1701100')
81
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
82
+
83
+ // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
84
+ // you can create multiple services for each accessory
85
+ (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
86
+ `${accessory.displayName} Strip Light`;
87
+
88
+ // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
89
+ // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
90
+ // accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Outlet, 'NAME', 'USER_DEFINED_SUBTYPE');
91
+
92
+ // set the service name, this is what is displayed as the default name on the Home app
93
+ // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
94
+ this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
95
+
96
+ // handle on / off events using the On characteristic
97
+ this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
98
+
99
+ // handle Brightness events using the Brightness characteristic
100
+ this.lightBulbService
101
+ .getCharacteristic(this.platform.Characteristic.Brightness)
102
+ .setProps({
103
+ minStep: this.minStep(device),
104
+ minValue: 0,
105
+ maxValue: 100,
106
+ validValueRanges: [0, 100],
107
+ })
108
+ .onGet(() => {
109
+ return this.Brightness;
110
+ })
111
+ .onSet(this.BrightnessSet.bind(this));
112
+
113
+ // handle Hue events using the Hue characteristic
114
+ this.lightBulbService
115
+ .getCharacteristic(this.platform.Characteristic.Hue)
116
+ .setProps({
117
+ minValue: 0,
118
+ maxValue: 360,
119
+ validValueRanges: [0, 360],
120
+ })
121
+ .onGet(() => {
122
+ return this.Hue;
123
+ })
124
+ .onSet(this.HueSet.bind(this));
125
+
126
+ // handle Hue events using the Hue characteristic
127
+ this.lightBulbService
128
+ .getCharacteristic(this.platform.Characteristic.Saturation)
129
+ .setProps({
130
+ minValue: 0,
131
+ maxValue: 100,
132
+ validValueRanges: [0, 100],
133
+ })
134
+ .onGet(() => {
135
+ return this.Saturation;
136
+ })
137
+ .onSet(this.SaturationSet.bind(this));
138
+
139
+ // Update Homekit
140
+ this.updateHomeKitCharacteristics();
141
+
142
+ // Start an update interval
143
+ interval(this.deviceRefreshRate * 1000)
144
+ .pipe(skipWhile(() => this.colorBulbUpdateInProgress))
145
+ .subscribe(async () => {
146
+ await this.refreshStatus();
147
+ });
148
+
149
+ // Watch for Bulb change events
150
+ // We put in a debounce of 100ms so we don't make duplicate calls
151
+ this.doColorBulbUpdate
152
+ .pipe(
153
+ tap(() => {
154
+ this.colorBulbUpdateInProgress = true;
155
+ }),
156
+ debounceTime(this.platform.config.options!.pushRate! * 1000),
157
+ )
158
+ .subscribe(async () => {
159
+ try {
160
+ await this.pushChanges();
161
+ } catch (e: any) {
162
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges`);
163
+ if (this.deviceLogging.includes('debug')) {
164
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
165
+ }
166
+ this.apiError(e);
167
+ }
168
+ this.colorBulbUpdateInProgress = false;
169
+ });
170
+ }
171
+
172
+ async parseStatus(): Promise<void> {
173
+ switch (this.power) {
174
+ case 'on':
175
+ this.On = true;
176
+ break;
177
+ default:
178
+ this.On = false;
179
+ }
180
+ this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
181
+
182
+ // Brightness
183
+ this.Brightness = Number(this.brightness);
184
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
185
+
186
+ // Color, Hue & Brightness
187
+ if (this.color) {
188
+ this.debugLog(`Strip Light: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
189
+ const [red, green, blue] = this.color!.split(':');
190
+ this.debugLog(`Strip Light: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
191
+ this.debugLog(`Strip Light: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
192
+ this.debugLog(`Strip Light: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
193
+
194
+ const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
195
+ this.debugLog(
196
+ `Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
197
+ );
198
+
199
+ // Hue
200
+ this.Hue = hue;
201
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${this.Hue}`);
202
+
203
+ // Saturation
204
+ this.Saturation = saturation;
205
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
206
+ }
207
+ }
208
+
209
+ async refreshStatus(): Promise<void> {
210
+ try {
211
+ this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
212
+ this.debugLog(`Strip Light: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
213
+ this.power = this.deviceStatus.body.power;
214
+ this.color = this.deviceStatus.body.color;
215
+ this.brightness = this.deviceStatus.body.brightness;
216
+
217
+ this.parseStatus();
218
+ this.updateHomeKitCharacteristics();
219
+ } catch (e: any) {
220
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
221
+ if (this.deviceLogging.includes('debug')) {
222
+ this.errorLog(
223
+ `Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
224
+ ` Error Message: ${JSON.stringify(e.message)}`,
225
+ );
226
+ }
227
+ this.apiError(e);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Pushes the requested changes to the SwitchBot API
233
+ * deviceType commandType Command command parameter Description
234
+ * Strip Light - "command" "turnOn" "default" = set to ON state |
235
+ * Strip Light - "command" "turnOff" "default" = set to OFF state |
236
+ * Strip Light - "command" "toggle" "default" = toggle state |
237
+ * Strip Light - "command" "setBrightness" "`{1-100}`" = set brightness |
238
+ * Strip Light - "command" "setColor" "`"{0-255}:{0-255}:{0-255}"`" = set RGB color value |
239
+ *
240
+ */
241
+ async pushChanges(): Promise<void> {
242
+ try {
243
+ if (this.On !== this.OnCached) {
244
+ // Push On Update
245
+ const payload = {
246
+ commandType: 'command',
247
+ parameter: 'default',
248
+ } as payload;
249
+
250
+ if (this.On) {
251
+ payload.command = 'turnOn';
252
+ } else {
253
+ payload.command = 'turnOff';
254
+ }
255
+
256
+ this.infoLog(
257
+ `Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
258
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
259
+ );
260
+
261
+ // Make the API request
262
+ const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
263
+ this.debugLog(`Strip Light: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
264
+ this.statusCode(push);
265
+ this.OnCached = this.On;
266
+ this.accessory.context.On = this.OnCached;
267
+ }
268
+ // Push Brightness Update
269
+ if (this.On) {
270
+ await this.pushBrightnessChanges();
271
+ }
272
+
273
+ // Push Hue & Saturation Update
274
+ if (this.On) {
275
+ await this.pushHueSaturationChanges();
276
+ }
277
+ } catch (e: any) {
278
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
279
+ if (this.deviceLogging.includes('debug')) {
280
+ this.errorLog(
281
+ `Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
282
+ ` Error Message: ${JSON.stringify(e.message)}`,
283
+ );
284
+ }
285
+ this.apiError(e);
286
+ }
287
+ }
288
+
289
+ async pushHueSaturationChanges(): Promise<void> {
290
+ try {
291
+ if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
292
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
293
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
294
+
295
+ const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
296
+ this.debugLog(`Strip Light: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
297
+
298
+ const payload = {
299
+ commandType: 'command',
300
+ command: 'setColor',
301
+ parameter: `${red}:${green}:${blue}`,
302
+ } as payload;
303
+
304
+ this.infoLog(
305
+ `Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
306
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
307
+ );
308
+
309
+ // Make the API request
310
+ const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
311
+ this.debugLog(`Strip Light: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
312
+ this.statusCode(push);
313
+ this.HueCached = this.Hue;
314
+ this.SaturationCached = this.Saturation;
315
+ } else {
316
+ this.debugLog(
317
+ `Strip Light: ${this.accessory.displayName} No Changes.` +
318
+ `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`,
319
+ );
320
+ }
321
+ } catch (e: any) {
322
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
323
+ if (this.deviceLogging.includes('debug')) {
324
+ this.errorLog(
325
+ `Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
326
+ ` Error Message: ${JSON.stringify(e.message)}`,
327
+ );
328
+ }
329
+ this.apiError(e);
330
+ }
331
+ }
332
+
333
+ async pushBrightnessChanges(): Promise<void> {
334
+ try {
335
+ if (this.Brightness !== this.BrightnessCached) {
336
+ const payload = {
337
+ commandType: 'command',
338
+ command: 'setBrightness',
339
+ parameter: `${this.Brightness}`,
340
+ } as payload;
341
+
342
+ this.infoLog(
343
+ `Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
344
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
345
+ );
346
+
347
+ // Make the API request
348
+ const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
349
+ this.debugLog(`Strip Light: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
350
+ this.statusCode(push);
351
+ this.BrightnessCached = this.Brightness;
352
+ } else {
353
+ this.debugLog(
354
+ `Strip Light: ${this.accessory.displayName} No Changes.` +
355
+ `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
356
+ );
357
+ }
358
+ } catch (e: any) {
359
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
360
+ if (this.deviceLogging.includes('debug')) {
361
+ this.errorLog(
362
+ `Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
363
+ ` Error Message: ${JSON.stringify(e.message)}`,
364
+ );
365
+ }
366
+ this.apiError(e);
367
+ }
368
+ }
369
+
370
+ async updateHomeKitCharacteristics(): Promise<void> {
371
+ if (this.On === undefined) {
372
+ this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
373
+ } else {
374
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
375
+ this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
376
+ }
377
+ if (this.Brightness === undefined) {
378
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
379
+ } else {
380
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
381
+ this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
382
+ }
383
+ if (this.Hue === undefined) {
384
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${this.Hue}`);
385
+ } else {
386
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
387
+ this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
388
+ }
389
+ if (this.Saturation === undefined) {
390
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
391
+ } else {
392
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
393
+ this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
394
+ }
395
+ }
396
+
397
+ apiError(e: any): void {
398
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
399
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
400
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
401
+ this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
402
+ //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
403
+ }
404
+
405
+ statusCode(push: AxiosResponse<{ statusCode: number }>): void {
406
+ switch (push.data.statusCode) {
407
+ case 151:
408
+ this.errorLog(`Strip Light: ${this.accessory.displayName} Command not supported by this device type.`);
409
+ break;
410
+ case 152:
411
+ this.errorLog(`Strip Light: ${this.accessory.displayName} Device not found.`);
412
+ break;
413
+ case 160:
414
+ this.errorLog(`Strip Light: ${this.accessory.displayName} Command is not supported.`);
415
+ break;
416
+ case 161:
417
+ this.errorLog(`Strip Light: ${this.accessory.displayName} Device is offline.`);
418
+ this.offlineOff();
419
+ break;
420
+ case 171:
421
+ this.errorLog(`Strip Light: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
422
+ this.offlineOff();
423
+ break;
424
+ case 190:
425
+ this.errorLog(
426
+ `Strip Light: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
427
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`,
428
+ );
429
+ break;
430
+ case 100:
431
+ if (this.platform.debugMode) {
432
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Command successfully sent.`);
433
+ }
434
+ break;
435
+ default:
436
+ if (this.platform.debugMode) {
437
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Unknown statusCode.`);
438
+ }
439
+ }
440
+ }
441
+
442
+ async offlineOff(): Promise<void> {
443
+ if (this.device.offline) {
444
+ this.On = false;
445
+ this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
446
+ }
447
+ }
448
+
449
+ /**
450
+ * Handle requests to set the value of the "On" characteristic
451
+ */
452
+ async OnSet(value: CharacteristicValue): Promise<void> {
453
+ this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${value}`);
454
+
455
+ this.On = value;
456
+ this.doColorBulbUpdate.next();
457
+ }
458
+
459
+ /**
460
+ * Handle requests to set the value of the "Brightness" characteristic
461
+ */
462
+ async BrightnessSet(value: CharacteristicValue): Promise<void> {
463
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${value}`);
464
+
465
+ this.Brightness = value;
466
+ this.doColorBulbUpdate.next();
467
+ }
468
+
469
+ /**
470
+ * Handle requests to set the value of the "Hue" characteristic
471
+ */
472
+ async HueSet(value: CharacteristicValue): Promise<void> {
473
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${value}`);
474
+
475
+ this.Hue = value;
476
+ this.doColorBulbUpdate.next();
477
+ }
478
+
479
+ /**
480
+ * Handle requests to set the value of the "Saturation" characteristic
481
+ */
482
+ async SaturationSet(value: CharacteristicValue): Promise<void> {
483
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${value}`);
484
+
485
+ this.Saturation = value;
486
+ this.doColorBulbUpdate.next();
487
+ }
488
+
489
+ async config(device: device & devicesConfig): Promise<void> {
490
+ let config = {};
491
+ if (device.colorbulb) {
492
+ config = device.colorbulb;
493
+ }
494
+ if (device.ble) {
495
+ config['ble'] = device.ble;
496
+ }
497
+ if (device.logging !== undefined) {
498
+ config['logging'] = device.logging;
499
+ }
500
+ if (device.refreshRate !== undefined) {
501
+ config['refreshRate'] = device.refreshRate;
502
+ }
503
+ if (device.scanDuration !== undefined) {
504
+ config['scanDuration'] = device.scanDuration;
505
+ }
506
+ if (device.offline !== undefined) {
507
+ config['offline'] = device.offline;
508
+ }
509
+ if (Object.entries(config).length !== 0) {
510
+ this.infoLog(`Strip Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
511
+ }
512
+ }
513
+
514
+ async refreshRate(device: device & devicesConfig): Promise<void> {
515
+ if (device.refreshRate) {
516
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
517
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
518
+ } else if (this.platform.config.options!.refreshRate) {
519
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
520
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
521
+ }
522
+ }
523
+
524
+ async logs(device: device & devicesConfig): Promise<void> {
525
+ if (this.platform.debugMode) {
526
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
527
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
528
+ } else if (device.logging) {
529
+ this.deviceLogging = this.accessory.context.logging = device.logging;
530
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
531
+ } else if (this.platform.config.options?.logging) {
532
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
533
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
534
+ } else {
535
+ this.deviceLogging = this.accessory.context.logging = 'standard';
536
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
537
+ }
538
+ }
539
+
540
+ minStep(device: device & devicesConfig): number {
541
+ if (device.colorbulb?.set_minStep) {
542
+ this.set_minStep = device.colorbulb?.set_minStep;
543
+ } else {
544
+ this.set_minStep = 1;
545
+ }
546
+ return this.set_minStep;
547
+ }
548
+
549
+ /**
550
+ * Logging for Device
551
+ */
552
+ infoLog(...log: any[]): void {
553
+ if (this.enablingDeviceLogging()) {
554
+ this.platform.log.info(String(...log));
555
+ }
556
+ }
557
+
558
+ warnLog(...log: any[]): void {
559
+ if (this.enablingDeviceLogging()) {
560
+ this.platform.log.warn(String(...log));
561
+ }
562
+ }
563
+
564
+ errorLog(...log: any[]): void {
565
+ if (this.enablingDeviceLogging()) {
566
+ this.platform.log.error(String(...log));
567
+ }
568
+ }
569
+
570
+ debugLog(...log: any[]): void {
571
+ if (this.enablingDeviceLogging()) {
572
+ if (this.deviceLogging === 'debug') {
573
+ this.platform.log.info('[DEBUG]', String(...log));
574
+ } else {
575
+ this.platform.log.debug(String(...log));
576
+ }
577
+ }
578
+ }
579
+
580
+ enablingDeviceLogging(): boolean {
581
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
582
+ }
583
+ }