@switchbot/homebridge-switchbot 3.1.1-beta.1 → 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/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/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/irdevice/fan.ts
CHANGED
|
@@ -86,7 +86,7 @@ export class Fan {
|
|
|
86
86
|
} else {
|
|
87
87
|
this.maxValue = 100;
|
|
88
88
|
}
|
|
89
|
-
// handle
|
|
89
|
+
// handle Rotation Speed events using the RotationSpeed characteristic
|
|
90
90
|
this.fanService
|
|
91
91
|
.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
92
92
|
.setProps({
|
|
@@ -237,17 +237,14 @@ export class Fan {
|
|
|
237
237
|
if (this.device.connectionType === 'OpenAPI') {
|
|
238
238
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
239
239
|
try {
|
|
240
|
-
const { body, statusCode
|
|
240
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
241
241
|
body: bodyChange,
|
|
242
242
|
method: 'POST',
|
|
243
243
|
headers: this.platform.generateHeaders(),
|
|
244
244
|
});
|
|
245
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
246
245
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
247
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
248
246
|
const deviceStatus: any = await body.json();
|
|
249
247
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
250
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
251
248
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
252
249
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
253
250
|
this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
package/src/irdevice/light.ts
CHANGED
|
@@ -235,17 +235,14 @@ export class Light {
|
|
|
235
235
|
if (this.device.connectionType === 'OpenAPI') {
|
|
236
236
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
237
237
|
try {
|
|
238
|
-
const { body, statusCode
|
|
238
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
239
239
|
body: bodyChange,
|
|
240
240
|
method: 'POST',
|
|
241
241
|
headers: this.platform.generateHeaders(),
|
|
242
242
|
});
|
|
243
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
244
243
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
245
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
246
244
|
const deviceStatus: any = await body.json();
|
|
247
245
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
248
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
249
246
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
250
247
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
251
248
|
this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
package/src/irdevice/other.ts
CHANGED
|
@@ -427,17 +427,14 @@ export class Others {
|
|
|
427
427
|
if (this.device.connectionType === 'OpenAPI') {
|
|
428
428
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
429
429
|
try {
|
|
430
|
-
const { body, statusCode
|
|
430
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
431
431
|
body: bodyChange,
|
|
432
432
|
method: 'POST',
|
|
433
433
|
headers: this.platform.generateHeaders(),
|
|
434
434
|
});
|
|
435
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
436
435
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
437
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
438
436
|
const deviceStatus: any = await body.json();
|
|
439
437
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
440
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
441
438
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
442
439
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
443
440
|
this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
|
@@ -773,7 +770,7 @@ export class Others {
|
|
|
773
770
|
}
|
|
774
771
|
|
|
775
772
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
776
|
-
// If outletService still
|
|
773
|
+
// If outletService still present, then remove first
|
|
777
774
|
this.outletService = this.accessory.getService(this.hap.Service.Outlet);
|
|
778
775
|
if (this.outletService) {
|
|
779
776
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
@@ -782,7 +779,7 @@ export class Others {
|
|
|
782
779
|
}
|
|
783
780
|
|
|
784
781
|
async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
785
|
-
// If garageDoorService still
|
|
782
|
+
// If garageDoorService still present, then remove first
|
|
786
783
|
this.garageDoorService = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
787
784
|
if (this.garageDoorService) {
|
|
788
785
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
@@ -791,7 +788,7 @@ export class Others {
|
|
|
791
788
|
}
|
|
792
789
|
|
|
793
790
|
async removeDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
794
|
-
// If doorService still
|
|
791
|
+
// If doorService still present, then remove first
|
|
795
792
|
this.doorService = this.accessory.getService(this.hap.Service.Door);
|
|
796
793
|
if (this.doorService) {
|
|
797
794
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
@@ -800,7 +797,7 @@ export class Others {
|
|
|
800
797
|
}
|
|
801
798
|
|
|
802
799
|
async removeLockService(accessory: PlatformAccessory): Promise<void> {
|
|
803
|
-
// If lockService still
|
|
800
|
+
// If lockService still present, then remove first
|
|
804
801
|
this.lockService = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
805
802
|
if (this.lockService) {
|
|
806
803
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
@@ -809,7 +806,7 @@ export class Others {
|
|
|
809
806
|
}
|
|
810
807
|
|
|
811
808
|
async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
|
|
812
|
-
// If faucetService still
|
|
809
|
+
// If faucetService still present, then remove first
|
|
813
810
|
this.faucetService = this.accessory.getService(this.hap.Service.Faucet);
|
|
814
811
|
if (this.faucetService) {
|
|
815
812
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
@@ -818,7 +815,7 @@ export class Others {
|
|
|
818
815
|
}
|
|
819
816
|
|
|
820
817
|
async removeFanService(accessory: PlatformAccessory): Promise<void> {
|
|
821
|
-
// If fanService still
|
|
818
|
+
// If fanService still present, then remove first
|
|
822
819
|
this.fanService = this.accessory.getService(this.hap.Service.Fan);
|
|
823
820
|
if (this.fanService) {
|
|
824
821
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
@@ -827,7 +824,7 @@ export class Others {
|
|
|
827
824
|
}
|
|
828
825
|
|
|
829
826
|
async removeWindowService(accessory: PlatformAccessory): Promise<void> {
|
|
830
|
-
// If windowService still
|
|
827
|
+
// If windowService still present, then remove first
|
|
831
828
|
this.windowService = this.accessory.getService(this.hap.Service.Window);
|
|
832
829
|
if (this.windowService) {
|
|
833
830
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
@@ -836,7 +833,7 @@ export class Others {
|
|
|
836
833
|
}
|
|
837
834
|
|
|
838
835
|
async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
|
|
839
|
-
// If windowCoveringService still
|
|
836
|
+
// If windowCoveringService still present, then remove first
|
|
840
837
|
this.windowCoveringService = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
841
838
|
if (this.windowCoveringService) {
|
|
842
839
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
@@ -845,7 +842,7 @@ export class Others {
|
|
|
845
842
|
}
|
|
846
843
|
|
|
847
844
|
async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
848
|
-
// If statefulProgrammableSwitchService still
|
|
845
|
+
// If statefulProgrammableSwitchService still present, then remove first
|
|
849
846
|
this.statefulProgrammableSwitchService = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
850
847
|
if (this.statefulProgrammableSwitchService) {
|
|
851
848
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
@@ -854,7 +851,7 @@ export class Others {
|
|
|
854
851
|
}
|
|
855
852
|
|
|
856
853
|
async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
857
|
-
// If switchService still
|
|
854
|
+
// If switchService still present, then remove first
|
|
858
855
|
this.switchService = this.accessory.getService(this.hap.Service.Switch);
|
|
859
856
|
if (this.switchService) {
|
|
860
857
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
@@ -865,10 +862,10 @@ export class Others {
|
|
|
865
862
|
async deviceType(device: irdevice & irDevicesConfig): Promise<void> {
|
|
866
863
|
if (!device.other?.deviceType && this.accessory.context.deviceType) {
|
|
867
864
|
this.otherDeviceType = this.accessory.context.deviceType;
|
|
868
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}, from
|
|
865
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}, from Accessory Cache.`);
|
|
869
866
|
} else if (device.other?.deviceType) {
|
|
870
867
|
this.accessory.context.deviceType = device.other.deviceType;
|
|
871
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}
|
|
868
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Accessory Cache: ${this.accessory.context.deviceType}`);
|
|
872
869
|
this.otherDeviceType = this.accessory.context.deviceType;
|
|
873
870
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`);
|
|
874
871
|
} else {
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -369,17 +369,14 @@ export class TV {
|
|
|
369
369
|
if (this.device.connectionType === 'OpenAPI') {
|
|
370
370
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
371
371
|
try {
|
|
372
|
-
const { body, statusCode
|
|
372
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
373
373
|
body: bodyChange,
|
|
374
374
|
method: 'POST',
|
|
375
375
|
headers: this.platform.generateHeaders(),
|
|
376
376
|
});
|
|
377
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
378
377
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
379
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
380
378
|
const deviceStatus: any = await body.json();
|
|
381
379
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
382
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
383
380
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
384
381
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
385
382
|
this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
|
@@ -116,17 +116,14 @@ export class VacuumCleaner {
|
|
|
116
116
|
if (this.device.connectionType === 'OpenAPI') {
|
|
117
117
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
118
118
|
try {
|
|
119
|
-
const { body, statusCode
|
|
119
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
120
120
|
body: bodyChange,
|
|
121
121
|
method: 'POST',
|
|
122
122
|
headers: this.platform.generateHeaders(),
|
|
123
123
|
});
|
|
124
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
125
124
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
126
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
127
125
|
const deviceStatus: any = await body.json();
|
|
128
126
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
129
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
130
127
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
131
128
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
132
129
|
this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
|
@@ -125,17 +125,14 @@ export class WaterHeater {
|
|
|
125
125
|
if (this.device.connectionType === 'OpenAPI') {
|
|
126
126
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
127
127
|
try {
|
|
128
|
-
const { body, statusCode
|
|
128
|
+
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
129
129
|
body: bodyChange,
|
|
130
130
|
method: 'POST',
|
|
131
131
|
headers: this.platform.generateHeaders(),
|
|
132
132
|
});
|
|
133
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
|
|
134
133
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
135
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} headers: ${JSON.stringify(headers)}`);
|
|
136
134
|
const deviceStatus: any = await body.json();
|
|
137
135
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
138
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus body: ${JSON.stringify(deviceStatus.body)}`);
|
|
139
136
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
140
137
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
141
138
|
this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
|
package/src/platform.ts
CHANGED
|
@@ -158,7 +158,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
async setupwebhook() {
|
|
161
|
-
//webhook
|
|
161
|
+
//webhook configuration
|
|
162
162
|
if (this.config.options?.webhookURL) {
|
|
163
163
|
const url = this.config.options?.webhookURL;
|
|
164
164
|
|
|
@@ -203,7 +203,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
try {
|
|
206
|
-
const { body, statusCode
|
|
206
|
+
const { body, statusCode } = await request(
|
|
207
207
|
'https://api.switch-bot.com/v1.1/webhook/setupWebhook', {
|
|
208
208
|
method: 'POST',
|
|
209
209
|
headers: this.generateHeaders(),
|
|
@@ -217,7 +217,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
217
217
|
this.debugLog(`setupWebhook: url:${url}`);
|
|
218
218
|
this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
|
|
219
219
|
this.debugLog(`setupWebhook: statusCode:${statusCode}`);
|
|
220
|
-
this.debugLog(`setupWebhook: headers:${JSON.stringify(headers)}`);
|
|
221
220
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
222
221
|
this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
|
|
223
222
|
+ `message:${response?.message}`);
|
|
@@ -227,7 +226,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
227
226
|
}
|
|
228
227
|
|
|
229
228
|
try {
|
|
230
|
-
const { body, statusCode
|
|
229
|
+
const { body, statusCode } = await request(
|
|
231
230
|
'https://api.switch-bot.com/v1.1/webhook/updateWebhook', {
|
|
232
231
|
method: 'POST',
|
|
233
232
|
headers: this.generateHeaders(),
|
|
@@ -243,7 +242,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
243
242
|
this.debugLog(`updateWebhook: url:${url}`);
|
|
244
243
|
this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
|
|
245
244
|
this.debugLog(`updateWebhook: statusCode:${statusCode}`);
|
|
246
|
-
this.debugLog(`updateWebhook: headers:${JSON.stringify(headers)}`);
|
|
247
245
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
248
246
|
this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
249
247
|
}
|
|
@@ -252,7 +250,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
252
250
|
}
|
|
253
251
|
|
|
254
252
|
try {
|
|
255
|
-
const { body, statusCode
|
|
253
|
+
const { body, statusCode } = await request(
|
|
256
254
|
'https://api.switch-bot.com/v1.1/webhook/queryWebhook', {
|
|
257
255
|
method: 'POST',
|
|
258
256
|
headers: this.generateHeaders(),
|
|
@@ -263,7 +261,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
263
261
|
const response: any = await body.json();
|
|
264
262
|
this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
|
|
265
263
|
this.debugLog(`queryWebhook: statusCode:${statusCode}`);
|
|
266
|
-
this.debugLog(`queryWebhook: headers:${JSON.stringify(headers)}`);
|
|
267
264
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
268
265
|
this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
269
266
|
} else {
|
|
@@ -275,7 +272,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
275
272
|
|
|
276
273
|
this.api.on('shutdown', async () => {
|
|
277
274
|
try {
|
|
278
|
-
const { body, statusCode
|
|
275
|
+
const { body, statusCode } = await request(
|
|
279
276
|
'https://api.switch-bot.com/v1.1/webhook/deleteWebhook', {
|
|
280
277
|
method: 'POST',
|
|
281
278
|
headers: this.generateHeaders(),
|
|
@@ -288,7 +285,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
288
285
|
this.debugLog(`deleteWebhook: url:${url}`);
|
|
289
286
|
this.debugLog(`deleteWebhook: body:${JSON.stringify(response)}`);
|
|
290
287
|
this.debugLog(`deleteWebhook: statusCode:${statusCode}`);
|
|
291
|
-
this.debugLog(`deleteWebhook: headers:${JSON.stringify(headers)}`);
|
|
292
288
|
if (statusCode !== 200 || response?.statusCode !== 100) {
|
|
293
289
|
this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
|
|
294
290
|
} else {
|
|
@@ -490,12 +486,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
490
486
|
async discoverDevices() {
|
|
491
487
|
if (this.config.credentials?.token) {
|
|
492
488
|
try {
|
|
493
|
-
const { body, statusCode
|
|
489
|
+
const { body, statusCode } = await request(Devices, {
|
|
494
490
|
headers: this.generateHeaders(),
|
|
495
491
|
});
|
|
496
|
-
this.debugWarnLog(`body: ${JSON.stringify(body)}`);
|
|
497
492
|
this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
498
|
-
this.debugWarnLog(`headers: ${JSON.stringify(headers)}`);
|
|
499
493
|
const devicesAPI: any = await body.json();
|
|
500
494
|
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
501
495
|
this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
@@ -2525,17 +2519,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2525
2519
|
}
|
|
2526
2520
|
|
|
2527
2521
|
// BLE Connection
|
|
2528
|
-
connectBLE() {
|
|
2529
|
-
let
|
|
2530
|
-
let
|
|
2522
|
+
async connectBLE() {
|
|
2523
|
+
let SwitchbotBLE: any;
|
|
2524
|
+
let Switchbot: any;
|
|
2531
2525
|
try {
|
|
2532
|
-
Switchbot =
|
|
2533
|
-
queueScheduler.schedule(() => (
|
|
2526
|
+
Switchbot = (await import('node-switchbot')).default;
|
|
2527
|
+
queueScheduler.schedule(() => (Switchbot = new SwitchbotBLE()));
|
|
2534
2528
|
} catch (e: any) {
|
|
2535
|
-
|
|
2536
|
-
|
|
2529
|
+
this.log.error(e);
|
|
2530
|
+
Switchbot = false;
|
|
2531
|
+
this.errorLog(`Was 'node-switchbot' found: ${Switchbot}`);
|
|
2537
2532
|
}
|
|
2538
|
-
return
|
|
2533
|
+
return Switchbot;
|
|
2539
2534
|
}
|
|
2540
2535
|
|
|
2541
2536
|
logType() {
|
|
@@ -2557,19 +2552,19 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2557
2552
|
* Otherwise send debug logs to log.debug
|
|
2558
2553
|
*/
|
|
2559
2554
|
infoLog(...log: any[]): void {
|
|
2560
|
-
if (this.
|
|
2555
|
+
if (this.enablingPlatformLogging()) {
|
|
2561
2556
|
this.log.info(String(...log));
|
|
2562
2557
|
}
|
|
2563
2558
|
}
|
|
2564
2559
|
|
|
2565
2560
|
warnLog(...log: any[]): void {
|
|
2566
|
-
if (this.
|
|
2561
|
+
if (this.enablingPlatformLogging()) {
|
|
2567
2562
|
this.log.warn(String(...log));
|
|
2568
2563
|
}
|
|
2569
2564
|
}
|
|
2570
2565
|
|
|
2571
2566
|
debugWarnLog(...log: any[]): void {
|
|
2572
|
-
if (this.
|
|
2567
|
+
if (this.enablingPlatformLogging()) {
|
|
2573
2568
|
if (this.platformLogging?.includes('debug')) {
|
|
2574
2569
|
this.log.warn('[DEBUG]', String(...log));
|
|
2575
2570
|
}
|
|
@@ -2577,13 +2572,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2577
2572
|
}
|
|
2578
2573
|
|
|
2579
2574
|
errorLog(...log: any[]): void {
|
|
2580
|
-
if (this.
|
|
2575
|
+
if (this.enablingPlatformLogging()) {
|
|
2581
2576
|
this.log.error(String(...log));
|
|
2582
2577
|
}
|
|
2583
2578
|
}
|
|
2584
2579
|
|
|
2585
2580
|
debugErrorLog(...log: any[]): void {
|
|
2586
|
-
if (this.
|
|
2581
|
+
if (this.enablingPlatformLogging()) {
|
|
2587
2582
|
if (this.platformLogging?.includes('debug')) {
|
|
2588
2583
|
this.log.error('[DEBUG]', String(...log));
|
|
2589
2584
|
}
|
|
@@ -2591,7 +2586,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2591
2586
|
}
|
|
2592
2587
|
|
|
2593
2588
|
debugLog(...log: any[]): void {
|
|
2594
|
-
if (this.
|
|
2589
|
+
if (this.enablingPlatformLogging()) {
|
|
2595
2590
|
if (this.platformLogging === 'debugMode') {
|
|
2596
2591
|
this.log.debug(String(...log));
|
|
2597
2592
|
} else if (this.platformLogging === 'debug') {
|
|
@@ -2600,7 +2595,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2600
2595
|
}
|
|
2601
2596
|
}
|
|
2602
2597
|
|
|
2603
|
-
|
|
2598
|
+
enablingPlatformLogging(): boolean {
|
|
2604
2599
|
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
|
|
2605
2600
|
}
|
|
2606
2601
|
}
|
package/src/settings.ts
CHANGED
|
@@ -303,7 +303,7 @@ export type deviceStatus = {
|
|
|
303
303
|
mode?: number; //available for devices. the fan mode. (Used by the following deviceTypes: Smart Fan)
|
|
304
304
|
speed?: number; //the fan speed. (Used by the following deviceTypes: Smart Fan)
|
|
305
305
|
shaking?: boolean; //determines if the fan is swinging or not. (Used by the following deviceTypes: Smart Fan)
|
|
306
|
-
shakeCenter?: string; //the fan's swing
|
|
306
|
+
shakeCenter?: string; //the fan's swing direction. (Used by the following deviceTypes: Smart Fan)
|
|
307
307
|
shakeRange?: string; //the fan's swing range, 0~120°. (Used by the following deviceTypes: Smart Fan)
|
|
308
308
|
};
|
|
309
309
|
|