@switchbot/homebridge-switchbot 3.1.1-beta.0 → 3.1.1-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/.github/workflows/labeler.yml +2 -2
- package/CHANGELOG.md +21 -14
- package/README.md +2 -2
- package/config.schema.json +1 -1
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +7 -9
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +19 -21
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +9 -17
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +9 -17
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +14 -14
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +31 -45
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +5 -5
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +8 -14
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +6 -6
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +8 -14
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +6 -8
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +6 -6
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +6 -6
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +5 -5
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +6 -8
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +7 -12
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.js +0 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +1 -4
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +1 -4
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +1 -4
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +2 -5
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +1 -4
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +13 -16
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +1 -4
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +1 -4
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +1 -4
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +2 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +21 -26
- package/dist/platform.js.map +1 -1
- package/package.json +10 -5
- package/src/device/blindtilt.ts +7 -10
- package/src/device/bot.ts +19 -21
- package/src/device/ceilinglight.ts +9 -17
- package/src/device/colorbulb.ts +9 -17
- package/src/device/contact.ts +14 -14
- package/src/device/curtain.ts +35 -48
- package/src/device/hub.ts +5 -5
- package/src/device/humidifier.ts +8 -14
- package/src/device/iosensor.ts +6 -6
- package/src/device/lightstrip.ts +8 -14
- package/src/device/lock.ts +6 -8
- package/src/device/meter.ts +6 -6
- package/src/device/meterplus.ts +6 -6
- package/src/device/motion.ts +5 -5
- package/src/device/plug.ts +6 -8
- package/src/device/robotvacuumcleaner.ts +7 -12
- package/src/homebridge-ui/server.ts +1 -2
- package/src/irdevice/airconditioner.ts +1 -4
- package/src/irdevice/airpurifier.ts +1 -4
- package/src/irdevice/camera.ts +1 -4
- package/src/irdevice/fan.ts +2 -5
- package/src/irdevice/light.ts +1 -4
- package/src/irdevice/other.ts +13 -16
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -4
- package/src/irdevice/waterheater.ts +1 -4
- package/src/platform.ts +22 -27
- package/src/settings.ts +1 -1
package/src/device/bot.ts
CHANGED
|
@@ -549,7 +549,7 @@ export class Bot {
|
|
|
549
549
|
id: this.device.bleMac,
|
|
550
550
|
})
|
|
551
551
|
.then(async () => {
|
|
552
|
-
// Set an event
|
|
552
|
+
// Set an event handler
|
|
553
553
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
554
554
|
this.debugLog(
|
|
555
555
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
@@ -596,15 +596,12 @@ export class Bot {
|
|
|
596
596
|
async openAPIRefreshStatus(): Promise<void> {
|
|
597
597
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
598
598
|
try {
|
|
599
|
-
const { body, statusCode
|
|
599
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
600
600
|
headers: this.platform.generateHeaders(),
|
|
601
601
|
});
|
|
602
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
603
602
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
604
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
605
603
|
const deviceStatus: any = await body.json();
|
|
606
604
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
607
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
608
605
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
609
606
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
610
607
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -756,7 +753,7 @@ export class Bot {
|
|
|
756
753
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode`);
|
|
757
754
|
this.On = false;
|
|
758
755
|
} else {
|
|
759
|
-
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device
|
|
756
|
+
throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Parameters not set for this Bot.`);
|
|
760
757
|
}
|
|
761
758
|
const bodyChange = JSON.stringify({
|
|
762
759
|
command: `${command}`,
|
|
@@ -765,14 +762,12 @@ export class Bot {
|
|
|
765
762
|
});
|
|
766
763
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
767
764
|
try {
|
|
768
|
-
const { body, statusCode
|
|
765
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
769
766
|
body: bodyChange,
|
|
770
767
|
method: 'POST',
|
|
771
768
|
headers: this.platform.generateHeaders(),
|
|
772
769
|
});
|
|
773
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
774
770
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
775
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
776
771
|
const deviceStatus: any = await body.json();
|
|
777
772
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
778
773
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -1074,7 +1069,7 @@ export class Bot {
|
|
|
1074
1069
|
}
|
|
1075
1070
|
|
|
1076
1071
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
1077
|
-
// If outletService still
|
|
1072
|
+
// If outletService still present, then remove first
|
|
1078
1073
|
this.outletService = this.accessory.getService(this.hap.Service.Outlet);
|
|
1079
1074
|
if (this.outletService) {
|
|
1080
1075
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
@@ -1083,7 +1078,7 @@ export class Bot {
|
|
|
1083
1078
|
}
|
|
1084
1079
|
|
|
1085
1080
|
async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
1086
|
-
// If garageDoorService still
|
|
1081
|
+
// If garageDoorService still present, then remove first
|
|
1087
1082
|
this.garageDoorService = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
1088
1083
|
if (this.garageDoorService) {
|
|
1089
1084
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
@@ -1092,7 +1087,7 @@ export class Bot {
|
|
|
1092
1087
|
}
|
|
1093
1088
|
|
|
1094
1089
|
async removeDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
1095
|
-
// If doorService still
|
|
1090
|
+
// If doorService still present, then remove first
|
|
1096
1091
|
this.doorService = this.accessory.getService(this.hap.Service.Door);
|
|
1097
1092
|
if (this.doorService) {
|
|
1098
1093
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
@@ -1101,7 +1096,7 @@ export class Bot {
|
|
|
1101
1096
|
}
|
|
1102
1097
|
|
|
1103
1098
|
async removeLockService(accessory: PlatformAccessory): Promise<void> {
|
|
1104
|
-
// If lockService still
|
|
1099
|
+
// If lockService still present, then remove first
|
|
1105
1100
|
this.lockService = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
1106
1101
|
if (this.lockService) {
|
|
1107
1102
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
@@ -1110,7 +1105,7 @@ export class Bot {
|
|
|
1110
1105
|
}
|
|
1111
1106
|
|
|
1112
1107
|
async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
|
|
1113
|
-
// If faucetService still
|
|
1108
|
+
// If faucetService still present, then remove first
|
|
1114
1109
|
this.faucetService = this.accessory.getService(this.hap.Service.Faucet);
|
|
1115
1110
|
if (this.faucetService) {
|
|
1116
1111
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
@@ -1119,7 +1114,7 @@ export class Bot {
|
|
|
1119
1114
|
}
|
|
1120
1115
|
|
|
1121
1116
|
async removeFanService(accessory: PlatformAccessory): Promise<void> {
|
|
1122
|
-
// If fanService still
|
|
1117
|
+
// If fanService still present, then remove first
|
|
1123
1118
|
this.fanService = this.accessory.getService(this.hap.Service.Fan);
|
|
1124
1119
|
if (this.fanService) {
|
|
1125
1120
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
@@ -1128,7 +1123,7 @@ export class Bot {
|
|
|
1128
1123
|
}
|
|
1129
1124
|
|
|
1130
1125
|
async removeWindowService(accessory: PlatformAccessory): Promise<void> {
|
|
1131
|
-
// If windowService still
|
|
1126
|
+
// If windowService still present, then remove first
|
|
1132
1127
|
this.windowService = this.accessory.getService(this.hap.Service.Window);
|
|
1133
1128
|
if (this.windowService) {
|
|
1134
1129
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
@@ -1137,7 +1132,7 @@ export class Bot {
|
|
|
1137
1132
|
}
|
|
1138
1133
|
|
|
1139
1134
|
async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
|
|
1140
|
-
// If windowCoveringService still
|
|
1135
|
+
// If windowCoveringService still present, then remove first
|
|
1141
1136
|
this.windowCoveringService = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
1142
1137
|
if (this.windowCoveringService) {
|
|
1143
1138
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
@@ -1146,7 +1141,7 @@ export class Bot {
|
|
|
1146
1141
|
}
|
|
1147
1142
|
|
|
1148
1143
|
async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
1149
|
-
// If statefulProgrammableSwitchService still
|
|
1144
|
+
// If statefulProgrammableSwitchService still present, then remove first
|
|
1150
1145
|
this.statefulProgrammableSwitchService = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
1151
1146
|
if (this.statefulProgrammableSwitchService) {
|
|
1152
1147
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
@@ -1155,7 +1150,7 @@ export class Bot {
|
|
|
1155
1150
|
}
|
|
1156
1151
|
|
|
1157
1152
|
async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
1158
|
-
// If switchService still
|
|
1153
|
+
// If switchService still present, then remove first
|
|
1159
1154
|
this.switchService = this.accessory.getService(this.hap.Service.Switch);
|
|
1160
1155
|
if (this.switchService) {
|
|
1161
1156
|
this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
@@ -1365,10 +1360,10 @@ export class Bot {
|
|
|
1365
1360
|
async deviceType(device: device & devicesConfig): Promise<void> {
|
|
1366
1361
|
if (!device.bot?.deviceType && this.accessory.context.deviceType) {
|
|
1367
1362
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1368
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}, from
|
|
1363
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
|
|
1369
1364
|
} else if (device.bot?.deviceType) {
|
|
1370
1365
|
this.accessory.context.deviceType = device.bot.deviceType;
|
|
1371
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
1366
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Accessory Cache: ${this.accessory.context.deviceType}`);
|
|
1372
1367
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1373
1368
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}`);
|
|
1374
1369
|
} else {
|
|
@@ -1446,6 +1441,9 @@ export class Bot {
|
|
|
1446
1441
|
if (device.maxRetry !== undefined) {
|
|
1447
1442
|
config['maxRetry'] = device.maxRetry;
|
|
1448
1443
|
}
|
|
1444
|
+
if (device.webhook !== undefined) {
|
|
1445
|
+
config['webhook'] = device.webhook;
|
|
1446
|
+
}
|
|
1449
1447
|
if (Object.entries(config).length !== 0) {
|
|
1450
1448
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1451
1449
|
}
|
|
@@ -378,7 +378,7 @@ export class CeilingLight {
|
|
|
378
378
|
id: this.device.bleMac,
|
|
379
379
|
})
|
|
380
380
|
.then(async () => {
|
|
381
|
-
// Set an event
|
|
381
|
+
// Set an event handler
|
|
382
382
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
383
383
|
this.debugLog(
|
|
384
384
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
@@ -431,15 +431,12 @@ export class CeilingLight {
|
|
|
431
431
|
async openAPIRefreshStatus() {
|
|
432
432
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
433
433
|
try {
|
|
434
|
-
const { body, statusCode
|
|
434
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
435
435
|
headers: this.platform.generateHeaders(),
|
|
436
436
|
});
|
|
437
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
438
437
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
439
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
440
438
|
const deviceStatus: any = await body.json();
|
|
441
439
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
442
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
443
440
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
444
441
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
445
442
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -561,14 +558,12 @@ export class CeilingLight {
|
|
|
561
558
|
});
|
|
562
559
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
563
560
|
try {
|
|
564
|
-
const { body, statusCode
|
|
561
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
565
562
|
body: bodyChange,
|
|
566
563
|
method: 'POST',
|
|
567
564
|
headers: this.platform.generateHeaders(),
|
|
568
565
|
});
|
|
569
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
570
566
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
571
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
572
567
|
const deviceStatus: any = await body.json();
|
|
573
568
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
574
569
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -622,14 +617,12 @@ export class CeilingLight {
|
|
|
622
617
|
});
|
|
623
618
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
624
619
|
try {
|
|
625
|
-
const { body, statusCode
|
|
620
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
626
621
|
body: bodyChange,
|
|
627
622
|
method: 'POST',
|
|
628
623
|
headers: this.platform.generateHeaders(),
|
|
629
624
|
});
|
|
630
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
631
625
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
632
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
633
626
|
const deviceStatus: any = await body.json();
|
|
634
627
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
635
628
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -668,14 +661,12 @@ export class CeilingLight {
|
|
|
668
661
|
});
|
|
669
662
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
670
663
|
try {
|
|
671
|
-
const { body, statusCode
|
|
664
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
672
665
|
body: bodyChange,
|
|
673
666
|
method: 'POST',
|
|
674
667
|
headers: this.platform.generateHeaders(),
|
|
675
668
|
});
|
|
676
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
677
669
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
678
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
679
670
|
const deviceStatus: any = await body.json();
|
|
680
671
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
681
672
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -712,14 +703,12 @@ export class CeilingLight {
|
|
|
712
703
|
});
|
|
713
704
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
714
705
|
try {
|
|
715
|
-
const { body, statusCode
|
|
706
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
716
707
|
body: bodyChange,
|
|
717
708
|
method: 'POST',
|
|
718
709
|
headers: this.platform.generateHeaders(),
|
|
719
710
|
});
|
|
720
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
721
711
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
722
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
723
712
|
const deviceStatus: any = await body.json();
|
|
724
713
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
725
714
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -1106,6 +1095,9 @@ export class CeilingLight {
|
|
|
1106
1095
|
if (device.maxRetry !== undefined) {
|
|
1107
1096
|
config['maxRetry'] = device.maxRetry;
|
|
1108
1097
|
}
|
|
1098
|
+
if (device.webhook !== undefined) {
|
|
1099
|
+
config['webhook'] = device.webhook;
|
|
1100
|
+
}
|
|
1109
1101
|
if (Object.entries(config).length !== 0) {
|
|
1110
1102
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1111
1103
|
}
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -424,7 +424,7 @@ export class ColorBulb {
|
|
|
424
424
|
id: this.device.bleMac,
|
|
425
425
|
})
|
|
426
426
|
.then(async () => {
|
|
427
|
-
// Set an event
|
|
427
|
+
// Set an event handler
|
|
428
428
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
429
429
|
this.debugLog(
|
|
430
430
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
@@ -478,15 +478,12 @@ export class ColorBulb {
|
|
|
478
478
|
async openAPIRefreshStatus() {
|
|
479
479
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
480
480
|
try {
|
|
481
|
-
const { body, statusCode
|
|
481
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
482
482
|
headers: this.platform.generateHeaders(),
|
|
483
483
|
});
|
|
484
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
485
484
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
486
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
487
485
|
const deviceStatus: any = await body.json();
|
|
488
486
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
489
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
490
487
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
491
488
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
492
489
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -744,14 +741,12 @@ export class ColorBulb {
|
|
|
744
741
|
});
|
|
745
742
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
746
743
|
try {
|
|
747
|
-
const { body, statusCode
|
|
744
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
748
745
|
body: bodyChange,
|
|
749
746
|
method: 'POST',
|
|
750
747
|
headers: this.platform.generateHeaders(),
|
|
751
748
|
});
|
|
752
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
753
749
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
754
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
755
750
|
const deviceStatus: any = await body.json();
|
|
756
751
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
757
752
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -805,14 +800,12 @@ export class ColorBulb {
|
|
|
805
800
|
});
|
|
806
801
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
807
802
|
try {
|
|
808
|
-
const { body, statusCode
|
|
803
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
809
804
|
body: bodyChange,
|
|
810
805
|
method: 'POST',
|
|
811
806
|
headers: this.platform.generateHeaders(),
|
|
812
807
|
});
|
|
813
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
814
808
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
815
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
816
809
|
const deviceStatus: any = await body.json();
|
|
817
810
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
818
811
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -851,14 +844,12 @@ export class ColorBulb {
|
|
|
851
844
|
});
|
|
852
845
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
853
846
|
try {
|
|
854
|
-
const { body, statusCode
|
|
847
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
855
848
|
body: bodyChange,
|
|
856
849
|
method: 'POST',
|
|
857
850
|
headers: this.platform.generateHeaders(),
|
|
858
851
|
});
|
|
859
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
860
852
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
861
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
862
853
|
const deviceStatus: any = await body.json();
|
|
863
854
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
864
855
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -895,14 +886,12 @@ export class ColorBulb {
|
|
|
895
886
|
});
|
|
896
887
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
897
888
|
try {
|
|
898
|
-
const { body, statusCode
|
|
889
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
899
890
|
body: bodyChange,
|
|
900
891
|
method: 'POST',
|
|
901
892
|
headers: this.platform.generateHeaders(),
|
|
902
893
|
});
|
|
903
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
904
894
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
905
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
906
895
|
const deviceStatus: any = await body.json();
|
|
907
896
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
908
897
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -1294,6 +1283,9 @@ export class ColorBulb {
|
|
|
1294
1283
|
if (device.maxRetry !== undefined) {
|
|
1295
1284
|
config['maxRetry'] = device.maxRetry;
|
|
1296
1285
|
}
|
|
1286
|
+
if (device.webhook !== undefined) {
|
|
1287
|
+
config['webhook'] = device.webhook;
|
|
1288
|
+
}
|
|
1297
1289
|
if (Object.entries(config).length !== 0) {
|
|
1298
1290
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1299
1291
|
}
|
package/src/device/contact.ts
CHANGED
|
@@ -38,7 +38,7 @@ export class Contact {
|
|
|
38
38
|
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
39
39
|
|
|
40
40
|
// BLE Status
|
|
41
|
-
|
|
41
|
+
BLE_BatteryLevel!: serviceData['battery'];
|
|
42
42
|
BLE_MotionDetected!: serviceData['movement'];
|
|
43
43
|
BLE_ContactSensorState!: serviceData['doorState'];
|
|
44
44
|
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
@@ -75,11 +75,11 @@ export class Contact {
|
|
|
75
75
|
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
76
76
|
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
77
77
|
// default placeholders
|
|
78
|
-
this.
|
|
78
|
+
this.deviceLogs(device);
|
|
79
79
|
this.scan(device);
|
|
80
80
|
this.refreshRate(device);
|
|
81
81
|
this.context();
|
|
82
|
-
this.
|
|
82
|
+
this.deviceConfig(device);
|
|
83
83
|
|
|
84
84
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
85
85
|
this.doContactUpdate = new Subject();
|
|
@@ -257,10 +257,10 @@ export class Contact {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
// Battery
|
|
260
|
-
if (this.
|
|
261
|
-
this.
|
|
260
|
+
if (this.BLE_BatteryLevel === undefined) {
|
|
261
|
+
this.BLE_BatteryLevel === 100;
|
|
262
262
|
}
|
|
263
|
-
this.BatteryLevel = Number(this.
|
|
263
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
264
264
|
if (this.BatteryLevel < 10) {
|
|
265
265
|
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
266
266
|
} else {
|
|
@@ -360,7 +360,7 @@ export class Contact {
|
|
|
360
360
|
id: this.device.bleMac,
|
|
361
361
|
})
|
|
362
362
|
.then(async () => {
|
|
363
|
-
// Set an event
|
|
363
|
+
// Set an event handler
|
|
364
364
|
this.scanning = true;
|
|
365
365
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
366
366
|
this.debugLog(
|
|
@@ -368,7 +368,7 @@ export class Contact {
|
|
|
368
368
|
` BLE Address Found: ${ad.address}`,
|
|
369
369
|
);
|
|
370
370
|
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
371
|
-
this.
|
|
371
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
372
372
|
this.BLE_ContactSensorState = ad.serviceData.doorState;
|
|
373
373
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
374
374
|
this.debugLog(
|
|
@@ -411,15 +411,12 @@ export class Contact {
|
|
|
411
411
|
async openAPIRefreshStatus(): Promise<void> {
|
|
412
412
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
413
413
|
try {
|
|
414
|
-
const { body, statusCode
|
|
414
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
415
415
|
headers: this.platform.generateHeaders(),
|
|
416
416
|
});
|
|
417
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
418
417
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
419
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
420
418
|
const deviceStatus: any = await body.json();
|
|
421
419
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
422
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
423
420
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
424
421
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
425
422
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -648,7 +645,7 @@ export class Contact {
|
|
|
648
645
|
}
|
|
649
646
|
}
|
|
650
647
|
|
|
651
|
-
async
|
|
648
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
652
649
|
let config = {};
|
|
653
650
|
if (device.contact) {
|
|
654
651
|
config = device.contact;
|
|
@@ -668,12 +665,15 @@ export class Contact {
|
|
|
668
665
|
if (device.scanDuration !== undefined) {
|
|
669
666
|
config['scanDuration'] = device.scanDuration;
|
|
670
667
|
}
|
|
668
|
+
if (device.webhook !== undefined) {
|
|
669
|
+
config['webhook'] = device.webhook;
|
|
670
|
+
}
|
|
671
671
|
if (Object.entries(config).length !== 0) {
|
|
672
672
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
-
async
|
|
676
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
677
677
|
if (this.platform.debugMode) {
|
|
678
678
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
679
679
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/device/curtain.ts
CHANGED
|
@@ -36,9 +36,9 @@ export class Curtain {
|
|
|
36
36
|
OpenAPI_CurrentPosition: deviceStatus['slidePosition'];
|
|
37
37
|
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
38
38
|
|
|
39
|
-
//
|
|
39
|
+
// Others
|
|
40
40
|
Mode!: string;
|
|
41
|
-
setPositionMode?: string
|
|
41
|
+
setPositionMode?: string;
|
|
42
42
|
|
|
43
43
|
// BLE Status
|
|
44
44
|
BLE_InMotion: serviceData['inMotion'];
|
|
@@ -157,12 +157,6 @@ export class Curtain {
|
|
|
157
157
|
|
|
158
158
|
this.windowCoveringService
|
|
159
159
|
.getCharacteristic(this.hap.Characteristic.HoldPosition)
|
|
160
|
-
.setProps({
|
|
161
|
-
minStep: this.minStep(device),
|
|
162
|
-
minValue: 0,
|
|
163
|
-
maxValue: 100,
|
|
164
|
-
validValueRanges: [0, 100],
|
|
165
|
-
})
|
|
166
160
|
.onSet(this.HoldPositionSet.bind(this));
|
|
167
161
|
|
|
168
162
|
// Light Sensor Service
|
|
@@ -559,7 +553,7 @@ export class Curtain {
|
|
|
559
553
|
id: this.device.bleMac,
|
|
560
554
|
})
|
|
561
555
|
.then(async () => {
|
|
562
|
-
// Set an event
|
|
556
|
+
// Set an event handler
|
|
563
557
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
564
558
|
this.debugLog(
|
|
565
559
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
@@ -609,15 +603,12 @@ export class Curtain {
|
|
|
609
603
|
async openAPIRefreshStatus(): Promise<void> {
|
|
610
604
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
611
605
|
try {
|
|
612
|
-
const { body, statusCode
|
|
606
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
613
607
|
headers: this.platform.generateHeaders(),
|
|
614
608
|
});
|
|
615
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
616
609
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
617
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
618
610
|
const deviceStatus: any = await body.json();
|
|
619
611
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
620
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
621
612
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
622
613
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
623
614
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
@@ -675,35 +666,30 @@ export class Curtain {
|
|
|
675
666
|
.toLowerCase();
|
|
676
667
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
677
668
|
this.SilentPerformance();
|
|
678
|
-
const adjustedMode = this.setPositionMode
|
|
679
|
-
if (adjustedMode === null) {
|
|
680
|
-
this.Mode = 'Default Mode';
|
|
681
|
-
}
|
|
669
|
+
const adjustedMode = this.setPositionMode == '1' ? 0x01 : 0xff;
|
|
682
670
|
this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
|
|
683
671
|
if (switchbot !== false) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
},
|
|
706
|
-
});
|
|
672
|
+
try {
|
|
673
|
+
const device_list = await switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac });
|
|
674
|
+
this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
675
|
+
|
|
676
|
+
await this.retry({
|
|
677
|
+
max: this.maxRetry(),
|
|
678
|
+
fn: async () => {
|
|
679
|
+
await device_list[0].runToPos(100 - Number(this.TargetPosition), adjustedMode);
|
|
680
|
+
},
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
684
|
+
} catch (e) {
|
|
685
|
+
this.apiError(e);
|
|
686
|
+
this.errorLog(
|
|
687
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
688
|
+
` Connection, Error Message: ${JSON.stringify((e as Error).message)}`,
|
|
689
|
+
);
|
|
690
|
+
await this.BLEPushConnection();
|
|
691
|
+
throw new Error('Connection error');
|
|
692
|
+
}
|
|
707
693
|
} else {
|
|
708
694
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
709
695
|
await this.BLEPushConnection();
|
|
@@ -774,14 +760,12 @@ export class Curtain {
|
|
|
774
760
|
});
|
|
775
761
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
776
762
|
try {
|
|
777
|
-
const { body, statusCode
|
|
763
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
778
764
|
body: bodyChange,
|
|
779
765
|
method: 'POST',
|
|
780
766
|
headers: this.platform.generateHeaders(),
|
|
781
767
|
});
|
|
782
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
783
768
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
784
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
785
769
|
const deviceStatus: any = await body.json();
|
|
786
770
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
787
771
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
@@ -969,7 +953,7 @@ export class Curtain {
|
|
|
969
953
|
}
|
|
970
954
|
|
|
971
955
|
/*
|
|
972
|
-
* Setup MQTT hadler if URL is
|
|
956
|
+
* Setup MQTT hadler if URL is specified.
|
|
973
957
|
*/
|
|
974
958
|
async setupMqtt(device: device & devicesConfig): Promise<void> {
|
|
975
959
|
if (device.mqttURL) {
|
|
@@ -1033,18 +1017,18 @@ export class Curtain {
|
|
|
1033
1017
|
async SilentPerformance() {
|
|
1034
1018
|
if (Number(this.TargetPosition) > 50) {
|
|
1035
1019
|
if (this.device.curtain?.setOpenMode === '1') {
|
|
1036
|
-
this.setPositionMode = 1;
|
|
1020
|
+
this.setPositionMode = '1';
|
|
1037
1021
|
this.Mode = 'Silent Mode';
|
|
1038
1022
|
} else {
|
|
1039
|
-
this.setPositionMode = 0;
|
|
1023
|
+
this.setPositionMode = '0';
|
|
1040
1024
|
this.Mode = 'Performance Mode';
|
|
1041
1025
|
}
|
|
1042
1026
|
} else {
|
|
1043
1027
|
if (this.device.curtain?.setCloseMode === '1') {
|
|
1044
|
-
this.setPositionMode = 1;
|
|
1028
|
+
this.setPositionMode = '1';
|
|
1045
1029
|
this.Mode = 'Silent Mode';
|
|
1046
1030
|
} else {
|
|
1047
|
-
this.setPositionMode = 0;
|
|
1031
|
+
this.setPositionMode = '0';
|
|
1048
1032
|
this.Mode = 'Performance Mode';
|
|
1049
1033
|
}
|
|
1050
1034
|
}
|
|
@@ -1280,6 +1264,9 @@ export class Curtain {
|
|
|
1280
1264
|
if (device.maxRetry !== undefined) {
|
|
1281
1265
|
config['maxRetry'] = device.maxRetry;
|
|
1282
1266
|
}
|
|
1267
|
+
if (device.webhook !== undefined) {
|
|
1268
|
+
config['webhook'] = device.webhook;
|
|
1269
|
+
}
|
|
1283
1270
|
if (Object.entries(config).length !== 0) {
|
|
1284
1271
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1285
1272
|
}
|