@switchbot/homebridge-switchbot 2.2.2-beta.8 → 2.2.2
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 +13 -0
- package/config.schema.json +9 -42
- package/dist/device/bot.d.ts +1 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +1 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +1 -1
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +3 -3
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -7
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +17 -2
- package/dist/device/contact.js.map +1 -1
- package/dist/device/humidifier.d.ts +7 -9
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +13 -11
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/meter.d.ts +1 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +1 -1
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +1 -1
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +15 -3
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +1 -3
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +9 -7
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +6 -6
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +39 -35
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -8
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -29
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +4 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +20 -24
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +4 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -26
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +4 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +20 -20
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +4 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +20 -24
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +6 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +35 -36
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +4 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +20 -24
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +4 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +26 -31
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +0 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +29 -35
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -19
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +5 -5
- package/src/device/bot.ts +1 -1
- package/src/device/ceilinglight.ts +1 -1
- package/src/device/colorbulb.ts +3 -3
- package/src/device/contact.ts +24 -10
- package/src/device/humidifier.ts +11 -11
- package/src/device/meter.ts +1 -1
- package/src/device/meterplus.ts +1 -1
- package/src/device/motion.ts +18 -7
- package/src/device/plug.ts +1 -1
- package/src/device/striplight.ts +5 -5
- package/src/irdevice/airconditioner.ts +43 -39
- package/src/irdevice/airpurifier.ts +34 -33
- package/src/irdevice/camera.ts +23 -26
- package/src/irdevice/fan.ts +25 -28
- package/src/irdevice/light.ts +23 -22
- package/src/irdevice/other.ts +23 -26
- package/src/irdevice/tv.ts +38 -39
- package/src/irdevice/vacuumcleaner.ts +23 -26
- package/src/irdevice/waterheater.ts +28 -32
- package/src/platform.ts +28 -34
- package/src/settings.ts +12 -28
- package/.github/npm-version-script.js +0 -81
package/src/device/bot.ts
CHANGED
|
@@ -1063,7 +1063,7 @@ export class Bot {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
}
|
|
1065
1065
|
|
|
1066
|
-
async stopScanning(
|
|
1066
|
+
async stopScanning(switchbot: any) {
|
|
1067
1067
|
await switchbot.stopScan();
|
|
1068
1068
|
if (this.connected) {
|
|
1069
1069
|
await this.BLEparseStatus();
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -392,7 +392,7 @@ export class ColorBulb {
|
|
|
392
392
|
if (this.serviceData) {
|
|
393
393
|
this.connected = true;
|
|
394
394
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
395
|
-
await this.stopScanning(
|
|
395
|
+
await this.stopScanning(switchbot);
|
|
396
396
|
} else {
|
|
397
397
|
this.connected = false;
|
|
398
398
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -403,7 +403,7 @@ export class ColorBulb {
|
|
|
403
403
|
})
|
|
404
404
|
.then(async () => {
|
|
405
405
|
// Stop to monitor
|
|
406
|
-
await this.stopScanning(
|
|
406
|
+
await this.stopScanning(switchbot);
|
|
407
407
|
})
|
|
408
408
|
.catch(async (e: any) => {
|
|
409
409
|
this.apiError(e);
|
|
@@ -1065,7 +1065,7 @@ export class ColorBulb {
|
|
|
1065
1065
|
}
|
|
1066
1066
|
}
|
|
1067
1067
|
|
|
1068
|
-
async stopScanning(
|
|
1068
|
+
async stopScanning(switchbot: any) {
|
|
1069
1069
|
await switchbot.stopScan();
|
|
1070
1070
|
if (this.connected) {
|
|
1071
1071
|
await this.BLEparseStatus();
|
package/src/device/contact.ts
CHANGED
|
@@ -35,7 +35,12 @@ export class Contact {
|
|
|
35
35
|
deviceStatus!: any; //deviceStatusResponse;
|
|
36
36
|
|
|
37
37
|
// BLE Others
|
|
38
|
+
tested!: any;
|
|
39
|
+
contact_open!: any;
|
|
40
|
+
button_count!: any;
|
|
41
|
+
scanning!: boolean;
|
|
38
42
|
connected?: boolean;
|
|
43
|
+
contact_timeout!: any;
|
|
39
44
|
switchbot!: switchbot;
|
|
40
45
|
serviceData!: serviceData;
|
|
41
46
|
address!: ad['address'];
|
|
@@ -43,10 +48,6 @@ export class Contact {
|
|
|
43
48
|
movement!: serviceData['movement'];
|
|
44
49
|
doorState!: serviceData['doorState'];
|
|
45
50
|
is_light!: any; //serviceData['lightLevel'];
|
|
46
|
-
tested!: any;
|
|
47
|
-
contact_open!: any;
|
|
48
|
-
contact_timeout!: any;
|
|
49
|
-
button_count!: any;
|
|
50
51
|
|
|
51
52
|
// Config
|
|
52
53
|
set_minLux!: number;
|
|
@@ -195,10 +196,18 @@ export class Contact {
|
|
|
195
196
|
default:
|
|
196
197
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
|
|
197
198
|
}
|
|
199
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
200
|
+
if ((this.ContactSensorState !== this.accessory.context.ContactSensorState)
|
|
201
|
+
&& this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED) {
|
|
202
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Opened`);
|
|
203
|
+
}
|
|
198
204
|
// Movement
|
|
199
205
|
if (!this.device.contact?.hide_motionsensor) {
|
|
200
206
|
this.MotionDetected = Boolean(this.movement);
|
|
201
207
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
208
|
+
if ((this.MotionDetected !== this.accessory.context.MotionDetected) && this.MotionDetected) {
|
|
209
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
210
|
+
}
|
|
202
211
|
}
|
|
203
212
|
// Light Level
|
|
204
213
|
if (!this.device.contact?.hide_lightsensor) {
|
|
@@ -211,10 +220,11 @@ export class Contact {
|
|
|
211
220
|
default:
|
|
212
221
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
213
222
|
}
|
|
214
|
-
this.debugLog(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.is_light},` +
|
|
224
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
225
|
+
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
226
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
227
|
+
}
|
|
218
228
|
}
|
|
219
229
|
// Battery
|
|
220
230
|
if (this.battery === undefined) {
|
|
@@ -301,6 +311,7 @@ export class Contact {
|
|
|
301
311
|
})
|
|
302
312
|
.then(async () => {
|
|
303
313
|
// Set an event hander
|
|
314
|
+
this.scanning = true;
|
|
304
315
|
switchbot.onadvertisement = async (ad: any) => {
|
|
305
316
|
this.address = ad.address;
|
|
306
317
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
@@ -324,6 +335,7 @@ export class Contact {
|
|
|
324
335
|
this.connected = true;
|
|
325
336
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
326
337
|
await this.stopScanning(switchbot);
|
|
338
|
+
this.scanning = false;
|
|
327
339
|
} else {
|
|
328
340
|
this.connected = false;
|
|
329
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -334,7 +346,9 @@ export class Contact {
|
|
|
334
346
|
})
|
|
335
347
|
.then(async () => {
|
|
336
348
|
// Stop to monitor
|
|
337
|
-
|
|
349
|
+
if (this.scanning) {
|
|
350
|
+
await this.stopScanning(switchbot);
|
|
351
|
+
}
|
|
338
352
|
})
|
|
339
353
|
.catch(async (e: any) => {
|
|
340
354
|
this.apiError(e);
|
|
@@ -450,7 +464,7 @@ export class Contact {
|
|
|
450
464
|
}
|
|
451
465
|
}
|
|
452
466
|
|
|
453
|
-
async stopScanning(
|
|
467
|
+
async stopScanning(switchbot: any) {
|
|
454
468
|
await switchbot.stopScan();
|
|
455
469
|
if (this.connected) {
|
|
456
470
|
await this.BLEparseStatus();
|
package/src/device/humidifier.ts
CHANGED
|
@@ -765,7 +765,7 @@ export class Humidifier {
|
|
|
765
765
|
}
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
-
async stopScanning(
|
|
768
|
+
async stopScanning(switchbot: any) {
|
|
769
769
|
await switchbot.stopScan();
|
|
770
770
|
if (this.connected) {
|
|
771
771
|
await this.BLEparseStatus();
|
|
@@ -923,15 +923,15 @@ export class Humidifier {
|
|
|
923
923
|
}
|
|
924
924
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
925
925
|
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
926
|
+
} else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
|
|
927
|
+
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
926
928
|
} else {
|
|
927
929
|
this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
|
|
928
|
-
if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
|
|
929
|
-
this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
930
|
-
}
|
|
931
|
-
this.warnLog(this.TargetHumidifierDehumidifierState);
|
|
932
930
|
}
|
|
933
931
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
934
932
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
933
|
+
} else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
|
|
934
|
+
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
935
935
|
} else {
|
|
936
936
|
this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
|
|
937
937
|
}
|
|
@@ -1004,19 +1004,19 @@ export class Humidifier {
|
|
|
1004
1004
|
/**
|
|
1005
1005
|
* Logging for Device
|
|
1006
1006
|
*/
|
|
1007
|
-
infoLog(...log: any[]): void {
|
|
1007
|
+
async infoLog(...log: any[]): Promise<void> {
|
|
1008
1008
|
if (this.enablingDeviceLogging()) {
|
|
1009
1009
|
this.platform.log.info(String(...log));
|
|
1010
1010
|
}
|
|
1011
1011
|
}
|
|
1012
1012
|
|
|
1013
|
-
warnLog(...log: any[]): void {
|
|
1013
|
+
async warnLog(...log: any[]): Promise<void> {
|
|
1014
1014
|
if (this.enablingDeviceLogging()) {
|
|
1015
1015
|
this.platform.log.warn(String(...log));
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
1018
|
|
|
1019
|
-
debugWarnLog(...log: any[]): void {
|
|
1019
|
+
async debugWarnLog(...log: any[]): Promise<void> {
|
|
1020
1020
|
if (this.enablingDeviceLogging()) {
|
|
1021
1021
|
if (this.deviceLogging?.includes('debug')) {
|
|
1022
1022
|
this.platform.log.warn('[DEBUG]', String(...log));
|
|
@@ -1024,13 +1024,13 @@ export class Humidifier {
|
|
|
1024
1024
|
}
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
|
-
errorLog(...log: any[]): void {
|
|
1027
|
+
async errorLog(...log: any[]): Promise<void> {
|
|
1028
1028
|
if (this.enablingDeviceLogging()) {
|
|
1029
1029
|
this.platform.log.error(String(...log));
|
|
1030
1030
|
}
|
|
1031
1031
|
}
|
|
1032
1032
|
|
|
1033
|
-
debugErrorLog(...log: any[]): void {
|
|
1033
|
+
async debugErrorLog(...log: any[]): Promise<void> {
|
|
1034
1034
|
if (this.enablingDeviceLogging()) {
|
|
1035
1035
|
if (this.deviceLogging?.includes('debug')) {
|
|
1036
1036
|
this.platform.log.error('[DEBUG]', String(...log));
|
|
@@ -1038,7 +1038,7 @@ export class Humidifier {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
|
-
debugLog(...log: any[]): void {
|
|
1041
|
+
async debugLog(...log: any[]): Promise<void> {
|
|
1042
1042
|
if (this.enablingDeviceLogging()) {
|
|
1043
1043
|
if (this.deviceLogging === 'debug') {
|
|
1044
1044
|
this.platform.log.info('[DEBUG]', String(...log));
|
package/src/device/meter.ts
CHANGED
package/src/device/meterplus.ts
CHANGED
|
@@ -487,7 +487,7 @@ export class MeterPlus {
|
|
|
487
487
|
: null;
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
-
async stopScanning(
|
|
490
|
+
async stopScanning(switchbot: any) {
|
|
491
491
|
await switchbot.stopScan();
|
|
492
492
|
if (this.connected) {
|
|
493
493
|
await this.BLEparseStatus();
|
package/src/device/motion.ts
CHANGED
|
@@ -32,6 +32,7 @@ export class Motion {
|
|
|
32
32
|
brightness: deviceStatus['brightness'];
|
|
33
33
|
|
|
34
34
|
// BLE Others
|
|
35
|
+
scanning!: boolean;
|
|
35
36
|
connected?: boolean;
|
|
36
37
|
switchbot!: switchbot;
|
|
37
38
|
serviceData!: serviceData;
|
|
@@ -165,6 +166,9 @@ export class Motion {
|
|
|
165
166
|
// Movement
|
|
166
167
|
this.MotionDetected = this.movement!;
|
|
167
168
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
169
|
+
if ((this.MotionDetected !== this.accessory.context.MotionDetected) && this.MotionDetected) {
|
|
170
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
171
|
+
}
|
|
168
172
|
// Light Level
|
|
169
173
|
if (!this.device.motion?.hide_lightsensor) {
|
|
170
174
|
this.set_minLux = this.minLux();
|
|
@@ -177,10 +181,11 @@ export class Motion {
|
|
|
177
181
|
default:
|
|
178
182
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
179
183
|
}
|
|
180
|
-
this.debugLog(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
185
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
186
|
+
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
187
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
188
|
+
}
|
|
184
189
|
}
|
|
185
190
|
// Battery
|
|
186
191
|
if (this.battery === undefined) {
|
|
@@ -255,6 +260,7 @@ export class Motion {
|
|
|
255
260
|
})
|
|
256
261
|
.then(async () => {
|
|
257
262
|
// Set an event hander
|
|
263
|
+
this.scanning = true;
|
|
258
264
|
switchbot.onadvertisement = async (ad: any) => {
|
|
259
265
|
this.address = ad.address;
|
|
260
266
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
@@ -278,6 +284,8 @@ export class Motion {
|
|
|
278
284
|
this.connected = true;
|
|
279
285
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
280
286
|
await this.stopScanning(switchbot);
|
|
287
|
+
this.scanning = false;
|
|
288
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
|
|
281
289
|
} else {
|
|
282
290
|
this.connected = false;
|
|
283
291
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -288,7 +296,10 @@ export class Motion {
|
|
|
288
296
|
})
|
|
289
297
|
.then(async () => {
|
|
290
298
|
// Stop to monitor
|
|
291
|
-
|
|
299
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
|
|
300
|
+
if (this.scanning) {
|
|
301
|
+
await this.stopScanning(switchbot);
|
|
302
|
+
}
|
|
292
303
|
})
|
|
293
304
|
.catch(async (e: any) => {
|
|
294
305
|
this.apiError(e);
|
|
@@ -394,8 +405,8 @@ export class Motion {
|
|
|
394
405
|
}
|
|
395
406
|
}
|
|
396
407
|
|
|
397
|
-
async stopScanning(
|
|
398
|
-
await
|
|
408
|
+
async stopScanning(switchbot: any) {
|
|
409
|
+
await switchbot.stopScan();
|
|
399
410
|
if (this.connected) {
|
|
400
411
|
await this.BLEparseStatus();
|
|
401
412
|
await this.updateHomeKitCharacteristics();
|
package/src/device/plug.ts
CHANGED
package/src/device/striplight.ts
CHANGED
|
@@ -215,9 +215,9 @@ export class StripLight {
|
|
|
215
215
|
async parseStatus(): Promise<void> {
|
|
216
216
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
217
217
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
218
|
-
} else
|
|
218
|
+
} else if (this.BLE) {
|
|
219
219
|
await this.BLEparseStatus();
|
|
220
|
-
} else
|
|
220
|
+
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
221
221
|
await this.openAPIparseStatus();
|
|
222
222
|
} else {
|
|
223
223
|
await this.offlineOff();
|
|
@@ -282,9 +282,9 @@ export class StripLight {
|
|
|
282
282
|
async refreshStatus(): Promise<void> {
|
|
283
283
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
284
284
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
285
|
-
} else
|
|
285
|
+
} else if (this.BLE) {
|
|
286
286
|
await this.BLERefreshStatus();
|
|
287
|
-
} else
|
|
287
|
+
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
288
288
|
await this.openAPIRefreshStatus();
|
|
289
289
|
} else {
|
|
290
290
|
await this.offlineOff();
|
|
@@ -830,7 +830,7 @@ export class StripLight {
|
|
|
830
830
|
}
|
|
831
831
|
}
|
|
832
832
|
|
|
833
|
-
async stopScanning(
|
|
833
|
+
async stopScanning(switchbot: any) {
|
|
834
834
|
await switchbot.stopScan();
|
|
835
835
|
if (this.connected) {
|
|
836
836
|
await this.BLEparseStatus();
|
|
@@ -3,7 +3,7 @@ import crypto from 'crypto';
|
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import superStringify from 'super-stringify';
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
|
-
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
|
+
import { irDevicesConfig, irdevice, HostDomain, DevicePath, body } from '../settings';
|
|
7
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -36,8 +36,8 @@ export class AirConditioner {
|
|
|
36
36
|
static MODE_HEAT: number;
|
|
37
37
|
|
|
38
38
|
// Config
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
disablePushOn?: boolean;
|
|
40
|
+
disablePushOff?: boolean;
|
|
41
41
|
deviceLogging!: string;
|
|
42
42
|
hide_automode?: boolean;
|
|
43
43
|
|
|
@@ -49,8 +49,8 @@ export class AirConditioner {
|
|
|
49
49
|
this.logs({ device });
|
|
50
50
|
this.config({ device });
|
|
51
51
|
this.context();
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
52
|
+
this.disablePushOnChanges({ device });
|
|
53
|
+
this.disablePushOffChanges({ device });
|
|
54
54
|
|
|
55
55
|
// set accessory information
|
|
56
56
|
accessory
|
|
@@ -65,7 +65,7 @@ export class AirConditioner {
|
|
|
65
65
|
// get the Television service if it exists, otherwise create a new Television service
|
|
66
66
|
// you can create multiple services for each accessory
|
|
67
67
|
(this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
|
|
68
|
-
`${accessory.displayName}
|
|
68
|
+
`${accessory.displayName} ${device.remoteType}`;
|
|
69
69
|
|
|
70
70
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
71
71
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -166,8 +166,8 @@ export class AirConditioner {
|
|
|
166
166
|
*/
|
|
167
167
|
async pushAirConditionerOnChanges(): Promise<void> {
|
|
168
168
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.Active},`
|
|
169
|
-
+ `
|
|
170
|
-
if (this.Active === this.platform.Characteristic.Active.
|
|
169
|
+
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
170
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
171
171
|
const commandType: string = await this.commandType();
|
|
172
172
|
const command: string = await this.commandOn();
|
|
173
173
|
const body = superStringify({
|
|
@@ -181,8 +181,8 @@ export class AirConditioner {
|
|
|
181
181
|
|
|
182
182
|
async pushAirConditionerOffChanges(): Promise<void> {
|
|
183
183
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.Active},`
|
|
184
|
-
+ `
|
|
185
|
-
if (this.Active === this.platform.Characteristic.Active.
|
|
184
|
+
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
185
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
186
186
|
const commandType: string = await this.commandType();
|
|
187
187
|
const command: string = await this.commandOff();
|
|
188
188
|
const body = superStringify({
|
|
@@ -195,6 +195,8 @@ export class AirConditioner {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
async pushAirConditionerStatusChanges(): Promise<void> {
|
|
198
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},`
|
|
199
|
+
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
198
200
|
if (!this.Busy) {
|
|
199
201
|
this.Busy = true;
|
|
200
202
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
@@ -206,6 +208,8 @@ export class AirConditioner {
|
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
211
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},`
|
|
212
|
+
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
209
213
|
await this.context();
|
|
210
214
|
if (this.CurrentMode === undefined) {
|
|
211
215
|
this.CurrentMode = 1;
|
|
@@ -246,10 +250,11 @@ export class AirConditioner {
|
|
|
246
250
|
await this.pushChanges(body);
|
|
247
251
|
}
|
|
248
252
|
|
|
249
|
-
async pushChanges(body:
|
|
253
|
+
async pushChanges(body: Array<body>): Promise<void> {
|
|
250
254
|
if (this.device.connectionType === 'OpenAPI') {
|
|
251
255
|
try {
|
|
252
|
-
|
|
256
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${body}`);
|
|
257
|
+
// Make Push On request to the API
|
|
253
258
|
const t = Date.now();
|
|
254
259
|
const nonce = 'requestID';
|
|
255
260
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
@@ -286,11 +291,11 @@ export class AirConditioner {
|
|
|
286
291
|
req.write(body);
|
|
287
292
|
req.end();
|
|
288
293
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
289
|
-
|
|
294
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
290
295
|
this.HeatingThresholdTemperature = this.CurrentTemperature;
|
|
291
296
|
this.CoolingThresholdTemperature = this.CurrentTemperature;
|
|
292
|
-
|
|
293
|
-
|
|
297
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
298
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
294
299
|
this.updateHomeKitCharacteristics();
|
|
295
300
|
} catch (e: any) {
|
|
296
301
|
this.apiError({ e });
|
|
@@ -341,22 +346,19 @@ export class AirConditioner {
|
|
|
341
346
|
|
|
342
347
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
343
348
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
} else {
|
|
349
|
+
|
|
350
|
+
this.Active = value;
|
|
351
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
348
352
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
|
|
349
|
-
if (this.
|
|
350
|
-
this.pushAirConditionerOnChanges();
|
|
351
|
-
} else {
|
|
353
|
+
if (this.disablePushOn) {
|
|
352
354
|
this.pushAirConditionerStatusChanges();
|
|
355
|
+
} else {
|
|
356
|
+
this.pushAirConditionerOnChanges();
|
|
353
357
|
}
|
|
358
|
+
} else {
|
|
359
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
360
|
+
this.pushAirConditionerOffChanges();
|
|
354
361
|
}
|
|
355
|
-
/**
|
|
356
|
-
* pushAirConditionerOnChanges and pushAirConditionerOffChanges above assume they are measuring the state of the accessory BEFORE
|
|
357
|
-
* they are updated, so we are only updating the accessory state after calling the above.
|
|
358
|
-
*/
|
|
359
|
-
this.Active = value;
|
|
360
362
|
}
|
|
361
363
|
|
|
362
364
|
async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
@@ -549,19 +551,19 @@ export class AirConditioner {
|
|
|
549
551
|
}
|
|
550
552
|
}
|
|
551
553
|
|
|
552
|
-
async
|
|
553
|
-
if (device.
|
|
554
|
-
this.
|
|
554
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
555
|
+
if (device.disablePushOn === undefined) {
|
|
556
|
+
this.disablePushOn = false;
|
|
555
557
|
} else {
|
|
556
|
-
this.
|
|
558
|
+
this.disablePushOn = device.disablePushOn;
|
|
557
559
|
}
|
|
558
560
|
}
|
|
559
561
|
|
|
560
|
-
async
|
|
561
|
-
if (device.
|
|
562
|
-
this.
|
|
562
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
563
|
+
if (device.disablePushOff === undefined) {
|
|
564
|
+
this.disablePushOff = false;
|
|
563
565
|
} else {
|
|
564
|
-
this.
|
|
566
|
+
this.disablePushOff = device.disablePushOff;
|
|
565
567
|
}
|
|
566
568
|
}
|
|
567
569
|
|
|
@@ -655,6 +657,8 @@ export class AirConditioner {
|
|
|
655
657
|
async context(): Promise<void> {
|
|
656
658
|
if (this.Active === undefined) {
|
|
657
659
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
660
|
+
} else if (this.Active) {
|
|
661
|
+
this.Active;
|
|
658
662
|
} else {
|
|
659
663
|
this.Active = this.accessory.context.Active;
|
|
660
664
|
}
|
|
@@ -698,11 +702,11 @@ export class AirConditioner {
|
|
|
698
702
|
if (device.customize !== undefined) {
|
|
699
703
|
config['customize'] = device.customize;
|
|
700
704
|
}
|
|
701
|
-
if (device.
|
|
702
|
-
config['
|
|
705
|
+
if (device.disablePushOn !== undefined) {
|
|
706
|
+
config['disablePushOn'] = device.disablePushOn;
|
|
703
707
|
}
|
|
704
|
-
if (device.
|
|
705
|
-
config['
|
|
708
|
+
if (device.disablePushOff !== undefined) {
|
|
709
|
+
config['disablePushOff'] = device.disablePushOff;
|
|
706
710
|
}
|
|
707
711
|
if (Object.entries(config).length !== 0) {
|
|
708
712
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|