@switchbot/homebridge-switchbot 3.5.0-beta.17 → 3.5.0-beta.19
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/CHANGELOG.md +1 -0
- package/config.schema.json +18 -0
- package/dist/device/blindtilt.d.ts +3 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +28 -1
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +3 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +22 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -0
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +22 -1
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +22 -1
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -2
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +3 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +22 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +3 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +22 -2
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -0
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +22 -1
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +3 -0
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +22 -2
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +3 -0
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +22 -1
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +3 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +22 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +22 -2
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +22 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +22 -2
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +22 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +3 -0
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +22 -1
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +3 -0
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +22 -2
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts +9 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +24 -1
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -0
- package/dist/settings.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +30 -3
- package/src/device/bot.ts +24 -3
- package/src/device/ceilinglight.ts +24 -3
- package/src/device/colorbulb.ts +24 -3
- package/src/device/contact.ts +24 -4
- package/src/device/curtain.ts +24 -3
- package/src/device/hub.ts +24 -4
- package/src/device/humidifier.ts +24 -3
- package/src/device/iosensor.ts +24 -4
- package/src/device/lightstrip.ts +24 -3
- package/src/device/lock.ts +24 -3
- package/src/device/meter.ts +24 -4
- package/src/device/meterplus.ts +24 -4
- package/src/device/motion.ts +24 -4
- package/src/device/plug.ts +24 -3
- package/src/device/robotvacuumcleaner.ts +24 -3
- package/src/device/waterdetector.ts +24 -4
- package/src/platform.ts +27 -2
- package/src/settings.ts +2 -0
package/src/device/meter.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { CharacteristicValue, PlatformAccessory, Service, Units, API, Logging, H
|
|
|
3
3
|
import { MqttClient } from 'mqtt';
|
|
4
4
|
import { hostname } from 'os';
|
|
5
5
|
import { interval } from 'rxjs';
|
|
6
|
-
import { request } from 'undici';
|
|
7
6
|
import { SwitchBotPlatform } from '../platform.js';
|
|
8
7
|
import { Devices, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings.js';
|
|
9
8
|
import { sleep } from '../utils.js';
|
|
@@ -51,6 +50,8 @@ export class Meter {
|
|
|
51
50
|
scanDuration!: number;
|
|
52
51
|
deviceLogging!: string;
|
|
53
52
|
deviceRefreshRate!: number;
|
|
53
|
+
maxRetries!: number;
|
|
54
|
+
delayBetweenRetries!: number;
|
|
54
55
|
|
|
55
56
|
// Connection
|
|
56
57
|
private readonly OpenAPI: boolean;
|
|
@@ -75,6 +76,7 @@ export class Meter {
|
|
|
75
76
|
this.deviceContext();
|
|
76
77
|
this.setupHistoryService(device);
|
|
77
78
|
this.setupMqtt(device);
|
|
79
|
+
this.deviceRetry(device);
|
|
78
80
|
this.deviceConfig(device);
|
|
79
81
|
|
|
80
82
|
this.CurrentRelativeHumidity = accessory.context.CurrentRelativeHumidity;
|
|
@@ -398,9 +400,10 @@ export class Meter {
|
|
|
398
400
|
async openAPIRefreshStatus(): Promise<void> {
|
|
399
401
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
400
402
|
try {
|
|
401
|
-
const { body, statusCode } = await
|
|
402
|
-
|
|
403
|
-
|
|
403
|
+
const { body, statusCode } = await this.platform.retryRequest(this.maxRetries, this.delayBetweenRetries,
|
|
404
|
+
`${Devices}/${this.device.deviceId}/status`, {
|
|
405
|
+
headers: this.platform.generateHeaders(),
|
|
406
|
+
});
|
|
404
407
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
405
408
|
const deviceStatus: any = await body.json();
|
|
406
409
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -736,6 +739,23 @@ export class Meter {
|
|
|
736
739
|
}
|
|
737
740
|
}
|
|
738
741
|
|
|
742
|
+
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
743
|
+
if (device.maxRetries === undefined) {
|
|
744
|
+
this.maxRetries = 5; // Maximum number of retries
|
|
745
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
746
|
+
} else {
|
|
747
|
+
this.maxRetries = device.maxRetries;
|
|
748
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
749
|
+
}
|
|
750
|
+
if (device.delayBetweenRetries === undefined) {
|
|
751
|
+
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
752
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
753
|
+
} else {
|
|
754
|
+
this.delayBetweenRetries = device.delayBetweenRetries;
|
|
755
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
739
759
|
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
740
760
|
let config = {};
|
|
741
761
|
if (device.meter) {
|
package/src/device/meterplus.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { CharacteristicValue, PlatformAccessory, Service, Units, API, Logging, H
|
|
|
3
3
|
import { MqttClient } from 'mqtt';
|
|
4
4
|
import { hostname } from 'os';
|
|
5
5
|
import { interval } from 'rxjs';
|
|
6
|
-
import { request } from 'undici';
|
|
7
6
|
import { SwitchBotPlatform } from '../platform.js';
|
|
8
7
|
import { Devices, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings.js';
|
|
9
8
|
import { sleep } from '../utils.js';
|
|
@@ -56,6 +55,8 @@ export class MeterPlus {
|
|
|
56
55
|
scanDuration!: number;
|
|
57
56
|
deviceLogging!: string;
|
|
58
57
|
deviceRefreshRate!: number;
|
|
58
|
+
maxRetries!: number;
|
|
59
|
+
delayBetweenRetries!: number;
|
|
59
60
|
|
|
60
61
|
// Connection
|
|
61
62
|
private readonly OpenAPI: boolean;
|
|
@@ -80,6 +81,7 @@ export class MeterPlus {
|
|
|
80
81
|
this.deviceContext();
|
|
81
82
|
this.setupHistoryService(device);
|
|
82
83
|
this.setupMqtt(device);
|
|
84
|
+
this.deviceRetry(device);
|
|
83
85
|
this.deviceConfig(device);
|
|
84
86
|
|
|
85
87
|
// Retrieve initial values and updateHomekit
|
|
@@ -400,9 +402,10 @@ export class MeterPlus {
|
|
|
400
402
|
async openAPIRefreshStatus(): Promise<void> {
|
|
401
403
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
402
404
|
try {
|
|
403
|
-
const { body, statusCode } = await
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
const { body, statusCode } = await this.platform.retryRequest(this.maxRetries, this.delayBetweenRetries,
|
|
406
|
+
`${Devices}/${this.device.deviceId}/status`, {
|
|
407
|
+
headers: this.platform.generateHeaders(),
|
|
408
|
+
});
|
|
406
409
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
407
410
|
const deviceStatus: any = await body.json();
|
|
408
411
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -751,6 +754,23 @@ export class MeterPlus {
|
|
|
751
754
|
}
|
|
752
755
|
}
|
|
753
756
|
|
|
757
|
+
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
758
|
+
if (device.maxRetries === undefined) {
|
|
759
|
+
this.maxRetries = 5; // Maximum number of retries
|
|
760
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
761
|
+
} else {
|
|
762
|
+
this.maxRetries = device.maxRetries;
|
|
763
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
764
|
+
}
|
|
765
|
+
if (device.delayBetweenRetries === undefined) {
|
|
766
|
+
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
767
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
768
|
+
} else {
|
|
769
|
+
this.delayBetweenRetries = device.delayBetweenRetries;
|
|
770
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
754
774
|
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
755
775
|
let config = {};
|
|
756
776
|
if (device.meter) {
|
package/src/device/motion.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { request } from 'undici';
|
|
2
1
|
import { sleep } from '../utils.js';
|
|
3
2
|
import { interval, Subject } from 'rxjs';
|
|
4
3
|
import { skipWhile } from 'rxjs/operators';
|
|
@@ -49,6 +48,8 @@ export class Motion {
|
|
|
49
48
|
scanDuration!: number;
|
|
50
49
|
deviceLogging!: string;
|
|
51
50
|
deviceRefreshRate!: number;
|
|
51
|
+
maxRetries!: number;
|
|
52
|
+
delayBetweenRetries!: number;
|
|
52
53
|
|
|
53
54
|
// Updates
|
|
54
55
|
motionUbpdateInProgress!: boolean;
|
|
@@ -75,6 +76,7 @@ export class Motion {
|
|
|
75
76
|
this.scan(device);
|
|
76
77
|
this.refreshRate(device);
|
|
77
78
|
this.deviceContext();
|
|
79
|
+
this.deviceRetry(device);
|
|
78
80
|
this.deviceConfig(device);
|
|
79
81
|
|
|
80
82
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -392,9 +394,10 @@ export class Motion {
|
|
|
392
394
|
async openAPIRefreshStatus(): Promise<void> {
|
|
393
395
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
394
396
|
try {
|
|
395
|
-
const { body, statusCode } = await
|
|
396
|
-
|
|
397
|
-
|
|
397
|
+
const { body, statusCode } = await this.platform.retryRequest(this.maxRetries, this.delayBetweenRetries,
|
|
398
|
+
`${Devices}/${this.device.deviceId}/status`, {
|
|
399
|
+
headers: this.platform.generateHeaders(),
|
|
400
|
+
});
|
|
398
401
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
399
402
|
const deviceStatus: any = await body.json();
|
|
400
403
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -665,6 +668,23 @@ export class Motion {
|
|
|
665
668
|
}
|
|
666
669
|
}
|
|
667
670
|
|
|
671
|
+
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
672
|
+
if (device.maxRetries === undefined) {
|
|
673
|
+
this.maxRetries = 5; // Maximum number of retries
|
|
674
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
675
|
+
} else {
|
|
676
|
+
this.maxRetries = device.maxRetries;
|
|
677
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
678
|
+
}
|
|
679
|
+
if (device.delayBetweenRetries === undefined) {
|
|
680
|
+
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
681
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
682
|
+
} else {
|
|
683
|
+
this.delayBetweenRetries = device.delayBetweenRetries;
|
|
684
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
668
688
|
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
669
689
|
let config = {};
|
|
670
690
|
if (device.motion) {
|
package/src/device/plug.ts
CHANGED
|
@@ -30,6 +30,8 @@ export class Plug {
|
|
|
30
30
|
scanDuration!: number;
|
|
31
31
|
deviceLogging!: string;
|
|
32
32
|
deviceRefreshRate!: number;
|
|
33
|
+
maxRetries!: number;
|
|
34
|
+
delayBetweenRetries!: number;
|
|
33
35
|
|
|
34
36
|
// Updates
|
|
35
37
|
plugUpdateInProgress!: boolean;
|
|
@@ -56,6 +58,7 @@ export class Plug {
|
|
|
56
58
|
this.scan(device);
|
|
57
59
|
this.refreshRate(device);
|
|
58
60
|
this.deviceContext();
|
|
61
|
+
this.deviceRetry(device);
|
|
59
62
|
this.deviceConfig(device);
|
|
60
63
|
|
|
61
64
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -297,9 +300,10 @@ export class Plug {
|
|
|
297
300
|
async openAPIRefreshStatus() {
|
|
298
301
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
299
302
|
try {
|
|
300
|
-
const { body, statusCode } = await
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
const { body, statusCode } = await this.platform.retryRequest(this.maxRetries, this.delayBetweenRetries,
|
|
304
|
+
`${Devices}/${this.device.deviceId}/status`, {
|
|
305
|
+
headers: this.platform.generateHeaders(),
|
|
306
|
+
});
|
|
303
307
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
304
308
|
const deviceStatus: any = await body.json();
|
|
305
309
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -691,6 +695,23 @@ export class Plug {
|
|
|
691
695
|
}
|
|
692
696
|
}
|
|
693
697
|
|
|
698
|
+
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
699
|
+
if (device.maxRetries === undefined) {
|
|
700
|
+
this.maxRetries = 5; // Maximum number of retries
|
|
701
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
702
|
+
} else {
|
|
703
|
+
this.maxRetries = device.maxRetries;
|
|
704
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
705
|
+
}
|
|
706
|
+
if (device.delayBetweenRetries === undefined) {
|
|
707
|
+
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
708
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
709
|
+
} else {
|
|
710
|
+
this.delayBetweenRetries = device.delayBetweenRetries;
|
|
711
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
694
715
|
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
695
716
|
let config = {};
|
|
696
717
|
if (device.plug) {
|
|
@@ -37,6 +37,8 @@ export class RobotVacuumCleaner {
|
|
|
37
37
|
scanDuration!: number;
|
|
38
38
|
deviceLogging!: string;
|
|
39
39
|
deviceRefreshRate!: number;
|
|
40
|
+
maxRetries!: number;
|
|
41
|
+
delayBetweenRetries!: number;
|
|
40
42
|
|
|
41
43
|
// Updates
|
|
42
44
|
robotVacuumCleanerUpdateInProgress!: boolean;
|
|
@@ -63,6 +65,7 @@ export class RobotVacuumCleaner {
|
|
|
63
65
|
this.scan(device);
|
|
64
66
|
this.refreshRate(device);
|
|
65
67
|
this.deviceContext();
|
|
68
|
+
this.deviceRetry(device);
|
|
66
69
|
this.deviceConfig(device);
|
|
67
70
|
|
|
68
71
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -344,9 +347,10 @@ export class RobotVacuumCleaner {
|
|
|
344
347
|
async openAPIRefreshStatus() {
|
|
345
348
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
346
349
|
try {
|
|
347
|
-
const { body, statusCode } = await
|
|
348
|
-
|
|
349
|
-
|
|
350
|
+
const { body, statusCode } = await this.platform.retryRequest(this.maxRetries, this.delayBetweenRetries,
|
|
351
|
+
`${Devices}/${this.device.deviceId}/status`, {
|
|
352
|
+
headers: this.platform.generateHeaders(),
|
|
353
|
+
});
|
|
350
354
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
351
355
|
const deviceStatus: any = await body.json();
|
|
352
356
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -852,6 +856,23 @@ export class RobotVacuumCleaner {
|
|
|
852
856
|
}
|
|
853
857
|
}
|
|
854
858
|
|
|
859
|
+
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
860
|
+
if (device.maxRetries === undefined) {
|
|
861
|
+
this.maxRetries = 5; // Maximum number of retries
|
|
862
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
863
|
+
} else {
|
|
864
|
+
this.maxRetries = device.maxRetries;
|
|
865
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
866
|
+
}
|
|
867
|
+
if (device.delayBetweenRetries === undefined) {
|
|
868
|
+
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
869
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
870
|
+
} else {
|
|
871
|
+
this.delayBetweenRetries = device.delayBetweenRetries;
|
|
872
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
855
876
|
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
856
877
|
let config = {};
|
|
857
878
|
if (device.plug) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { hostname } from 'os';
|
|
2
|
-
import { request } from 'undici';
|
|
3
2
|
import { sleep } from '../utils.js';
|
|
4
3
|
import { MqttClient } from 'mqtt';
|
|
5
4
|
import asyncmqtt from 'async-mqtt';
|
|
@@ -53,6 +52,8 @@ export class WaterDetector {
|
|
|
53
52
|
scanDuration!: number;
|
|
54
53
|
deviceLogging!: string;
|
|
55
54
|
deviceRefreshRate!: number;
|
|
55
|
+
maxRetries!: number;
|
|
56
|
+
delayBetweenRetries!: number;
|
|
56
57
|
|
|
57
58
|
// Updates
|
|
58
59
|
WaterDetectorUpdateInProgress!: boolean;
|
|
@@ -81,6 +82,7 @@ export class WaterDetector {
|
|
|
81
82
|
this.deviceContext();
|
|
82
83
|
this.setupHistoryService(device);
|
|
83
84
|
this.setupMqtt(device);
|
|
85
|
+
this.deviceRetry(device);
|
|
84
86
|
this.deviceConfig(device);
|
|
85
87
|
|
|
86
88
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -282,9 +284,10 @@ export class WaterDetector {
|
|
|
282
284
|
async openAPIRefreshStatus(): Promise<void> {
|
|
283
285
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
284
286
|
try {
|
|
285
|
-
const { body, statusCode } = await
|
|
286
|
-
|
|
287
|
-
|
|
287
|
+
const { body, statusCode } = await this.platform.retryRequest(this.maxRetries, this.delayBetweenRetries,
|
|
288
|
+
`${Devices}/${this.device.deviceId}/status`, {
|
|
289
|
+
headers: this.platform.generateHeaders(),
|
|
290
|
+
});
|
|
288
291
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
289
292
|
const deviceStatus: any = await body.json();
|
|
290
293
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -589,6 +592,23 @@ export class WaterDetector {
|
|
|
589
592
|
}
|
|
590
593
|
}
|
|
591
594
|
|
|
595
|
+
async deviceRetry(device: device & devicesConfig): Promise<void> {
|
|
596
|
+
if (device.maxRetries === undefined) {
|
|
597
|
+
this.maxRetries = 5; // Maximum number of retries
|
|
598
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
599
|
+
} else {
|
|
600
|
+
this.maxRetries = device.maxRetries;
|
|
601
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
602
|
+
}
|
|
603
|
+
if (device.delayBetweenRetries === undefined) {
|
|
604
|
+
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
605
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
606
|
+
} else {
|
|
607
|
+
this.delayBetweenRetries = device.delayBetweenRetries;
|
|
608
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
592
612
|
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
593
613
|
let config = {};
|
|
594
614
|
if (device.waterdetector) {
|
package/src/platform.ts
CHANGED
|
@@ -32,7 +32,7 @@ import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
|
32
32
|
import { AirConditioner } from './irdevice/airconditioner.js';
|
|
33
33
|
import * as http from 'http';
|
|
34
34
|
import { Buffer } from 'buffer';
|
|
35
|
-
import { request } from 'undici';
|
|
35
|
+
import { Dispatcher, request } from 'undici';
|
|
36
36
|
import { MqttClient } from 'mqtt';
|
|
37
37
|
import { queueScheduler } from 'rxjs';
|
|
38
38
|
import fakegato from 'fakegato-history';
|
|
@@ -40,6 +40,8 @@ import asyncmqtt from 'async-mqtt';
|
|
|
40
40
|
import crypto, { randomUUID } from 'crypto';
|
|
41
41
|
import { readFileSync, writeFileSync } from 'fs';
|
|
42
42
|
import hbLib from 'homebridge-lib';
|
|
43
|
+
import { UrlObject } from 'url';
|
|
44
|
+
import { sleep } from './utils.js';
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
|
|
@@ -635,7 +637,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
635
637
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
636
638
|
break;
|
|
637
639
|
case 'Hub 2':
|
|
638
|
-
case 'remote with screen':
|
|
639
640
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
640
641
|
this.createHub2(device);
|
|
641
642
|
break;
|
|
@@ -2629,6 +2630,30 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2629
2630
|
}
|
|
2630
2631
|
}
|
|
2631
2632
|
|
|
2633
|
+
async retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number, url: string | URL | UrlObject,
|
|
2634
|
+
options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions,
|
|
2635
|
+
'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>): Promise<{ body: any; statusCode: number }> {
|
|
2636
|
+
let retryCount = 0;
|
|
2637
|
+
const maxRetries = deviceMaxRetries;
|
|
2638
|
+
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2639
|
+
while (retryCount < maxRetries) {
|
|
2640
|
+
try {
|
|
2641
|
+
const { body, statusCode } = await request(url, options);
|
|
2642
|
+
if (statusCode === 200 || statusCode === 100) {
|
|
2643
|
+
return { body, statusCode };
|
|
2644
|
+
} else {
|
|
2645
|
+
this.debugLog(`Received status code: ${statusCode}`);
|
|
2646
|
+
}
|
|
2647
|
+
} catch (error: any) {
|
|
2648
|
+
this.errorLog(`Error making request: ${error.message}`);
|
|
2649
|
+
}
|
|
2650
|
+
retryCount++;
|
|
2651
|
+
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2652
|
+
await sleep(delayBetweenRetries);
|
|
2653
|
+
}
|
|
2654
|
+
return { body: null, statusCode: -1 };
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2632
2657
|
// BLE Connection
|
|
2633
2658
|
async connectBLE() {
|
|
2634
2659
|
let switchbot: any;
|
package/src/settings.ts
CHANGED