@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1
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/.github/npm-version-script.js +81 -0
- 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.map +1 -1
- package/dist/device/blindtilt.js +49 -59
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +44 -50
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +60 -63
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +68 -70
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -25
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -58
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +6 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +168 -26
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +49 -56
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -20
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +59 -61
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +40 -41
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +65 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -33
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -51
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +57 -61
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -31
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +17 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +27 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -26
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +19 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +44 -47
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +17 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -43
- 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 +1 -1
- package/src/device/blindtilt.ts +106 -72
- package/src/device/bot.ts +94 -58
- package/src/device/ceilinglight.ts +102 -68
- package/src/device/colorbulb.ts +134 -82
- package/src/device/contact.ts +54 -33
- package/src/device/curtain.ts +130 -101
- package/src/device/hub.ts +198 -35
- package/src/device/humidifier.ts +128 -80
- package/src/device/iosensor.ts +43 -27
- package/src/device/lightstrip.ts +108 -67
- package/src/device/lock.ts +73 -45
- package/src/device/meter.ts +94 -75
- package/src/device/meterplus.ts +43 -27
- package/src/device/motion.ts +50 -32
- package/src/device/plug.ts +62 -39
- package/src/device/robotvacuumcleaner.ts +78 -54
- package/src/irdevice/airconditioner.ts +111 -83
- package/src/irdevice/airpurifier.ts +55 -34
- package/src/irdevice/camera.ts +35 -23
- package/src/irdevice/fan.ts +47 -33
- package/src/irdevice/light.ts +43 -29
- package/src/irdevice/other.ts +39 -23
- package/src/irdevice/tv.ts +65 -51
- package/src/irdevice/vacuumcleaner.ts +35 -23
- package/src/irdevice/waterheater.ts +43 -27
- package/src/platform.ts +85 -55
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/colorbulb.ts
CHANGED
|
@@ -44,10 +44,10 @@ export class ColorBulb {
|
|
|
44
44
|
wifiRssi: serviceData['wifiRssi'];
|
|
45
45
|
brightnessBLE: serviceData['brightness'];
|
|
46
46
|
color_temperature: serviceData['color_temperature'];
|
|
47
|
-
preset: any
|
|
48
|
-
color_mode: any
|
|
49
|
-
speed: any
|
|
50
|
-
loop_index: any
|
|
47
|
+
preset: any; //serviceData['preset'];
|
|
48
|
+
color_mode: any; //serviceData['color_mode'];
|
|
49
|
+
speed: any; //serviceData['speed'];
|
|
50
|
+
loop_index: any; //serviceData['loop_index'];
|
|
51
51
|
|
|
52
52
|
// Config
|
|
53
53
|
set_minStep?: number;
|
|
@@ -69,10 +69,14 @@ export class ColorBulb {
|
|
|
69
69
|
doColorBulbUpdate!: Subject<void>;
|
|
70
70
|
|
|
71
71
|
// Connection
|
|
72
|
-
private readonly BLE =
|
|
73
|
-
private readonly OpenAPI =
|
|
74
|
-
|
|
75
|
-
constructor(
|
|
72
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
73
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
74
|
+
|
|
75
|
+
constructor(
|
|
76
|
+
private readonly platform: SwitchBotPlatform,
|
|
77
|
+
private accessory: PlatformAccessory,
|
|
78
|
+
public device: device & devicesConfig,
|
|
79
|
+
) {
|
|
76
80
|
// default placeholders
|
|
77
81
|
this.logs(device);
|
|
78
82
|
this.scan(device);
|
|
@@ -213,8 +217,10 @@ export class ColorBulb {
|
|
|
213
217
|
await this.pushChanges();
|
|
214
218
|
} catch (e: any) {
|
|
215
219
|
this.apiError(e);
|
|
216
|
-
this.errorLog(
|
|
217
|
-
|
|
220
|
+
this.errorLog(
|
|
221
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
222
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
223
|
+
);
|
|
218
224
|
}
|
|
219
225
|
this.colorBulbUpdateInProgress = false;
|
|
220
226
|
});
|
|
@@ -232,8 +238,9 @@ export class ColorBulb {
|
|
|
232
238
|
await this.openAPIparseStatus();
|
|
233
239
|
} else {
|
|
234
240
|
await this.offlineOff();
|
|
235
|
-
this.debugWarnLog(
|
|
236
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
241
|
+
this.debugWarnLog(
|
|
242
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
243
|
+
);
|
|
237
244
|
}
|
|
238
245
|
}
|
|
239
246
|
|
|
@@ -249,7 +256,6 @@ export class ColorBulb {
|
|
|
249
256
|
}
|
|
250
257
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
251
258
|
|
|
252
|
-
|
|
253
259
|
// Brightness
|
|
254
260
|
this.Brightness = Number(this.brightnessBLE);
|
|
255
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
@@ -260,8 +266,10 @@ export class ColorBulb {
|
|
|
260
266
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.blue}`);
|
|
261
267
|
|
|
262
268
|
const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
|
|
263
|
-
this.debugLog(
|
|
264
|
-
|
|
269
|
+
this.debugLog(
|
|
270
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
271
|
+
` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`,
|
|
272
|
+
);
|
|
265
273
|
|
|
266
274
|
// Hue
|
|
267
275
|
this.Hue = hue;
|
|
@@ -305,8 +313,9 @@ export class ColorBulb {
|
|
|
305
313
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
306
314
|
|
|
307
315
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
308
|
-
this.debugLog(
|
|
309
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}
|
|
316
|
+
this.debugLog(
|
|
317
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
318
|
+
);
|
|
310
319
|
|
|
311
320
|
// Hue
|
|
312
321
|
this.Hue = hue;
|
|
@@ -341,8 +350,10 @@ export class ColorBulb {
|
|
|
341
350
|
await this.openAPIRefreshStatus();
|
|
342
351
|
} else {
|
|
343
352
|
await this.offlineOff();
|
|
344
|
-
this.debugWarnLog(
|
|
345
|
-
|
|
353
|
+
this.debugWarnLog(
|
|
354
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
355
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
356
|
+
);
|
|
346
357
|
}
|
|
347
358
|
}
|
|
348
359
|
|
|
@@ -367,8 +378,10 @@ export class ColorBulb {
|
|
|
367
378
|
// Set an event hander
|
|
368
379
|
switchbot.onadvertisement = async (ad: any) => {
|
|
369
380
|
this.address = ad.address;
|
|
370
|
-
this.debugLog(
|
|
371
|
-
|
|
381
|
+
this.debugLog(
|
|
382
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
383
|
+
` BLE Address Found: ${this.address}`,
|
|
384
|
+
);
|
|
372
385
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
373
386
|
this.serviceData = ad.serviceData;
|
|
374
387
|
this.powerState = ad.serviceData.power;
|
|
@@ -408,8 +421,10 @@ export class ColorBulb {
|
|
|
408
421
|
})
|
|
409
422
|
.catch(async (e: any) => {
|
|
410
423
|
this.apiError(e);
|
|
411
|
-
this.errorLog(
|
|
412
|
-
|
|
424
|
+
this.errorLog(
|
|
425
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
426
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
427
|
+
);
|
|
413
428
|
await this.BLERefreshConnection(switchbot);
|
|
414
429
|
});
|
|
415
430
|
} else {
|
|
@@ -436,8 +451,10 @@ export class ColorBulb {
|
|
|
436
451
|
this.updateHomeKitCharacteristics();
|
|
437
452
|
} catch (e: any) {
|
|
438
453
|
this.apiError(e);
|
|
439
|
-
this.errorLog(
|
|
440
|
-
|
|
454
|
+
this.errorLog(
|
|
455
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
456
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
457
|
+
);
|
|
441
458
|
}
|
|
442
459
|
}
|
|
443
460
|
|
|
@@ -455,14 +472,15 @@ export class ColorBulb {
|
|
|
455
472
|
async pushChanges(): Promise<void> {
|
|
456
473
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
457
474
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
458
|
-
}
|
|
475
|
+
} /* if (this.BLE) {
|
|
459
476
|
await this.BLEpushChanges();
|
|
460
|
-
} else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
477
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
461
478
|
await this.openAPIpushChanges();
|
|
462
479
|
} else {
|
|
463
480
|
await this.offlineOff();
|
|
464
|
-
this.debugWarnLog(
|
|
465
|
-
|
|
481
|
+
this.debugWarnLog(
|
|
482
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
483
|
+
);
|
|
466
484
|
}
|
|
467
485
|
// Refresh the status from the API
|
|
468
486
|
interval(15000)
|
|
@@ -508,8 +526,10 @@ export class ColorBulb {
|
|
|
508
526
|
})
|
|
509
527
|
.catch(async (e: any) => {
|
|
510
528
|
this.apiError(e);
|
|
511
|
-
this.errorLog(
|
|
512
|
-
|
|
529
|
+
this.errorLog(
|
|
530
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
531
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
532
|
+
);
|
|
513
533
|
await this.BLEPushConnection();
|
|
514
534
|
});
|
|
515
535
|
// Push Brightness Update
|
|
@@ -525,8 +545,9 @@ export class ColorBulb {
|
|
|
525
545
|
await this.BLEpushRGBChanges();
|
|
526
546
|
}
|
|
527
547
|
} else {
|
|
528
|
-
this.debugLog(
|
|
529
|
-
+ `OnCached: ${this.accessory.context.On}
|
|
548
|
+
this.debugLog(
|
|
549
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
|
|
550
|
+
);
|
|
530
551
|
}
|
|
531
552
|
}
|
|
532
553
|
|
|
@@ -555,13 +576,18 @@ export class ColorBulb {
|
|
|
555
576
|
})
|
|
556
577
|
.catch(async (e: any) => {
|
|
557
578
|
this.apiError(e);
|
|
558
|
-
this.errorLog(
|
|
559
|
-
|
|
579
|
+
this.errorLog(
|
|
580
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}` +
|
|
581
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
582
|
+
);
|
|
560
583
|
await this.BLEPushConnection();
|
|
561
584
|
});
|
|
562
585
|
} else {
|
|
563
|
-
this.debugLog(
|
|
564
|
-
|
|
586
|
+
this.debugLog(
|
|
587
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
|
|
588
|
+
`Brightness: ${this.Brightness}, ` +
|
|
589
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
590
|
+
);
|
|
565
591
|
}
|
|
566
592
|
}
|
|
567
593
|
|
|
@@ -590,14 +616,17 @@ export class ColorBulb {
|
|
|
590
616
|
})
|
|
591
617
|
.catch(async (e: any) => {
|
|
592
618
|
this.apiError(e);
|
|
593
|
-
this.errorLog(
|
|
594
|
-
|
|
619
|
+
this.errorLog(
|
|
620
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with ` +
|
|
621
|
+
`${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
622
|
+
);
|
|
595
623
|
await this.BLEPushConnection();
|
|
596
624
|
});
|
|
597
625
|
} else {
|
|
598
|
-
this.debugLog(
|
|
599
|
-
|
|
600
|
-
|
|
626
|
+
this.debugLog(
|
|
627
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
|
|
628
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
|
|
629
|
+
);
|
|
601
630
|
}
|
|
602
631
|
}
|
|
603
632
|
|
|
@@ -623,7 +652,7 @@ export class ColorBulb {
|
|
|
623
652
|
id: this.device.bleMac,
|
|
624
653
|
})
|
|
625
654
|
.then(async (device_list: any) => {
|
|
626
|
-
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
|
|
655
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
|
|
627
656
|
return await device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
628
657
|
})
|
|
629
658
|
.then(() => {
|
|
@@ -632,13 +661,17 @@ export class ColorBulb {
|
|
|
632
661
|
})
|
|
633
662
|
.catch(async (e: any) => {
|
|
634
663
|
this.apiError(e);
|
|
635
|
-
this.errorLog(
|
|
636
|
-
|
|
664
|
+
this.errorLog(
|
|
665
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}` +
|
|
666
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
667
|
+
);
|
|
637
668
|
await this.BLEPushConnection();
|
|
638
669
|
});
|
|
639
670
|
} else {
|
|
640
|
-
this.debugLog(
|
|
641
|
-
|
|
671
|
+
this.debugLog(
|
|
672
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
|
|
673
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
674
|
+
);
|
|
642
675
|
}
|
|
643
676
|
}
|
|
644
677
|
|
|
@@ -652,9 +685,9 @@ export class ColorBulb {
|
|
|
652
685
|
command = 'turnOff';
|
|
653
686
|
}
|
|
654
687
|
const bodyChange = JSON.stringify({
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
688
|
+
command: `${command}`,
|
|
689
|
+
parameter: 'default',
|
|
690
|
+
commandType: 'command',
|
|
658
691
|
});
|
|
659
692
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
660
693
|
try {
|
|
@@ -669,13 +702,17 @@ export class ColorBulb {
|
|
|
669
702
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
670
703
|
} catch (e: any) {
|
|
671
704
|
this.apiError(e);
|
|
672
|
-
this.errorLog(
|
|
673
|
-
|
|
705
|
+
this.errorLog(
|
|
706
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
707
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
674
708
|
);
|
|
675
709
|
}
|
|
676
710
|
} else {
|
|
677
|
-
this.debugLog(
|
|
678
|
-
|
|
711
|
+
this.debugLog(
|
|
712
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
713
|
+
`On: ${this.On}, ` +
|
|
714
|
+
`OnCached: ${this.accessory.context.On}`,
|
|
715
|
+
);
|
|
679
716
|
}
|
|
680
717
|
// Push Hue & Saturation Update
|
|
681
718
|
if (this.On) {
|
|
@@ -699,9 +736,9 @@ export class ColorBulb {
|
|
|
699
736
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
700
737
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
701
738
|
const bodyChange = JSON.stringify({
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
739
|
+
command: 'setColor',
|
|
740
|
+
parameter: `${red}:${green}:${blue}`,
|
|
741
|
+
commandType: 'command',
|
|
705
742
|
});
|
|
706
743
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
707
744
|
try {
|
|
@@ -716,13 +753,16 @@ export class ColorBulb {
|
|
|
716
753
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
717
754
|
} catch (e: any) {
|
|
718
755
|
this.apiError(e);
|
|
719
|
-
this.errorLog(
|
|
720
|
-
|
|
756
|
+
this.errorLog(
|
|
757
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}` +
|
|
758
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
721
759
|
);
|
|
722
760
|
}
|
|
723
761
|
} else {
|
|
724
|
-
this.debugLog(
|
|
725
|
-
|
|
762
|
+
this.debugLog(
|
|
763
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
|
|
764
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
765
|
+
);
|
|
726
766
|
}
|
|
727
767
|
}
|
|
728
768
|
|
|
@@ -732,9 +772,9 @@ export class ColorBulb {
|
|
|
732
772
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
733
773
|
this.cacheKelvin = kelvin;
|
|
734
774
|
const bodyChange = JSON.stringify({
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
775
|
+
command: 'setColorTemperature',
|
|
776
|
+
parameter: `${kelvin}`,
|
|
777
|
+
commandType: 'command',
|
|
738
778
|
});
|
|
739
779
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
740
780
|
try {
|
|
@@ -749,13 +789,16 @@ export class ColorBulb {
|
|
|
749
789
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
750
790
|
} catch (e: any) {
|
|
751
791
|
this.apiError(e);
|
|
752
|
-
this.errorLog(
|
|
753
|
-
|
|
792
|
+
this.errorLog(
|
|
793
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}` +
|
|
794
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
754
795
|
);
|
|
755
796
|
}
|
|
756
797
|
} else {
|
|
757
|
-
this.debugLog(
|
|
758
|
-
|
|
798
|
+
this.debugLog(
|
|
799
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
|
|
800
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
|
|
801
|
+
);
|
|
759
802
|
}
|
|
760
803
|
}
|
|
761
804
|
|
|
@@ -763,9 +806,9 @@ export class ColorBulb {
|
|
|
763
806
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
764
807
|
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
765
808
|
const bodyChange = JSON.stringify({
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
809
|
+
command: 'setBrightness',
|
|
810
|
+
parameter: `${this.Brightness}`,
|
|
811
|
+
commandType: 'command',
|
|
769
812
|
});
|
|
770
813
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
771
814
|
try {
|
|
@@ -780,13 +823,17 @@ export class ColorBulb {
|
|
|
780
823
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
781
824
|
} catch (e: any) {
|
|
782
825
|
this.apiError(e);
|
|
783
|
-
this.errorLog(
|
|
784
|
-
|
|
826
|
+
this.errorLog(
|
|
827
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}` +
|
|
828
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
785
829
|
);
|
|
786
830
|
}
|
|
787
831
|
} else {
|
|
788
|
-
this.debugLog(
|
|
789
|
-
|
|
832
|
+
this.debugLog(
|
|
833
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` +
|
|
834
|
+
`Brightness: ${this.Brightness}, ` +
|
|
835
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
836
|
+
);
|
|
790
837
|
}
|
|
791
838
|
}
|
|
792
839
|
|
|
@@ -1038,14 +1085,16 @@ export class ColorBulb {
|
|
|
1038
1085
|
this.offlineOff();
|
|
1039
1086
|
break;
|
|
1040
1087
|
case 171:
|
|
1041
|
-
this.errorLog(
|
|
1042
|
-
|
|
1088
|
+
this.errorLog(
|
|
1089
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1090
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
1091
|
+
);
|
|
1043
1092
|
this.offlineOff();
|
|
1044
1093
|
break;
|
|
1045
1094
|
case 190:
|
|
1046
1095
|
this.errorLog(
|
|
1047
1096
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1048
|
-
|
|
1097
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
1049
1098
|
);
|
|
1050
1099
|
break;
|
|
1051
1100
|
case 100:
|
|
@@ -1055,8 +1104,10 @@ export class ColorBulb {
|
|
|
1055
1104
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1056
1105
|
break;
|
|
1057
1106
|
default:
|
|
1058
|
-
this.infoLog(
|
|
1059
|
-
|
|
1107
|
+
this.infoLog(
|
|
1108
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1109
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
1110
|
+
);
|
|
1060
1111
|
}
|
|
1061
1112
|
}
|
|
1062
1113
|
|
|
@@ -1077,8 +1128,9 @@ export class ColorBulb {
|
|
|
1077
1128
|
|
|
1078
1129
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1079
1130
|
let FirmwareRevision: string;
|
|
1080
|
-
this.debugLog(
|
|
1081
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
1131
|
+
this.debugLog(
|
|
1132
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
1133
|
+
);
|
|
1082
1134
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1083
1135
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1084
1136
|
if (accessory.context.FirmwareRevision) {
|
package/src/device/contact.ts
CHANGED
|
@@ -59,10 +59,14 @@ export class Contact {
|
|
|
59
59
|
doContactUpdate!: Subject<void>;
|
|
60
60
|
|
|
61
61
|
// Connection
|
|
62
|
-
private readonly BLE =
|
|
63
|
-
private readonly OpenAPI =
|
|
64
|
-
|
|
65
|
-
constructor(
|
|
62
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
63
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
64
|
+
|
|
65
|
+
constructor(
|
|
66
|
+
private readonly platform: SwitchBotPlatform,
|
|
67
|
+
private accessory: PlatformAccessory,
|
|
68
|
+
public device: device & devicesConfig,
|
|
69
|
+
) {
|
|
66
70
|
// default placeholders
|
|
67
71
|
this.logs(device);
|
|
68
72
|
this.scan(device);
|
|
@@ -179,8 +183,9 @@ export class Contact {
|
|
|
179
183
|
await this.openAPIparseStatus();
|
|
180
184
|
} else {
|
|
181
185
|
await this.offlineOff();
|
|
182
|
-
this.debugWarnLog(
|
|
183
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
186
|
+
this.debugWarnLog(
|
|
187
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
188
|
+
);
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
191
|
|
|
@@ -200,15 +205,17 @@ export class Contact {
|
|
|
200
205
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
|
|
201
206
|
}
|
|
202
207
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
203
|
-
if (
|
|
204
|
-
|
|
208
|
+
if (
|
|
209
|
+
this.ContactSensorState !== this.accessory.context.ContactSensorState &&
|
|
210
|
+
this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
|
211
|
+
) {
|
|
205
212
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Opened`);
|
|
206
213
|
}
|
|
207
214
|
// Movement
|
|
208
215
|
if (!this.device.contact?.hide_motionsensor) {
|
|
209
216
|
this.MotionDetected = Boolean(this.movement);
|
|
210
217
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
211
|
-
if (
|
|
218
|
+
if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
|
|
212
219
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
213
220
|
}
|
|
214
221
|
}
|
|
@@ -223,8 +230,10 @@ export class Contact {
|
|
|
223
230
|
default:
|
|
224
231
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
225
232
|
}
|
|
226
|
-
this.debugLog(
|
|
227
|
-
|
|
233
|
+
this.debugLog(
|
|
234
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.is_light},` +
|
|
235
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
236
|
+
);
|
|
228
237
|
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
229
238
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
230
239
|
}
|
|
@@ -239,8 +248,9 @@ export class Contact {
|
|
|
239
248
|
} else {
|
|
240
249
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
241
250
|
}
|
|
242
|
-
this.debugLog(
|
|
243
|
-
+ `StatusLowBattery: ${this.StatusLowBattery}
|
|
251
|
+
this.debugLog(
|
|
252
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
|
|
253
|
+
);
|
|
244
254
|
}
|
|
245
255
|
|
|
246
256
|
async openAPIparseStatus(): Promise<void> {
|
|
@@ -288,8 +298,10 @@ export class Contact {
|
|
|
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
|
|
|
@@ -317,8 +329,10 @@ export class Contact {
|
|
|
317
329
|
this.scanning = true;
|
|
318
330
|
switchbot.onadvertisement = async (ad: any) => {
|
|
319
331
|
this.address = ad.address;
|
|
320
|
-
this.debugLog(
|
|
321
|
-
|
|
332
|
+
this.debugLog(
|
|
333
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
334
|
+
` BLE Address Found: ${this.address}`,
|
|
335
|
+
);
|
|
322
336
|
this.serviceData = ad.serviceData;
|
|
323
337
|
this.movement = ad.serviceData.movement;
|
|
324
338
|
this.tested = ad.serviceData.tested;
|
|
@@ -355,8 +369,10 @@ export class Contact {
|
|
|
355
369
|
})
|
|
356
370
|
.catch(async (e: any) => {
|
|
357
371
|
this.apiError(e);
|
|
358
|
-
this.errorLog(
|
|
359
|
-
|
|
372
|
+
this.errorLog(
|
|
373
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
374
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
375
|
+
);
|
|
360
376
|
await this.BLERefreshConnection(switchbot);
|
|
361
377
|
});
|
|
362
378
|
} else {
|
|
@@ -374,10 +390,7 @@ export class Contact {
|
|
|
374
390
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
375
391
|
this.statusCode(statusCode);
|
|
376
392
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
377
|
-
this.debugLog(
|
|
378
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
379
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
380
|
-
);
|
|
393
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
381
394
|
this.openState = deviceStatus.body.openState;
|
|
382
395
|
this.moveDetected = deviceStatus.body.moveDetected;
|
|
383
396
|
this.brightness = deviceStatus.body.brightness;
|
|
@@ -385,8 +398,10 @@ export class Contact {
|
|
|
385
398
|
this.updateHomeKitCharacteristics();
|
|
386
399
|
} catch (e: any) {
|
|
387
400
|
this.apiError(e);
|
|
388
|
-
this.errorLog(
|
|
389
|
-
|
|
401
|
+
this.errorLog(
|
|
402
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
403
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
404
|
+
);
|
|
390
405
|
}
|
|
391
406
|
}
|
|
392
407
|
|
|
@@ -416,8 +431,9 @@ export class Contact {
|
|
|
416
431
|
} else {
|
|
417
432
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
418
433
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
419
|
-
this.debugLog(
|
|
420
|
-
|
|
434
|
+
this.debugLog(
|
|
435
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
436
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
421
437
|
);
|
|
422
438
|
}
|
|
423
439
|
}
|
|
@@ -523,8 +539,10 @@ export class Contact {
|
|
|
523
539
|
this.offlineOff();
|
|
524
540
|
break;
|
|
525
541
|
case 171:
|
|
526
|
-
this.errorLog(
|
|
527
|
-
|
|
542
|
+
this.errorLog(
|
|
543
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
544
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
545
|
+
);
|
|
528
546
|
this.offlineOff();
|
|
529
547
|
break;
|
|
530
548
|
case 190:
|
|
@@ -540,8 +558,10 @@ export class Contact {
|
|
|
540
558
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
541
559
|
break;
|
|
542
560
|
default:
|
|
543
|
-
this.infoLog(
|
|
544
|
-
|
|
561
|
+
this.infoLog(
|
|
562
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
563
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
564
|
+
);
|
|
545
565
|
}
|
|
546
566
|
}
|
|
547
567
|
|
|
@@ -568,8 +588,9 @@ export class Contact {
|
|
|
568
588
|
|
|
569
589
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
570
590
|
let FirmwareRevision: string;
|
|
571
|
-
this.debugLog(
|
|
572
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
591
|
+
this.debugLog(
|
|
592
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
593
|
+
);
|
|
573
594
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
574
595
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
575
596
|
if (accessory.context.FirmwareRevision) {
|