@switchbot/homebridge-switchbot 2.6.0-beta.4 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/tasks.json +13 -0
- package/CHANGELOG.md +4 -2
- package/README.md +18 -9
- package/dist/device/blindtilt.d.ts +1 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +80 -140
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +79 -138
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +2 -6
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +157 -304
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -6
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +164 -311
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +36 -72
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +78 -138
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +2 -6
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +30 -63
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +115 -228
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +38 -74
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/{striplight.d.ts → lightstrip.d.ts} +2 -10
- package/dist/device/lightstrip.d.ts.map +1 -0
- package/dist/device/{striplight.js → lightstrip.js} +138 -194
- package/dist/device/lightstrip.js.map +1 -0
- package/dist/device/lock.d.ts +1 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +66 -126
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +38 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +39 -75
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +35 -72
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +65 -126
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +79 -151
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -7
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +34 -62
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -7
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +31 -59
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -5
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +30 -57
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +39 -66
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -5
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +32 -59
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -5
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +30 -57
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +3 -7
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +46 -76
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +30 -58
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -23
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +41 -74
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +156 -149
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +5 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +122 -181
- package/src/device/bot.ts +96 -149
- package/src/device/ceilinglight.ts +172 -315
- package/src/device/colorbulb.ts +178 -324
- package/src/device/contact.ts +48 -78
- package/src/device/curtain.ts +93 -148
- package/src/device/hub.ts +34 -63
- package/src/device/humidifier.ts +135 -243
- package/src/device/iosensor.ts +49 -79
- package/src/device/{striplight.ts → lightstrip.ts} +148 -200
- package/src/device/lock.ts +78 -134
- package/src/device/meter.ts +48 -78
- package/src/device/meterplus.ts +50 -80
- package/src/device/motion.ts +46 -77
- package/src/device/plug.ts +76 -134
- package/src/device/robotvacuumcleaner.ts +91 -159
- package/src/irdevice/airconditioner.ts +56 -81
- package/src/irdevice/airpurifier.ts +41 -67
- package/src/irdevice/camera.ts +35 -60
- package/src/irdevice/fan.ts +46 -71
- package/src/irdevice/light.ts +38 -63
- package/src/irdevice/other.ts +35 -60
- package/src/irdevice/tv.ts +52 -80
- package/src/irdevice/vacuumcleaner.ts +36 -62
- package/src/irdevice/waterheater.ts +46 -76
- package/src/platform.ts +144 -158
- package/src/settings.ts +5 -0
- package/.github/npm-version-script.js +0 -81
- package/dist/device/striplight.d.ts.map +0 -1
- package/dist/device/striplight.js.map +0 -1
package/src/device/bot.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
import crypto from 'crypto';
|
|
3
1
|
import { Context } from 'vm';
|
|
4
|
-
import {
|
|
2
|
+
import { request } from 'undici';
|
|
3
|
+
import { sleep } from '../utils';
|
|
5
4
|
import { interval, Subject } from 'rxjs';
|
|
6
|
-
import superStringify from 'super-stringify';
|
|
7
5
|
import { SwitchBotPlatform } from '../platform';
|
|
8
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
9
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot,
|
|
11
|
-
import { sleep } from '../utils';
|
|
8
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot, Devices } from '../settings';
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Platform Accessory
|
|
@@ -396,7 +393,7 @@ export class Bot {
|
|
|
396
393
|
} catch (e: any) {
|
|
397
394
|
this.apiError(e);
|
|
398
395
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
399
|
-
|
|
396
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
400
397
|
}
|
|
401
398
|
this.botUpdateInProgress = false;
|
|
402
399
|
});
|
|
@@ -415,7 +412,7 @@ export class Bot {
|
|
|
415
412
|
} else {
|
|
416
413
|
await this.offlineOff();
|
|
417
414
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
418
|
-
|
|
415
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
419
416
|
}
|
|
420
417
|
}
|
|
421
418
|
|
|
@@ -473,7 +470,7 @@ export class Bot {
|
|
|
473
470
|
} else {
|
|
474
471
|
await this.offlineOff();
|
|
475
472
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
476
|
-
|
|
473
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
477
474
|
}
|
|
478
475
|
}
|
|
479
476
|
|
|
@@ -495,18 +492,18 @@ export class Bot {
|
|
|
495
492
|
id: this.device.bleMac,
|
|
496
493
|
})
|
|
497
494
|
.then(async () => {
|
|
498
|
-
|
|
495
|
+
// Set an event hander
|
|
499
496
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
500
497
|
this.address = ad.address;
|
|
501
498
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
502
|
-
|
|
499
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
503
500
|
this.serviceData = ad.serviceData;
|
|
504
501
|
this.mode = ad.serviceData.mode;
|
|
505
502
|
this.state = ad.serviceData.state;
|
|
506
503
|
this.battery = ad.serviceData.battery;
|
|
507
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
504
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
508
505
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: `
|
|
509
|
-
|
|
506
|
+
+ `${ad.serviceData.modelName}, mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
|
|
510
507
|
|
|
511
508
|
if (this.serviceData) {
|
|
512
509
|
this.connected = true;
|
|
@@ -521,13 +518,13 @@ export class Bot {
|
|
|
521
518
|
return await sleep(this.scanDuration * 1000);
|
|
522
519
|
})
|
|
523
520
|
.then(async () => {
|
|
524
|
-
|
|
521
|
+
// Stop to monitor
|
|
525
522
|
await this.stopScanning(switchbot);
|
|
526
523
|
})
|
|
527
524
|
.catch(async (e: any) => {
|
|
528
525
|
this.apiError(e);
|
|
529
526
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
530
|
-
|
|
527
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
531
528
|
await this.BLERefreshConnection(switchbot);
|
|
532
529
|
});
|
|
533
530
|
} else {
|
|
@@ -536,53 +533,26 @@ export class Bot {
|
|
|
536
533
|
}
|
|
537
534
|
|
|
538
535
|
async openAPIRefreshStatus(): Promise<void> {
|
|
536
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
539
537
|
try {
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
543
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
544
|
-
const sign = signTerm.toString('base64');
|
|
545
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
546
|
-
const options = {
|
|
547
|
-
hostname: HostDomain,
|
|
548
|
-
port: 443,
|
|
549
|
-
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
550
|
-
method: 'GET',
|
|
551
|
-
headers: {
|
|
552
|
-
Authorization: this.platform.config.credentials?.token,
|
|
553
|
-
sign: sign,
|
|
554
|
-
nonce: nonce,
|
|
555
|
-
t: t,
|
|
556
|
-
'Content-Type': 'application/json',
|
|
557
|
-
},
|
|
558
|
-
};
|
|
559
|
-
const req = https.request(options, (res) => {
|
|
560
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
561
|
-
let rawData = '';
|
|
562
|
-
res.on('data', (d) => {
|
|
563
|
-
rawData += d;
|
|
564
|
-
this.debugLog(`d: ${d}`);
|
|
565
|
-
});
|
|
566
|
-
res.on('end', () => {
|
|
567
|
-
try {
|
|
568
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
569
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
570
|
-
this.power = this.deviceStatus.body.power;
|
|
571
|
-
this.openAPIparseStatus();
|
|
572
|
-
this.updateHomeKitCharacteristics();
|
|
573
|
-
} catch (e: any) {
|
|
574
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
req.on('error', (e: any) => {
|
|
579
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
538
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
539
|
+
headers: this.platform.generateHeaders(),
|
|
580
540
|
});
|
|
581
|
-
|
|
541
|
+
const deviceStatus = await body.json();
|
|
542
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
543
|
+
this.statusCode(statusCode);
|
|
544
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
545
|
+
this.debugLog(
|
|
546
|
+
`${this.device.deviceType}: ${this.accessory.displayName
|
|
547
|
+
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
548
|
+
);
|
|
549
|
+
this.power = deviceStatus.body.power;
|
|
550
|
+
this.openAPIparseStatus();
|
|
551
|
+
this.updateHomeKitCharacteristics();
|
|
582
552
|
} catch (e: any) {
|
|
583
553
|
this.apiError(e);
|
|
584
554
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
585
|
-
|
|
555
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
586
556
|
}
|
|
587
557
|
}
|
|
588
558
|
|
|
@@ -603,7 +573,7 @@ export class Bot {
|
|
|
603
573
|
} else {
|
|
604
574
|
await this.offlineOff();
|
|
605
575
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
606
|
-
|
|
576
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
607
577
|
}
|
|
608
578
|
// Refresh the status from the API
|
|
609
579
|
interval(15000)
|
|
@@ -649,7 +619,7 @@ export class Bot {
|
|
|
649
619
|
.catch(async (e: any) => {
|
|
650
620
|
this.apiError(e);
|
|
651
621
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
652
|
-
|
|
622
|
+
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
653
623
|
await this.BLEPushConnection();
|
|
654
624
|
});
|
|
655
625
|
} else if (this.botMode === 'switch') {
|
|
@@ -676,7 +646,7 @@ export class Bot {
|
|
|
676
646
|
.catch(async (e: any) => {
|
|
677
647
|
this.apiError(e);
|
|
678
648
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
679
|
-
|
|
649
|
+
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
680
650
|
await this.BLEPushConnection();
|
|
681
651
|
});
|
|
682
652
|
} else {
|
|
@@ -684,76 +654,48 @@ export class Bot {
|
|
|
684
654
|
}
|
|
685
655
|
} else {
|
|
686
656
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
687
|
-
|
|
657
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
688
658
|
}
|
|
689
659
|
}
|
|
690
660
|
|
|
691
661
|
async openAPIpushChanges(): Promise<void> {
|
|
662
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
692
663
|
if (this.multiPressCount > 0) {
|
|
693
664
|
this.debugLog(`${this.device.deviceType}: ${this.multiPressCount} request(s) queued.`);
|
|
694
665
|
this.On = true;
|
|
695
666
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
if (
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
} else {
|
|
722
|
-
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
|
|
723
|
-
}
|
|
724
|
-
const body = superStringify({
|
|
725
|
-
'command': `${command}`,
|
|
726
|
-
'parameter': 'default',
|
|
727
|
-
'commandType': 'command',
|
|
728
|
-
});
|
|
729
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
730
|
-
const options = {
|
|
731
|
-
hostname: HostDomain,
|
|
732
|
-
port: 443,
|
|
733
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
667
|
+
if ((this.On !== this.accessory.context.On || this.allowPush) || this.multiPressCount > 0) {
|
|
668
|
+
let command = '';
|
|
669
|
+
if (this.botMode === 'switch' && this.On) {
|
|
670
|
+
command = 'turnOn';
|
|
671
|
+
this.On = true;
|
|
672
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
673
|
+
} else if (this.botMode === 'switch' && !this.On) {
|
|
674
|
+
command = 'turnOff';
|
|
675
|
+
this.On = false;
|
|
676
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
677
|
+
} else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
678
|
+
command = 'press';
|
|
679
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode`);
|
|
680
|
+
this.On = false;
|
|
681
|
+
} else {
|
|
682
|
+
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
|
|
683
|
+
}
|
|
684
|
+
const body = JSON.stringify({
|
|
685
|
+
'command': `${command}`,
|
|
686
|
+
'parameter': 'default',
|
|
687
|
+
'commandType': 'command',
|
|
688
|
+
});
|
|
689
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
690
|
+
try {
|
|
691
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
734
692
|
method: 'POST',
|
|
735
|
-
headers:
|
|
736
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
737
|
-
'sign': sign,
|
|
738
|
-
'nonce': nonce,
|
|
739
|
-
't': t,
|
|
740
|
-
'Content-Type': 'application/json',
|
|
741
|
-
'Content-Length': body.length,
|
|
742
|
-
},
|
|
743
|
-
};
|
|
744
|
-
const req = https.request(options, res => {
|
|
745
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
746
|
-
this.statusCode({ res });
|
|
747
|
-
res.on('data', d => {
|
|
748
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
749
|
-
});
|
|
750
|
-
});
|
|
751
|
-
req.on('error', (e: any) => {
|
|
752
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
693
|
+
headers: this.platform.generateHeaders(),
|
|
753
694
|
});
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
this.
|
|
695
|
+
const deviceStatus = await body.json();
|
|
696
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
697
|
+
this.statusCode(statusCode);
|
|
698
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
757
699
|
if (this.device.bot?.mode === 'multipress') {
|
|
758
700
|
this.multiPressCount--;
|
|
759
701
|
if (this.multiPressCount > 0) {
|
|
@@ -762,15 +704,15 @@ export class Bot {
|
|
|
762
704
|
this.openAPIpushChanges();
|
|
763
705
|
}
|
|
764
706
|
}
|
|
765
|
-
}
|
|
766
|
-
this.
|
|
767
|
-
|
|
707
|
+
} catch (e: any) {
|
|
708
|
+
this.apiError(e);
|
|
709
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
710
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
711
|
+
);
|
|
768
712
|
}
|
|
769
|
-
}
|
|
770
|
-
this.
|
|
771
|
-
|
|
772
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`,
|
|
773
|
-
);
|
|
713
|
+
} else {
|
|
714
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
715
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
774
716
|
}
|
|
775
717
|
}
|
|
776
718
|
|
|
@@ -849,7 +791,7 @@ export class Bot {
|
|
|
849
791
|
this.platform.Characteristic.CurrentDoorState.OPEN,
|
|
850
792
|
);
|
|
851
793
|
this.debugLog(`${this.device.deviceType}: `
|
|
852
|
-
|
|
794
|
+
+ `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
|
|
853
795
|
} else {
|
|
854
796
|
this.garageDoorService?.updateCharacteristic(
|
|
855
797
|
this.platform.Characteristic.TargetDoorState,
|
|
@@ -860,7 +802,7 @@ export class Bot {
|
|
|
860
802
|
this.platform.Characteristic.CurrentDoorState.CLOSED,
|
|
861
803
|
);
|
|
862
804
|
this.debugLog(`${this.device.deviceType}: `
|
|
863
|
-
|
|
805
|
+
+ `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
|
|
864
806
|
}
|
|
865
807
|
}
|
|
866
808
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Garage Door On: ${this.On}`);
|
|
@@ -935,7 +877,7 @@ export class Bot {
|
|
|
935
877
|
this.platform.Characteristic.LockCurrentState.UNSECURED,
|
|
936
878
|
);
|
|
937
879
|
this.debugLog(`${this.device.deviceType}: `
|
|
938
|
-
|
|
880
|
+
+ `${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`);
|
|
939
881
|
} else {
|
|
940
882
|
this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.platform.Characteristic.LockTargetState.SECURED);
|
|
941
883
|
this.lockService?.updateCharacteristic(
|
|
@@ -943,7 +885,7 @@ export class Bot {
|
|
|
943
885
|
this.platform.Characteristic.LockCurrentState.SECURED,
|
|
944
886
|
);
|
|
945
887
|
this.debugLog(`${this.device.deviceType}: `
|
|
946
|
-
|
|
888
|
+
+ `${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`);
|
|
947
889
|
}
|
|
948
890
|
}
|
|
949
891
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
@@ -984,7 +926,7 @@ export class Bot {
|
|
|
984
926
|
);
|
|
985
927
|
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
986
928
|
this.debugLog(`${this.device.deviceType}: `
|
|
987
|
-
|
|
929
|
+
+ `${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
|
|
988
930
|
} else {
|
|
989
931
|
this.statefulProgrammableSwitchService?.updateCharacteristic(
|
|
990
932
|
this.platform.Characteristic.ProgrammableSwitchEvent,
|
|
@@ -992,7 +934,7 @@ export class Bot {
|
|
|
992
934
|
);
|
|
993
935
|
this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
994
936
|
this.debugLog(`${this.device.deviceType}: `
|
|
995
|
-
|
|
937
|
+
+ `${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
|
|
996
938
|
}
|
|
997
939
|
}
|
|
998
940
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
|
|
@@ -1148,7 +1090,7 @@ export class Bot {
|
|
|
1148
1090
|
});
|
|
1149
1091
|
// Set an event handler
|
|
1150
1092
|
switchbot.onadvertisement = (ad: any) => {
|
|
1151
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
1093
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
1152
1094
|
};
|
|
1153
1095
|
await sleep(10000);
|
|
1154
1096
|
// Stop to monitor
|
|
@@ -1234,36 +1176,41 @@ export class Bot {
|
|
|
1234
1176
|
}
|
|
1235
1177
|
}
|
|
1236
1178
|
|
|
1237
|
-
async statusCode(
|
|
1238
|
-
switch (
|
|
1179
|
+
async statusCode(statusCode: number): Promise<void> {
|
|
1180
|
+
switch (statusCode) {
|
|
1239
1181
|
case 151:
|
|
1240
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
1182
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
1241
1183
|
break;
|
|
1242
1184
|
case 152:
|
|
1243
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
1185
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
1244
1186
|
break;
|
|
1245
1187
|
case 160:
|
|
1246
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
1188
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
1247
1189
|
break;
|
|
1248
1190
|
case 161:
|
|
1249
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
1250
|
-
|
|
1191
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
1192
|
+
this.offlineOff();
|
|
1251
1193
|
break;
|
|
1252
1194
|
case 171:
|
|
1253
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline
|
|
1254
|
-
|
|
1195
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
1196
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
1197
|
+
this.offlineOff();
|
|
1255
1198
|
break;
|
|
1256
1199
|
case 190:
|
|
1257
1200
|
this.errorLog(
|
|
1258
1201
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1259
|
-
|
|
1202
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
1260
1203
|
);
|
|
1261
1204
|
break;
|
|
1262
1205
|
case 100:
|
|
1263
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent
|
|
1206
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
1207
|
+
break;
|
|
1208
|
+
case 200:
|
|
1209
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1264
1210
|
break;
|
|
1265
1211
|
default:
|
|
1266
|
-
this.
|
|
1212
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
1213
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
1267
1214
|
}
|
|
1268
1215
|
}
|
|
1269
1216
|
|
|
@@ -1315,7 +1262,7 @@ export class Bot {
|
|
|
1315
1262
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1316
1263
|
let FirmwareRevision: string;
|
|
1317
1264
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
1318
|
-
|
|
1265
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
1319
1266
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1320
1267
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1321
1268
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -1393,7 +1340,7 @@ export class Bot {
|
|
|
1393
1340
|
config['maxRetry'] = device.maxRetry;
|
|
1394
1341
|
}
|
|
1395
1342
|
if (Object.entries(config).length !== 0) {
|
|
1396
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
1343
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1397
1344
|
}
|
|
1398
1345
|
}
|
|
1399
1346
|
|