@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-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.
- package/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts +1 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +58 -65
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +52 -55
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +68 -68
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +76 -75
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +67 -59
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +81 -94
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +197 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +58 -62
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +28 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +68 -67
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +51 -47
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +75 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +4 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +74 -74
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +66 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +39 -39
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -53
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +64 -66
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +32 -34
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +20 -23
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +30 -32
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +26 -29
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +22 -23
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +47 -50
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +20 -23
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +22 -23
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +46 -44
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +114 -78
- package/src/device/bot.ts +102 -63
- package/src/device/ceilinglight.ts +113 -73
- package/src/device/colorbulb.ts +144 -87
- package/src/device/contact.ts +98 -63
- package/src/device/curtain.ts +160 -134
- package/src/device/hub.ts +228 -39
- package/src/device/humidifier.ts +136 -85
- package/src/device/iosensor.ts +52 -32
- package/src/device/lightstrip.ts +118 -72
- package/src/device/lock.ts +85 -50
- package/src/device/meter.ts +104 -80
- package/src/device/meterplus.ts +103 -80
- package/src/device/motion.ts +95 -59
- package/src/device/plug.ts +70 -44
- package/src/device/robotvacuumcleaner.ts +107 -56
- package/src/irdevice/airconditioner.ts +116 -86
- package/src/irdevice/airpurifier.ts +60 -39
- package/src/irdevice/camera.ts +40 -28
- package/src/irdevice/fan.ts +52 -38
- package/src/irdevice/light.ts +48 -34
- package/src/irdevice/other.ts +44 -28
- package/src/irdevice/tv.ts +70 -56
- package/src/irdevice/vacuumcleaner.ts +40 -28
- package/src/irdevice/waterheater.ts +48 -32
- package/src/platform.ts +87 -56
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/lightstrip.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable brace-style */
|
|
1
2
|
import { Context } from 'vm';
|
|
2
3
|
import { request } from 'undici';
|
|
3
4
|
import { sleep } from '../utils';
|
|
@@ -24,6 +25,7 @@ export class StripLight {
|
|
|
24
25
|
ColorTemperature?: CharacteristicValue;
|
|
25
26
|
|
|
26
27
|
// OpenAPI Others
|
|
28
|
+
Version: deviceStatus['version'];
|
|
27
29
|
power: deviceStatus['power'];
|
|
28
30
|
color: deviceStatus['color'];
|
|
29
31
|
brightness: deviceStatus['brightness'];
|
|
@@ -59,16 +61,21 @@ export class StripLight {
|
|
|
59
61
|
doStripLightUpdate!: Subject<void>;
|
|
60
62
|
|
|
61
63
|
// Connection
|
|
62
|
-
private readonly BLE =
|
|
63
|
-
private readonly OpenAPI =
|
|
64
|
-
|
|
65
|
-
constructor(
|
|
64
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
65
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
private readonly platform: SwitchBotPlatform,
|
|
69
|
+
private accessory: PlatformAccessory,
|
|
70
|
+
public device: device & devicesConfig,
|
|
71
|
+
) {
|
|
66
72
|
// default placeholders
|
|
67
73
|
this.logs(device);
|
|
68
74
|
this.scan(device);
|
|
69
75
|
this.refreshRate(device);
|
|
70
|
-
this.config(device);
|
|
71
76
|
this.context();
|
|
77
|
+
this.config(device);
|
|
78
|
+
|
|
72
79
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
73
80
|
this.doStripLightUpdate = new Subject();
|
|
74
81
|
this.stripLightUpdateInProgress = false;
|
|
@@ -91,7 +98,6 @@ export class StripLight {
|
|
|
91
98
|
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
92
99
|
`${accessory.displayName} ${device.deviceType}`;
|
|
93
100
|
|
|
94
|
-
|
|
95
101
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
96
102
|
this.accessory.removeService(this.lightBulbService);
|
|
97
103
|
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
@@ -202,8 +208,10 @@ export class StripLight {
|
|
|
202
208
|
await this.pushChanges();
|
|
203
209
|
} catch (e: any) {
|
|
204
210
|
this.apiError(e);
|
|
205
|
-
this.errorLog(
|
|
206
|
-
|
|
211
|
+
this.errorLog(
|
|
212
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
213
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
214
|
+
);
|
|
207
215
|
}
|
|
208
216
|
this.stripLightUpdateInProgress = false;
|
|
209
217
|
});
|
|
@@ -221,8 +229,9 @@ export class StripLight {
|
|
|
221
229
|
await this.openAPIparseStatus();
|
|
222
230
|
} else {
|
|
223
231
|
await this.offlineOff();
|
|
224
|
-
this.debugWarnLog(
|
|
225
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
232
|
+
this.debugWarnLog(
|
|
233
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
234
|
+
);
|
|
226
235
|
}
|
|
227
236
|
}
|
|
228
237
|
|
|
@@ -263,8 +272,9 @@ export class StripLight {
|
|
|
263
272
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
264
273
|
|
|
265
274
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
266
|
-
this.debugLog(
|
|
267
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}
|
|
275
|
+
this.debugLog(
|
|
276
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
277
|
+
);
|
|
268
278
|
|
|
269
279
|
// Hue
|
|
270
280
|
this.Hue = hue;
|
|
@@ -288,8 +298,10 @@ export class StripLight {
|
|
|
288
298
|
await this.openAPIRefreshStatus();
|
|
289
299
|
} else {
|
|
290
300
|
await this.offlineOff();
|
|
291
|
-
this.debugWarnLog(
|
|
292
|
-
|
|
301
|
+
this.debugWarnLog(
|
|
302
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
303
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
304
|
+
);
|
|
293
305
|
}
|
|
294
306
|
}
|
|
295
307
|
|
|
@@ -314,8 +326,10 @@ export class StripLight {
|
|
|
314
326
|
// Set an event hander
|
|
315
327
|
switchbot.onadvertisement = async (ad: any) => {
|
|
316
328
|
this.address = ad.address;
|
|
317
|
-
this.debugLog(
|
|
318
|
-
|
|
329
|
+
this.debugLog(
|
|
330
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
331
|
+
` BLE Address Found: ${this.address}`,
|
|
332
|
+
);
|
|
319
333
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
320
334
|
this.serviceData = ad.serviceData;
|
|
321
335
|
//this.state = ad.serviceData.state;
|
|
@@ -350,8 +364,10 @@ export class StripLight {
|
|
|
350
364
|
})
|
|
351
365
|
.catch(async (e: any) => {
|
|
352
366
|
this.apiError(e);
|
|
353
|
-
this.errorLog(
|
|
354
|
-
|
|
367
|
+
this.errorLog(
|
|
368
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
369
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
370
|
+
);
|
|
355
371
|
await this.BLERefreshConnection(switchbot);
|
|
356
372
|
});
|
|
357
373
|
} else {
|
|
@@ -369,10 +385,7 @@ export class StripLight {
|
|
|
369
385
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
370
386
|
this.statusCode(statusCode);
|
|
371
387
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
372
|
-
this.debugLog(
|
|
373
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
374
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
375
|
-
);
|
|
388
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
376
389
|
this.power = deviceStatus.body.power;
|
|
377
390
|
this.color = deviceStatus.body.color;
|
|
378
391
|
this.brightness = deviceStatus.body.brightness;
|
|
@@ -380,8 +393,10 @@ export class StripLight {
|
|
|
380
393
|
this.updateHomeKitCharacteristics();
|
|
381
394
|
} catch (e: any) {
|
|
382
395
|
this.apiError(e);
|
|
383
|
-
this.errorLog(
|
|
384
|
-
|
|
396
|
+
this.errorLog(
|
|
397
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
398
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
399
|
+
);
|
|
385
400
|
}
|
|
386
401
|
}
|
|
387
402
|
|
|
@@ -398,14 +413,15 @@ export class StripLight {
|
|
|
398
413
|
async pushChanges(): Promise<void> {
|
|
399
414
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
400
415
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
401
|
-
}
|
|
416
|
+
} /*if (this.BLE) {
|
|
402
417
|
await this.BLEpushChanges();
|
|
403
|
-
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
418
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
404
419
|
await this.openAPIpushChanges();
|
|
405
420
|
} else {
|
|
406
421
|
await this.offlineOff();
|
|
407
|
-
this.debugWarnLog(
|
|
408
|
-
|
|
422
|
+
this.debugWarnLog(
|
|
423
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
424
|
+
);
|
|
409
425
|
}
|
|
410
426
|
// Refresh the status from the API
|
|
411
427
|
interval(15000)
|
|
@@ -451,8 +467,10 @@ export class StripLight {
|
|
|
451
467
|
})
|
|
452
468
|
.catch(async (e: any) => {
|
|
453
469
|
this.apiError(e);
|
|
454
|
-
this.errorLog(
|
|
455
|
-
|
|
470
|
+
this.errorLog(
|
|
471
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
472
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
473
|
+
);
|
|
456
474
|
await this.BLEPushConnection();
|
|
457
475
|
});
|
|
458
476
|
// Push Brightness Update
|
|
@@ -464,8 +482,9 @@ export class StripLight {
|
|
|
464
482
|
await this.BLEpushRGBChanges();
|
|
465
483
|
}
|
|
466
484
|
} else {
|
|
467
|
-
this.debugLog(
|
|
468
|
-
+ `OnCached: ${this.accessory.context.On}
|
|
485
|
+
this.debugLog(
|
|
486
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
|
|
487
|
+
);
|
|
469
488
|
}
|
|
470
489
|
}
|
|
471
490
|
|
|
@@ -494,13 +513,18 @@ export class StripLight {
|
|
|
494
513
|
})
|
|
495
514
|
.catch(async (e: any) => {
|
|
496
515
|
this.apiError(e);
|
|
497
|
-
this.errorLog(
|
|
498
|
-
|
|
516
|
+
this.errorLog(
|
|
517
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}` +
|
|
518
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
519
|
+
);
|
|
499
520
|
await this.BLEPushConnection();
|
|
500
521
|
});
|
|
501
522
|
} else {
|
|
502
|
-
this.debugLog(
|
|
503
|
-
|
|
523
|
+
this.debugLog(
|
|
524
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
|
|
525
|
+
`Brightness: ${this.Brightness}, ` +
|
|
526
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
527
|
+
);
|
|
504
528
|
}
|
|
505
529
|
}
|
|
506
530
|
|
|
@@ -526,7 +550,7 @@ export class StripLight {
|
|
|
526
550
|
id: this.device.bleMac,
|
|
527
551
|
})
|
|
528
552
|
.then(async (device_list: any) => {
|
|
529
|
-
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
|
|
553
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
|
|
530
554
|
return await device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
531
555
|
})
|
|
532
556
|
.then(() => {
|
|
@@ -535,13 +559,17 @@ export class StripLight {
|
|
|
535
559
|
})
|
|
536
560
|
.catch(async (e: any) => {
|
|
537
561
|
this.apiError(e);
|
|
538
|
-
this.errorLog(
|
|
539
|
-
|
|
562
|
+
this.errorLog(
|
|
563
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}` +
|
|
564
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
565
|
+
);
|
|
540
566
|
await this.BLEPushConnection();
|
|
541
567
|
});
|
|
542
568
|
} else {
|
|
543
|
-
this.debugLog(
|
|
544
|
-
|
|
569
|
+
this.debugLog(
|
|
570
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
|
|
571
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
572
|
+
);
|
|
545
573
|
}
|
|
546
574
|
}
|
|
547
575
|
|
|
@@ -555,9 +583,9 @@ export class StripLight {
|
|
|
555
583
|
command = 'turnOff';
|
|
556
584
|
}*/
|
|
557
585
|
const bodyChange = JSON.stringify({
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
586
|
+
command: `${command}`,
|
|
587
|
+
parameter: 'default',
|
|
588
|
+
commandType: 'command',
|
|
561
589
|
});
|
|
562
590
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
563
591
|
try {
|
|
@@ -572,13 +600,17 @@ export class StripLight {
|
|
|
572
600
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
573
601
|
} catch (e: any) {
|
|
574
602
|
this.apiError(e);
|
|
575
|
-
this.errorLog(
|
|
576
|
-
|
|
603
|
+
this.errorLog(
|
|
604
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
605
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
577
606
|
);
|
|
578
607
|
}
|
|
579
608
|
} else {
|
|
580
|
-
this.debugLog(
|
|
581
|
-
|
|
609
|
+
this.debugLog(
|
|
610
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
611
|
+
`On: ${this.On}, ` +
|
|
612
|
+
`OnCached: ${this.accessory.context.On}`,
|
|
613
|
+
);
|
|
582
614
|
}
|
|
583
615
|
// Push Hue & Saturation Update
|
|
584
616
|
if (this.On) {
|
|
@@ -599,9 +631,9 @@ export class StripLight {
|
|
|
599
631
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
600
632
|
// Make Push On request to the API
|
|
601
633
|
const bodyChange = JSON.stringify({
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
634
|
+
command: 'setColor',
|
|
635
|
+
parameter: `${red}:${green}:${blue}`,
|
|
636
|
+
commandType: 'command',
|
|
605
637
|
});
|
|
606
638
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
607
639
|
try {
|
|
@@ -616,13 +648,16 @@ export class StripLight {
|
|
|
616
648
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
617
649
|
} catch (e: any) {
|
|
618
650
|
this.apiError(e);
|
|
619
|
-
this.errorLog(
|
|
620
|
-
|
|
651
|
+
this.errorLog(
|
|
652
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}` +
|
|
653
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
621
654
|
);
|
|
622
655
|
}
|
|
623
656
|
} else {
|
|
624
|
-
this.debugLog(
|
|
625
|
-
|
|
657
|
+
this.debugLog(
|
|
658
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
|
|
659
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
660
|
+
);
|
|
626
661
|
}
|
|
627
662
|
}
|
|
628
663
|
|
|
@@ -630,9 +665,9 @@ export class StripLight {
|
|
|
630
665
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
631
666
|
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
632
667
|
const bodyChange = JSON.stringify({
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
668
|
+
command: 'setBrightness',
|
|
669
|
+
parameter: `${this.Brightness}`,
|
|
670
|
+
commandType: 'command',
|
|
636
671
|
});
|
|
637
672
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
638
673
|
try {
|
|
@@ -647,13 +682,17 @@ export class StripLight {
|
|
|
647
682
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
648
683
|
} catch (e: any) {
|
|
649
684
|
this.apiError(e);
|
|
650
|
-
this.errorLog(
|
|
651
|
-
|
|
685
|
+
this.errorLog(
|
|
686
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}` +
|
|
687
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
652
688
|
);
|
|
653
689
|
}
|
|
654
690
|
} else {
|
|
655
|
-
this.debugLog(
|
|
656
|
-
|
|
691
|
+
this.debugLog(
|
|
692
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges,` +
|
|
693
|
+
`Brightness: ${this.Brightness}, ` +
|
|
694
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
695
|
+
);
|
|
657
696
|
}
|
|
658
697
|
}
|
|
659
698
|
|
|
@@ -905,8 +944,10 @@ export class StripLight {
|
|
|
905
944
|
this.offlineOff();
|
|
906
945
|
break;
|
|
907
946
|
case 171:
|
|
908
|
-
this.errorLog(
|
|
909
|
-
|
|
947
|
+
this.errorLog(
|
|
948
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
949
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
950
|
+
);
|
|
910
951
|
this.offlineOff();
|
|
911
952
|
break;
|
|
912
953
|
case 190:
|
|
@@ -922,8 +963,10 @@ export class StripLight {
|
|
|
922
963
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
923
964
|
break;
|
|
924
965
|
default:
|
|
925
|
-
this.infoLog(
|
|
926
|
-
|
|
966
|
+
this.infoLog(
|
|
967
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
968
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
969
|
+
);
|
|
927
970
|
}
|
|
928
971
|
}
|
|
929
972
|
|
|
@@ -943,14 +986,17 @@ export class StripLight {
|
|
|
943
986
|
|
|
944
987
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
945
988
|
let FirmwareRevision: string;
|
|
946
|
-
this.debugLog(
|
|
947
|
-
+ `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
989
|
+
this.debugLog(
|
|
990
|
+
`${this.device.deviceType}: ${this.accessory.displayName} ` + `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
991
|
+
);
|
|
948
992
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
949
993
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
950
|
-
if (
|
|
951
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
952
|
-
} else if (device.firmware) {
|
|
994
|
+
if (device.firmware) {
|
|
953
995
|
FirmwareRevision = device.firmware;
|
|
996
|
+
} else if (device.version) {
|
|
997
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
998
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
999
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
954
1000
|
} else {
|
|
955
1001
|
FirmwareRevision = this.platform.version;
|
|
956
1002
|
}
|
|
@@ -1024,7 +1070,7 @@ export class StripLight {
|
|
|
1024
1070
|
config['maxRetry'] = device.maxRetry;
|
|
1025
1071
|
}
|
|
1026
1072
|
if (Object.entries(config).length !== 0) {
|
|
1027
|
-
this.
|
|
1073
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1028
1074
|
}
|
|
1029
1075
|
}
|
|
1030
1076
|
|