@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/colorbulb.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 ColorBulb {
|
|
|
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'];
|
|
@@ -44,10 +46,10 @@ export class ColorBulb {
|
|
|
44
46
|
wifiRssi: serviceData['wifiRssi'];
|
|
45
47
|
brightnessBLE: serviceData['brightness'];
|
|
46
48
|
color_temperature: serviceData['color_temperature'];
|
|
47
|
-
preset: any
|
|
48
|
-
color_mode: any
|
|
49
|
-
speed: any
|
|
50
|
-
loop_index: any
|
|
49
|
+
preset: any; //serviceData['preset'];
|
|
50
|
+
color_mode: any; //serviceData['color_mode'];
|
|
51
|
+
speed: any; //serviceData['speed'];
|
|
52
|
+
loop_index: any; //serviceData['loop_index'];
|
|
51
53
|
|
|
52
54
|
// Config
|
|
53
55
|
set_minStep?: number;
|
|
@@ -69,17 +71,22 @@ export class ColorBulb {
|
|
|
69
71
|
doColorBulbUpdate!: Subject<void>;
|
|
70
72
|
|
|
71
73
|
// Connection
|
|
72
|
-
private readonly BLE =
|
|
73
|
-
private readonly OpenAPI =
|
|
74
|
-
|
|
75
|
-
constructor(
|
|
74
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
75
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
76
|
+
|
|
77
|
+
constructor(
|
|
78
|
+
private readonly platform: SwitchBotPlatform,
|
|
79
|
+
private accessory: PlatformAccessory,
|
|
80
|
+
public device: device & devicesConfig,
|
|
81
|
+
) {
|
|
76
82
|
// default placeholders
|
|
77
83
|
this.logs(device);
|
|
78
84
|
this.scan(device);
|
|
79
85
|
this.refreshRate(device);
|
|
80
86
|
this.adaptiveLighting(device);
|
|
81
|
-
this.config(device);
|
|
82
87
|
this.context();
|
|
88
|
+
this.config(device);
|
|
89
|
+
|
|
83
90
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
84
91
|
this.doColorBulbUpdate = new Subject();
|
|
85
92
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -213,8 +220,10 @@ export class ColorBulb {
|
|
|
213
220
|
await this.pushChanges();
|
|
214
221
|
} catch (e: any) {
|
|
215
222
|
this.apiError(e);
|
|
216
|
-
this.errorLog(
|
|
217
|
-
|
|
223
|
+
this.errorLog(
|
|
224
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
225
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
226
|
+
);
|
|
218
227
|
}
|
|
219
228
|
this.colorBulbUpdateInProgress = false;
|
|
220
229
|
});
|
|
@@ -232,8 +241,9 @@ export class ColorBulb {
|
|
|
232
241
|
await this.openAPIparseStatus();
|
|
233
242
|
} else {
|
|
234
243
|
await this.offlineOff();
|
|
235
|
-
this.debugWarnLog(
|
|
236
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
244
|
+
this.debugWarnLog(
|
|
245
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
246
|
+
);
|
|
237
247
|
}
|
|
238
248
|
}
|
|
239
249
|
|
|
@@ -249,7 +259,6 @@ export class ColorBulb {
|
|
|
249
259
|
}
|
|
250
260
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
251
261
|
|
|
252
|
-
|
|
253
262
|
// Brightness
|
|
254
263
|
this.Brightness = Number(this.brightnessBLE);
|
|
255
264
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
@@ -260,8 +269,10 @@ export class ColorBulb {
|
|
|
260
269
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.blue}`);
|
|
261
270
|
|
|
262
271
|
const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
|
|
263
|
-
this.debugLog(
|
|
264
|
-
|
|
272
|
+
this.debugLog(
|
|
273
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
274
|
+
` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`,
|
|
275
|
+
);
|
|
265
276
|
|
|
266
277
|
// Hue
|
|
267
278
|
this.Hue = hue;
|
|
@@ -305,8 +316,9 @@ export class ColorBulb {
|
|
|
305
316
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
306
317
|
|
|
307
318
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
308
|
-
this.debugLog(
|
|
309
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}
|
|
319
|
+
this.debugLog(
|
|
320
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
321
|
+
);
|
|
310
322
|
|
|
311
323
|
// Hue
|
|
312
324
|
this.Hue = hue;
|
|
@@ -341,8 +353,10 @@ export class ColorBulb {
|
|
|
341
353
|
await this.openAPIRefreshStatus();
|
|
342
354
|
} else {
|
|
343
355
|
await this.offlineOff();
|
|
344
|
-
this.debugWarnLog(
|
|
345
|
-
|
|
356
|
+
this.debugWarnLog(
|
|
357
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
358
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
359
|
+
);
|
|
346
360
|
}
|
|
347
361
|
}
|
|
348
362
|
|
|
@@ -367,8 +381,10 @@ export class ColorBulb {
|
|
|
367
381
|
// Set an event hander
|
|
368
382
|
switchbot.onadvertisement = async (ad: any) => {
|
|
369
383
|
this.address = ad.address;
|
|
370
|
-
this.debugLog(
|
|
371
|
-
|
|
384
|
+
this.debugLog(
|
|
385
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
386
|
+
` BLE Address Found: ${this.address}`,
|
|
387
|
+
);
|
|
372
388
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
373
389
|
this.serviceData = ad.serviceData;
|
|
374
390
|
this.powerState = ad.serviceData.power;
|
|
@@ -408,8 +424,10 @@ export class ColorBulb {
|
|
|
408
424
|
})
|
|
409
425
|
.catch(async (e: any) => {
|
|
410
426
|
this.apiError(e);
|
|
411
|
-
this.errorLog(
|
|
412
|
-
|
|
427
|
+
this.errorLog(
|
|
428
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
429
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
430
|
+
);
|
|
413
431
|
await this.BLERefreshConnection(switchbot);
|
|
414
432
|
});
|
|
415
433
|
} else {
|
|
@@ -436,8 +454,10 @@ export class ColorBulb {
|
|
|
436
454
|
this.updateHomeKitCharacteristics();
|
|
437
455
|
} catch (e: any) {
|
|
438
456
|
this.apiError(e);
|
|
439
|
-
this.errorLog(
|
|
440
|
-
|
|
457
|
+
this.errorLog(
|
|
458
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
459
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
460
|
+
);
|
|
441
461
|
}
|
|
442
462
|
}
|
|
443
463
|
|
|
@@ -455,14 +475,15 @@ export class ColorBulb {
|
|
|
455
475
|
async pushChanges(): Promise<void> {
|
|
456
476
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
457
477
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
458
|
-
}
|
|
478
|
+
} /* if (this.BLE) {
|
|
459
479
|
await this.BLEpushChanges();
|
|
460
|
-
} else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
480
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
461
481
|
await this.openAPIpushChanges();
|
|
462
482
|
} else {
|
|
463
483
|
await this.offlineOff();
|
|
464
|
-
this.debugWarnLog(
|
|
465
|
-
|
|
484
|
+
this.debugWarnLog(
|
|
485
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
486
|
+
);
|
|
466
487
|
}
|
|
467
488
|
// Refresh the status from the API
|
|
468
489
|
interval(15000)
|
|
@@ -508,8 +529,10 @@ export class ColorBulb {
|
|
|
508
529
|
})
|
|
509
530
|
.catch(async (e: any) => {
|
|
510
531
|
this.apiError(e);
|
|
511
|
-
this.errorLog(
|
|
512
|
-
|
|
532
|
+
this.errorLog(
|
|
533
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
534
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
535
|
+
);
|
|
513
536
|
await this.BLEPushConnection();
|
|
514
537
|
});
|
|
515
538
|
// Push Brightness Update
|
|
@@ -525,8 +548,9 @@ export class ColorBulb {
|
|
|
525
548
|
await this.BLEpushRGBChanges();
|
|
526
549
|
}
|
|
527
550
|
} else {
|
|
528
|
-
this.debugLog(
|
|
529
|
-
+ `OnCached: ${this.accessory.context.On}
|
|
551
|
+
this.debugLog(
|
|
552
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
|
|
553
|
+
);
|
|
530
554
|
}
|
|
531
555
|
}
|
|
532
556
|
|
|
@@ -555,13 +579,18 @@ export class ColorBulb {
|
|
|
555
579
|
})
|
|
556
580
|
.catch(async (e: any) => {
|
|
557
581
|
this.apiError(e);
|
|
558
|
-
this.errorLog(
|
|
559
|
-
|
|
582
|
+
this.errorLog(
|
|
583
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}` +
|
|
584
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
585
|
+
);
|
|
560
586
|
await this.BLEPushConnection();
|
|
561
587
|
});
|
|
562
588
|
} else {
|
|
563
|
-
this.debugLog(
|
|
564
|
-
|
|
589
|
+
this.debugLog(
|
|
590
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
|
|
591
|
+
`Brightness: ${this.Brightness}, ` +
|
|
592
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
593
|
+
);
|
|
565
594
|
}
|
|
566
595
|
}
|
|
567
596
|
|
|
@@ -590,14 +619,17 @@ export class ColorBulb {
|
|
|
590
619
|
})
|
|
591
620
|
.catch(async (e: any) => {
|
|
592
621
|
this.apiError(e);
|
|
593
|
-
this.errorLog(
|
|
594
|
-
|
|
622
|
+
this.errorLog(
|
|
623
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with ` +
|
|
624
|
+
`${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
625
|
+
);
|
|
595
626
|
await this.BLEPushConnection();
|
|
596
627
|
});
|
|
597
628
|
} else {
|
|
598
|
-
this.debugLog(
|
|
599
|
-
|
|
600
|
-
|
|
629
|
+
this.debugLog(
|
|
630
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
|
|
631
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
|
|
632
|
+
);
|
|
601
633
|
}
|
|
602
634
|
}
|
|
603
635
|
|
|
@@ -623,7 +655,7 @@ export class ColorBulb {
|
|
|
623
655
|
id: this.device.bleMac,
|
|
624
656
|
})
|
|
625
657
|
.then(async (device_list: any) => {
|
|
626
|
-
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
|
|
658
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
|
|
627
659
|
return await device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
628
660
|
})
|
|
629
661
|
.then(() => {
|
|
@@ -632,13 +664,17 @@ export class ColorBulb {
|
|
|
632
664
|
})
|
|
633
665
|
.catch(async (e: any) => {
|
|
634
666
|
this.apiError(e);
|
|
635
|
-
this.errorLog(
|
|
636
|
-
|
|
667
|
+
this.errorLog(
|
|
668
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}` +
|
|
669
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
670
|
+
);
|
|
637
671
|
await this.BLEPushConnection();
|
|
638
672
|
});
|
|
639
673
|
} else {
|
|
640
|
-
this.debugLog(
|
|
641
|
-
|
|
674
|
+
this.debugLog(
|
|
675
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
|
|
676
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
677
|
+
);
|
|
642
678
|
}
|
|
643
679
|
}
|
|
644
680
|
|
|
@@ -652,9 +688,9 @@ export class ColorBulb {
|
|
|
652
688
|
command = 'turnOff';
|
|
653
689
|
}
|
|
654
690
|
const bodyChange = JSON.stringify({
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
691
|
+
command: `${command}`,
|
|
692
|
+
parameter: 'default',
|
|
693
|
+
commandType: 'command',
|
|
658
694
|
});
|
|
659
695
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
660
696
|
try {
|
|
@@ -669,13 +705,17 @@ export class ColorBulb {
|
|
|
669
705
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
670
706
|
} catch (e: any) {
|
|
671
707
|
this.apiError(e);
|
|
672
|
-
this.errorLog(
|
|
673
|
-
|
|
708
|
+
this.errorLog(
|
|
709
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
710
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
674
711
|
);
|
|
675
712
|
}
|
|
676
713
|
} else {
|
|
677
|
-
this.debugLog(
|
|
678
|
-
|
|
714
|
+
this.debugLog(
|
|
715
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
716
|
+
`On: ${this.On}, ` +
|
|
717
|
+
`OnCached: ${this.accessory.context.On}`,
|
|
718
|
+
);
|
|
679
719
|
}
|
|
680
720
|
// Push Hue & Saturation Update
|
|
681
721
|
if (this.On) {
|
|
@@ -699,9 +739,9 @@ export class ColorBulb {
|
|
|
699
739
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
700
740
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
701
741
|
const bodyChange = JSON.stringify({
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
742
|
+
command: 'setColor',
|
|
743
|
+
parameter: `${red}:${green}:${blue}`,
|
|
744
|
+
commandType: 'command',
|
|
705
745
|
});
|
|
706
746
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
707
747
|
try {
|
|
@@ -716,13 +756,16 @@ export class ColorBulb {
|
|
|
716
756
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
717
757
|
} catch (e: any) {
|
|
718
758
|
this.apiError(e);
|
|
719
|
-
this.errorLog(
|
|
720
|
-
|
|
759
|
+
this.errorLog(
|
|
760
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}` +
|
|
761
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
721
762
|
);
|
|
722
763
|
}
|
|
723
764
|
} else {
|
|
724
|
-
this.debugLog(
|
|
725
|
-
|
|
765
|
+
this.debugLog(
|
|
766
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
|
|
767
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
768
|
+
);
|
|
726
769
|
}
|
|
727
770
|
}
|
|
728
771
|
|
|
@@ -732,9 +775,9 @@ export class ColorBulb {
|
|
|
732
775
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
733
776
|
this.cacheKelvin = kelvin;
|
|
734
777
|
const bodyChange = JSON.stringify({
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
778
|
+
command: 'setColorTemperature',
|
|
779
|
+
parameter: `${kelvin}`,
|
|
780
|
+
commandType: 'command',
|
|
738
781
|
});
|
|
739
782
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
740
783
|
try {
|
|
@@ -749,13 +792,16 @@ export class ColorBulb {
|
|
|
749
792
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
750
793
|
} catch (e: any) {
|
|
751
794
|
this.apiError(e);
|
|
752
|
-
this.errorLog(
|
|
753
|
-
|
|
795
|
+
this.errorLog(
|
|
796
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}` +
|
|
797
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
754
798
|
);
|
|
755
799
|
}
|
|
756
800
|
} else {
|
|
757
|
-
this.debugLog(
|
|
758
|
-
|
|
801
|
+
this.debugLog(
|
|
802
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
|
|
803
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
|
|
804
|
+
);
|
|
759
805
|
}
|
|
760
806
|
}
|
|
761
807
|
|
|
@@ -763,9 +809,9 @@ export class ColorBulb {
|
|
|
763
809
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
764
810
|
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
765
811
|
const bodyChange = JSON.stringify({
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
812
|
+
command: 'setBrightness',
|
|
813
|
+
parameter: `${this.Brightness}`,
|
|
814
|
+
commandType: 'command',
|
|
769
815
|
});
|
|
770
816
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
771
817
|
try {
|
|
@@ -780,13 +826,17 @@ export class ColorBulb {
|
|
|
780
826
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
781
827
|
} catch (e: any) {
|
|
782
828
|
this.apiError(e);
|
|
783
|
-
this.errorLog(
|
|
784
|
-
|
|
829
|
+
this.errorLog(
|
|
830
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}` +
|
|
831
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
785
832
|
);
|
|
786
833
|
}
|
|
787
834
|
} else {
|
|
788
|
-
this.debugLog(
|
|
789
|
-
|
|
835
|
+
this.debugLog(
|
|
836
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` +
|
|
837
|
+
`Brightness: ${this.Brightness}, ` +
|
|
838
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
839
|
+
);
|
|
790
840
|
}
|
|
791
841
|
}
|
|
792
842
|
|
|
@@ -1038,14 +1088,16 @@ export class ColorBulb {
|
|
|
1038
1088
|
this.offlineOff();
|
|
1039
1089
|
break;
|
|
1040
1090
|
case 171:
|
|
1041
|
-
this.errorLog(
|
|
1042
|
-
|
|
1091
|
+
this.errorLog(
|
|
1092
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1093
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
1094
|
+
);
|
|
1043
1095
|
this.offlineOff();
|
|
1044
1096
|
break;
|
|
1045
1097
|
case 190:
|
|
1046
1098
|
this.errorLog(
|
|
1047
1099
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1048
|
-
|
|
1100
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
1049
1101
|
);
|
|
1050
1102
|
break;
|
|
1051
1103
|
case 100:
|
|
@@ -1055,8 +1107,10 @@ export class ColorBulb {
|
|
|
1055
1107
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1056
1108
|
break;
|
|
1057
1109
|
default:
|
|
1058
|
-
this.infoLog(
|
|
1059
|
-
|
|
1110
|
+
this.infoLog(
|
|
1111
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1112
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
1113
|
+
);
|
|
1060
1114
|
}
|
|
1061
1115
|
}
|
|
1062
1116
|
|
|
@@ -1077,14 +1131,17 @@ export class ColorBulb {
|
|
|
1077
1131
|
|
|
1078
1132
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1079
1133
|
let FirmwareRevision: string;
|
|
1080
|
-
this.debugLog(
|
|
1081
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
1134
|
+
this.debugLog(
|
|
1135
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
1136
|
+
);
|
|
1082
1137
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1083
1138
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1084
|
-
if (
|
|
1085
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1086
|
-
} else if (device.firmware) {
|
|
1139
|
+
if (device.firmware) {
|
|
1087
1140
|
FirmwareRevision = device.firmware;
|
|
1141
|
+
} else if (device.version) {
|
|
1142
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
1143
|
+
} if (accessory.context.FirmwareRevision) {
|
|
1144
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1088
1145
|
} else {
|
|
1089
1146
|
FirmwareRevision = this.platform.version;
|
|
1090
1147
|
}
|
|
@@ -1158,7 +1215,7 @@ export class ColorBulb {
|
|
|
1158
1215
|
config['maxRetry'] = device.maxRetry;
|
|
1159
1216
|
}
|
|
1160
1217
|
if (Object.entries(config).length !== 0) {
|
|
1161
|
-
this.
|
|
1218
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1162
1219
|
}
|
|
1163
1220
|
}
|
|
1164
1221
|
|