@switchbot/homebridge-switchbot 2.2.0-beta.2 → 2.2.0-beta.4
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/dist/device/bot.d.ts +3 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +5 -5
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.js +79 -77
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +3 -3
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +2 -2
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.js +2 -2
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +8 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +83 -0
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +2 -2
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +2 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +3 -3
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +2 -2
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.js +2 -2
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +16 -28
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +4 -5
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -3
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +11 -10
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +2 -3
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +11 -12
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -3
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +1 -9
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +5 -7
- package/src/device/colorbulb.ts +74 -74
- package/src/device/contact.ts +3 -3
- package/src/device/curtain.ts +2 -2
- package/src/device/humidifier.ts +2 -2
- package/src/device/lock.ts +92 -1
- package/src/device/meter.ts +2 -2
- package/src/device/meterplus.ts +2 -2
- package/src/device/motion.ts +3 -3
- package/src/device/plug.ts +2 -2
- package/src/device/striplight.ts +2 -2
- package/src/irdevice/airconditioner.ts +20 -37
- package/src/irdevice/airpurifier.ts +4 -5
- package/src/irdevice/camera.ts +3 -4
- package/src/irdevice/fan.ts +11 -10
- package/src/irdevice/light.ts +2 -3
- package/src/irdevice/other.ts +1 -1
- package/src/irdevice/tv.ts +11 -12
- package/src/irdevice/vacuumcleaner.ts +2 -3
- package/src/irdevice/waterheater.ts +2 -3
- package/src/platform.ts +1 -9
package/src/device/lock.ts
CHANGED
|
@@ -7,7 +7,7 @@ import superStringify from 'super-stringify';
|
|
|
7
7
|
import { SwitchBotPlatform } from '../platform';
|
|
8
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
9
9
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, deviceStatus, HostDomain, DevicePath } from '../settings';
|
|
10
|
+
import { device, devicesConfig, deviceStatus, HostDomain, DevicePath, switchbot, ad, serviceData } from '../settings';
|
|
11
11
|
|
|
12
12
|
export class Lock {
|
|
13
13
|
// Services
|
|
@@ -24,6 +24,12 @@ export class Lock {
|
|
|
24
24
|
lockState!: deviceStatus['lockState'];
|
|
25
25
|
deviceStatus!: any; //deviceStatusResponse;
|
|
26
26
|
|
|
27
|
+
// BLE Others
|
|
28
|
+
connected?: boolean;
|
|
29
|
+
switchbot!: switchbot;
|
|
30
|
+
address!: ad['address'];
|
|
31
|
+
serviceData!: serviceData;
|
|
32
|
+
|
|
27
33
|
// Config
|
|
28
34
|
scanDuration!: number;
|
|
29
35
|
deviceLogging!: string;
|
|
@@ -206,6 +212,63 @@ export class Lock {
|
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
214
|
|
|
215
|
+
async BLERefreshStatus(): Promise<void> {
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
217
|
+
const switchbot = await this.platform.connectBLE();
|
|
218
|
+
// Convert to BLE Address
|
|
219
|
+
this.device.bleMac = this.device
|
|
220
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
221
|
+
.join(':')
|
|
222
|
+
.toLowerCase();
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
224
|
+
this.getCustomBLEAddress(switchbot);
|
|
225
|
+
// Start to monitor advertisement packets
|
|
226
|
+
if (switchbot !== false) {
|
|
227
|
+
switchbot
|
|
228
|
+
.startScan({
|
|
229
|
+
model: 'o',
|
|
230
|
+
id: this.device.bleMac,
|
|
231
|
+
})
|
|
232
|
+
.then(() => {
|
|
233
|
+
// Set an event hander
|
|
234
|
+
switchbot.onadvertisement = async (ad: any) => {
|
|
235
|
+
this.address = ad.address;
|
|
236
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
237
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
238
|
+
this.serviceData = ad.serviceData;
|
|
239
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
240
|
+
this.debugLog(
|
|
241
|
+
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
242
|
+
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
|
|
243
|
+
`inMotion: ${ad.serviceData.inMotion}`);
|
|
244
|
+
|
|
245
|
+
if (this.serviceData) {
|
|
246
|
+
this.connected = true;
|
|
247
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
248
|
+
await this.stopScanning(switchbot);
|
|
249
|
+
} else {
|
|
250
|
+
this.connected = false;
|
|
251
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
// Wait 2 seconds
|
|
255
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
256
|
+
})
|
|
257
|
+
.then(async () => {
|
|
258
|
+
// Stop to monitor
|
|
259
|
+
await this.stopScanning(switchbot);
|
|
260
|
+
})
|
|
261
|
+
.catch(async (e: any) => {
|
|
262
|
+
this.apiError(e);
|
|
263
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
264
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
265
|
+
await this.BLERefreshConnection(switchbot);
|
|
266
|
+
});
|
|
267
|
+
} else {
|
|
268
|
+
await this.BLERefreshConnection(switchbot);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
209
272
|
async openAPIRefreshStatus(): Promise<void> {
|
|
210
273
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
211
274
|
try {
|
|
@@ -427,6 +490,34 @@ export class Lock {
|
|
|
427
490
|
}
|
|
428
491
|
}
|
|
429
492
|
|
|
493
|
+
async stopScanning(switchbot: any) {
|
|
494
|
+
switchbot.stopScan();
|
|
495
|
+
if (this.connected) {
|
|
496
|
+
await this.BLEparseStatus();
|
|
497
|
+
await this.updateHomeKitCharacteristics();
|
|
498
|
+
} else {
|
|
499
|
+
await this.BLERefreshConnection(switchbot);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
async getCustomBLEAddress(switchbot: any) {
|
|
504
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
505
|
+
(async () => {
|
|
506
|
+
// Start to monitor advertisement packets
|
|
507
|
+
await switchbot.startScan({
|
|
508
|
+
model: 'c',
|
|
509
|
+
});
|
|
510
|
+
// Set an event handler
|
|
511
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
512
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
513
|
+
};
|
|
514
|
+
await switchbot.wait(10000);
|
|
515
|
+
// Stop to monitor
|
|
516
|
+
switchbot.stopScan();
|
|
517
|
+
})();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
430
521
|
async BLEPushConnection() {
|
|
431
522
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
432
523
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
package/src/device/meter.ts
CHANGED
|
@@ -491,8 +491,8 @@ export class Meter {
|
|
|
491
491
|
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
492
492
|
switchbot.stopScan();
|
|
493
493
|
if (this.connected) {
|
|
494
|
-
this.BLEparseStatus();
|
|
495
|
-
this.updateHomeKitCharacteristics();
|
|
494
|
+
await this.BLEparseStatus();
|
|
495
|
+
await this.updateHomeKitCharacteristics();
|
|
496
496
|
} else {
|
|
497
497
|
await this.BLERefreshConnection(switchbot);
|
|
498
498
|
}
|
package/src/device/meterplus.ts
CHANGED
|
@@ -490,8 +490,8 @@ export class MeterPlus {
|
|
|
490
490
|
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
491
491
|
switchbot.stopScan();
|
|
492
492
|
if (this.connected) {
|
|
493
|
-
this.BLEparseStatus();
|
|
494
|
-
this.updateHomeKitCharacteristics();
|
|
493
|
+
await this.BLEparseStatus();
|
|
494
|
+
await this.updateHomeKitCharacteristics();
|
|
495
495
|
} else {
|
|
496
496
|
await this.BLERefreshConnection(switchbot);
|
|
497
497
|
}
|
package/src/device/motion.ts
CHANGED
|
@@ -394,11 +394,11 @@ export class Motion {
|
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
async stopScanning(switchbot: any) {
|
|
397
|
+
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
398
398
|
switchbot.stopScan();
|
|
399
399
|
if (this.connected) {
|
|
400
|
-
this.BLEparseStatus();
|
|
401
|
-
this.updateHomeKitCharacteristics();
|
|
400
|
+
await this.BLEparseStatus();
|
|
401
|
+
await this.updateHomeKitCharacteristics();
|
|
402
402
|
} else {
|
|
403
403
|
await this.BLERefreshConnection(switchbot);
|
|
404
404
|
}
|
package/src/device/plug.ts
CHANGED
|
@@ -461,8 +461,8 @@ export class Plug {
|
|
|
461
461
|
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
462
462
|
switchbot.stopScan();
|
|
463
463
|
if (this.connected) {
|
|
464
|
-
this.BLEparseStatus();
|
|
465
|
-
this.updateHomeKitCharacteristics();
|
|
464
|
+
await this.BLEparseStatus();
|
|
465
|
+
await this.updateHomeKitCharacteristics();
|
|
466
466
|
} else {
|
|
467
467
|
await this.BLERefreshConnection(switchbot);
|
|
468
468
|
}
|
package/src/device/striplight.ts
CHANGED
|
@@ -812,8 +812,8 @@ export class StripLight {
|
|
|
812
812
|
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
813
813
|
switchbot.stopScan();
|
|
814
814
|
if (this.connected) {
|
|
815
|
-
this.BLEparseStatus();
|
|
816
|
-
this.updateHomeKitCharacteristics();
|
|
815
|
+
await this.BLEparseStatus();
|
|
816
|
+
await this.updateHomeKitCharacteristics();
|
|
817
817
|
} else {
|
|
818
818
|
await this.BLERefreshConnection(switchbot);
|
|
819
819
|
}
|
|
@@ -48,7 +48,7 @@ export class AirConditioner {
|
|
|
48
48
|
// default placeholders
|
|
49
49
|
this.logs({ device });
|
|
50
50
|
this.config({ device });
|
|
51
|
-
this.context(
|
|
51
|
+
this.context();
|
|
52
52
|
this.allowPushOnChanges({ device });
|
|
53
53
|
this.allowPushOffChanges({ device });
|
|
54
54
|
|
|
@@ -202,7 +202,7 @@ export class AirConditioner {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
205
|
-
this.
|
|
205
|
+
await this.context();
|
|
206
206
|
if (this.CurrentMode === undefined) {
|
|
207
207
|
this.CurrentMode = 1;
|
|
208
208
|
}
|
|
@@ -224,7 +224,7 @@ export class AirConditioner {
|
|
|
224
224
|
const parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
|
|
225
225
|
|
|
226
226
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
227
|
-
this.
|
|
227
|
+
await this.context();
|
|
228
228
|
if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
|
|
229
229
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
230
230
|
} else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
|
|
@@ -282,11 +282,11 @@ export class AirConditioner {
|
|
|
282
282
|
req.write(body);
|
|
283
283
|
req.end();
|
|
284
284
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
285
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
285
|
+
//this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
286
286
|
this.HeatingThresholdTemperature = this.CurrentTemperature;
|
|
287
287
|
this.CoolingThresholdTemperature = this.CurrentTemperature;
|
|
288
|
-
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
289
|
-
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
288
|
+
//this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
289
|
+
//this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
290
290
|
this.updateHomeKitCharacteristics();
|
|
291
291
|
} catch (e: any) {
|
|
292
292
|
this.apiError({ e });
|
|
@@ -332,7 +332,6 @@ export class AirConditioner {
|
|
|
332
332
|
this.CurrentFanSpeed = Number(value) + 1;
|
|
333
333
|
}
|
|
334
334
|
this.RotationSpeed = this.CurrentFanSpeed;
|
|
335
|
-
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
336
335
|
this.pushAirConditionerStatusChanges();
|
|
337
336
|
}
|
|
338
337
|
|
|
@@ -354,7 +353,6 @@ export class AirConditioner {
|
|
|
354
353
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
355
354
|
*/
|
|
356
355
|
this.Active = value;
|
|
357
|
-
this.accessory.context.Active = this.Active;
|
|
358
356
|
}
|
|
359
357
|
|
|
360
358
|
async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
@@ -407,7 +405,6 @@ export class AirConditioner {
|
|
|
407
405
|
);
|
|
408
406
|
}
|
|
409
407
|
}
|
|
410
|
-
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
411
408
|
this.pushAirConditionerStatusChanges();
|
|
412
409
|
}
|
|
413
410
|
|
|
@@ -434,7 +431,7 @@ export class AirConditioner {
|
|
|
434
431
|
|
|
435
432
|
async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
436
433
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
437
|
-
this.
|
|
434
|
+
await this.context();
|
|
438
435
|
if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
|
|
439
436
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
440
437
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
@@ -454,7 +451,7 @@ export class AirConditioner {
|
|
|
454
451
|
}
|
|
455
452
|
|
|
456
453
|
async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
457
|
-
this.
|
|
454
|
+
await this.context();
|
|
458
455
|
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
459
456
|
this.HeatingThresholdTemperature = this.accessory.context.CurrentTemperature;
|
|
460
457
|
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
@@ -463,18 +460,14 @@ export class AirConditioner {
|
|
|
463
460
|
}
|
|
464
461
|
|
|
465
462
|
async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
466
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
467
463
|
this.CurrentTemperature = value;
|
|
468
|
-
this.accessory.
|
|
469
|
-
|
|
470
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
|
|
471
|
-
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
|
|
472
|
-
);
|
|
464
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
|
|
465
|
+
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`);
|
|
473
466
|
this.pushAirConditionerStatusChanges();
|
|
474
467
|
}
|
|
475
468
|
|
|
476
469
|
async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
477
|
-
this.
|
|
470
|
+
await this.context();
|
|
478
471
|
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
479
472
|
this.CoolingThresholdTemperature = this.accessory.context.CurrentTemperature;
|
|
480
473
|
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
@@ -483,25 +476,12 @@ export class AirConditioner {
|
|
|
483
476
|
}
|
|
484
477
|
|
|
485
478
|
async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
486
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
487
479
|
this.CurrentTemperature = value;
|
|
488
|
-
this.accessory.
|
|
489
|
-
|
|
490
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
|
|
491
|
-
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
|
|
492
|
-
);
|
|
480
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
|
|
481
|
+
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`);
|
|
493
482
|
this.pushAirConditionerStatusChanges();
|
|
494
483
|
}
|
|
495
484
|
|
|
496
|
-
async CurrentTemperatureUndefined(): Promise<void> {
|
|
497
|
-
if (this.CurrentTemperature === undefined) {
|
|
498
|
-
this.CurrentTemperature = 24;
|
|
499
|
-
}
|
|
500
|
-
if (this.accessory.context.CurrentTemperature === undefined) {
|
|
501
|
-
this.CurrentTemperature = 30;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
485
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
506
486
|
if (this.Active === undefined) {
|
|
507
487
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
@@ -668,7 +648,7 @@ export class AirConditioner {
|
|
|
668
648
|
return FirmwareRevision;
|
|
669
649
|
}
|
|
670
650
|
|
|
671
|
-
async context(
|
|
651
|
+
async context(): Promise<void> {
|
|
672
652
|
if (this.Active === undefined) {
|
|
673
653
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
674
654
|
} else {
|
|
@@ -679,11 +659,14 @@ export class AirConditioner {
|
|
|
679
659
|
} else {
|
|
680
660
|
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
681
661
|
}
|
|
682
|
-
if (
|
|
683
|
-
this.
|
|
662
|
+
if (this.accessory.context.CurrentTemperature === undefined) {
|
|
663
|
+
this.CurrentTemperature = 30;
|
|
664
|
+
}
|
|
665
|
+
if (this.device.irair?.hide_automode) {
|
|
666
|
+
this.hide_automode = this.device.irair?.hide_automode;
|
|
684
667
|
this.accessory.context.hide_automode = this.hide_automode;
|
|
685
668
|
} else {
|
|
686
|
-
this.hide_automode = device.irair?.hide_automode;
|
|
669
|
+
this.hide_automode = this.device.irair?.hide_automode;
|
|
687
670
|
this.accessory.context.hide_automode = this.hide_automode;
|
|
688
671
|
}
|
|
689
672
|
}
|
|
@@ -94,7 +94,6 @@ export class AirPurifier {
|
|
|
94
94
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
95
95
|
*/
|
|
96
96
|
this.Active = value;
|
|
97
|
-
this.accessory.context.Active = this.Active;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
@@ -134,7 +133,7 @@ export class AirPurifier {
|
|
|
134
133
|
* AirPurifier: "command" "highSpeed" "default" = fan speed to high
|
|
135
134
|
*/
|
|
136
135
|
async pushAirPurifierOnChanges(): Promise<void> {
|
|
137
|
-
if (this.Active
|
|
136
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
|
|
138
137
|
const commandType: string = await this.commandType();
|
|
139
138
|
const command: string = await this.commandOn();
|
|
140
139
|
const body = superStringify({
|
|
@@ -147,9 +146,9 @@ export class AirPurifier {
|
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
async pushAirPurifierOffChanges(): Promise<void> {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOn) {
|
|
150
|
+
const commandType: string = await this.commandType();
|
|
151
|
+
const command: string = await this.commandOff();
|
|
153
152
|
const body = superStringify({
|
|
154
153
|
'command': command,
|
|
155
154
|
'parameter': 'default',
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -70,7 +70,6 @@ export class Camera {
|
|
|
70
70
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
71
71
|
*/
|
|
72
72
|
this.On = value;
|
|
73
|
-
this.accessory.context.On = this.On;
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
/**
|
|
@@ -84,7 +83,7 @@ export class Camera {
|
|
|
84
83
|
* Camera - "command" "channelSub" "default" = previous channel
|
|
85
84
|
*/
|
|
86
85
|
async pushOnChanges(): Promise<void> {
|
|
87
|
-
if (this.On) {
|
|
86
|
+
if (this.On || this.allowPushOn) {
|
|
88
87
|
const commandType: string = await this.commandType();
|
|
89
88
|
const command: string = await this.commandOn();
|
|
90
89
|
const body = superStringify({
|
|
@@ -99,7 +98,7 @@ export class Camera {
|
|
|
99
98
|
async pushOffChanges(): Promise<void> {
|
|
100
99
|
const commandType: string = await this.commandType();
|
|
101
100
|
const command: string = await this.commandOff();
|
|
102
|
-
if (!this.On) {
|
|
101
|
+
if (!this.On || this.allowPushOff) {
|
|
103
102
|
const body = superStringify({
|
|
104
103
|
'command': command,
|
|
105
104
|
'parameter': 'default',
|
|
@@ -109,7 +108,7 @@ export class Camera {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
|
|
112
|
-
async pushChanges(body): Promise<void> {
|
|
111
|
+
async pushChanges(body: any): Promise<void> {
|
|
113
112
|
if (this.device.connectionType === 'OpenAPI') {
|
|
114
113
|
try {
|
|
115
114
|
// Make Push On request to the API
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -161,7 +161,6 @@ export class Fan {
|
|
|
161
161
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
162
162
|
*/
|
|
163
163
|
this.Active = value;
|
|
164
|
-
this.accessory.context.Active = this.Active;
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
/**
|
|
@@ -174,7 +173,7 @@ export class Fan {
|
|
|
174
173
|
* Fan - "command" "highSpeed" "default" = fan speed to high
|
|
175
174
|
*/
|
|
176
175
|
async pushFanOnChanges(): Promise<void> {
|
|
177
|
-
if (this.Active
|
|
176
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
|
|
178
177
|
const commandType: string = await this.commandType();
|
|
179
178
|
const command: string = await this.commandOn();
|
|
180
179
|
const body = superStringify({
|
|
@@ -187,14 +186,16 @@ export class Fan {
|
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
async pushFanOffChanges(): Promise<void> {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
189
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOff) {
|
|
190
|
+
const commandType: string = await this.commandType();
|
|
191
|
+
const command: string = await this.commandOff();
|
|
192
|
+
const body = superStringify({
|
|
193
|
+
'command': command,
|
|
194
|
+
'parameter': 'default',
|
|
195
|
+
'commandType': commandType,
|
|
196
|
+
});
|
|
197
|
+
await this.pushTVChanges(body);
|
|
198
|
+
}
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
async pushFanSpeedUpChanges(): Promise<void> {
|
package/src/irdevice/light.ts
CHANGED
|
@@ -70,7 +70,6 @@ export class Light {
|
|
|
70
70
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
71
71
|
*/
|
|
72
72
|
this.On = value;
|
|
73
|
-
this.accessory.context.On = this.On;
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
/**
|
|
@@ -84,7 +83,7 @@ export class Light {
|
|
|
84
83
|
* Light - "command" "channelSub" "default" = previous channel
|
|
85
84
|
*/
|
|
86
85
|
async pushLightOnChanges(): Promise<void> {
|
|
87
|
-
if (this.On) {
|
|
86
|
+
if (this.On || this.allowPushOn) {
|
|
88
87
|
const commandType: string = await this.commandType();
|
|
89
88
|
const command: string = await this.commandOn();
|
|
90
89
|
const body = superStringify({
|
|
@@ -97,7 +96,7 @@ export class Light {
|
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
async pushLightOffChanges(): Promise<void> {
|
|
100
|
-
if (!this.On) {
|
|
99
|
+
if (!this.On || this.allowPushOff) {
|
|
101
100
|
const commandType: string = await this.commandType();
|
|
102
101
|
const command: string = await this.commandOff();
|
|
103
102
|
const body = superStringify({
|
package/src/irdevice/other.ts
CHANGED
|
@@ -78,7 +78,6 @@ export class Others {
|
|
|
78
78
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
79
79
|
*/
|
|
80
80
|
this.Active = value;
|
|
81
|
-
this.accessory.context.Active = this.Active;
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
/**
|
|
@@ -182,6 +181,7 @@ export class Others {
|
|
|
182
181
|
if (this.Active === undefined) {
|
|
183
182
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
184
183
|
} else {
|
|
184
|
+
this.accessory.context.Active = this.Active;
|
|
185
185
|
this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
186
186
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
187
187
|
}
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -202,8 +202,6 @@ export class TV {
|
|
|
202
202
|
|
|
203
203
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
204
204
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
205
|
-
this.Active = value;
|
|
206
|
-
this.accessory.context.Active = this.Active;
|
|
207
205
|
if (!this.device.irtv?.disable_power) {
|
|
208
206
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
209
207
|
await this.pushTvOffChanges();
|
|
@@ -215,7 +213,6 @@ export class TV {
|
|
|
215
213
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
216
214
|
*/
|
|
217
215
|
this.Active = value;
|
|
218
|
-
this.accessory.context.Active = this.Active;
|
|
219
216
|
}
|
|
220
217
|
}
|
|
221
218
|
|
|
@@ -230,7 +227,7 @@ export class TV {
|
|
|
230
227
|
* TV "command" "channelSub" "default" previous channel
|
|
231
228
|
*/
|
|
232
229
|
async pushTvOnChanges(): Promise<void> {
|
|
233
|
-
if (this.Active
|
|
230
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
|
|
234
231
|
const commandType: string = await this.commandType();
|
|
235
232
|
const command: string = await this.commandOn();
|
|
236
233
|
const body = superStringify({
|
|
@@ -243,14 +240,16 @@ export class TV {
|
|
|
243
240
|
}
|
|
244
241
|
|
|
245
242
|
async pushTvOffChanges(): Promise<void> {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
243
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOn) {
|
|
244
|
+
const commandType: string = await this.commandType();
|
|
245
|
+
const command: string = await this.commandOff();
|
|
246
|
+
const body = superStringify({
|
|
247
|
+
'command': command,
|
|
248
|
+
'parameter': 'default',
|
|
249
|
+
'commandType': commandType,
|
|
250
|
+
});
|
|
251
|
+
await this.pushTVChanges(body);
|
|
252
|
+
}
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
async pushOkChanges(): Promise<void> {
|
|
@@ -70,7 +70,6 @@ export class VacuumCleaner {
|
|
|
70
70
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
71
71
|
*/
|
|
72
72
|
this.On = value;
|
|
73
|
-
this.accessory.context.On = this.On;
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
/**
|
|
@@ -80,7 +79,7 @@ export class VacuumCleaner {
|
|
|
80
79
|
* Vacuum Cleaner "command" "turnOn" "default" set to ON state
|
|
81
80
|
*/
|
|
82
81
|
async pushOnChanges(): Promise<void> {
|
|
83
|
-
if (this.On) {
|
|
82
|
+
if (this.On || this.allowPushOn) {
|
|
84
83
|
const commandType: string = await this.commandType();
|
|
85
84
|
const command: string = await this.commandOn();
|
|
86
85
|
const body = superStringify({
|
|
@@ -93,7 +92,7 @@ export class VacuumCleaner {
|
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
async pushOffChanges(): Promise<void> {
|
|
96
|
-
if (!this.On) {
|
|
95
|
+
if (!this.On || this.allowPushOff) {
|
|
97
96
|
const commandType: string = await this.commandType();
|
|
98
97
|
const command: string = await this.commandOff();
|
|
99
98
|
const body = superStringify({
|
|
@@ -76,7 +76,6 @@ export class WaterHeater {
|
|
|
76
76
|
* they are updated, so we are only updating the accessory state after calling the above.
|
|
77
77
|
*/
|
|
78
78
|
this.Active = value;
|
|
79
|
-
this.accessory.context.Active = this.Active;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
/**
|
|
@@ -86,7 +85,7 @@ export class WaterHeater {
|
|
|
86
85
|
* WaterHeater "command" "turnOn" "default" set to ON state
|
|
87
86
|
*/
|
|
88
87
|
async pushWaterHeaterOnChanges(): Promise<void> {
|
|
89
|
-
if (this.Active
|
|
88
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
|
|
90
89
|
const commandType: string = await this.commandType();
|
|
91
90
|
const command: string = await this.commandOn();
|
|
92
91
|
const body = superStringify({
|
|
@@ -99,7 +98,7 @@ export class WaterHeater {
|
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
async pushWaterHeaterOffChanges(): Promise<void> {
|
|
102
|
-
if (this.Active
|
|
101
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOff) {
|
|
103
102
|
const commandType: string = await this.commandType();
|
|
104
103
|
const command: string = await this.commandOff();
|
|
105
104
|
const body = superStringify({
|
package/src/platform.ts
CHANGED
|
@@ -261,7 +261,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
261
261
|
const data = this.config.credentials?.token + t + nonce;
|
|
262
262
|
const signTerm = crypto.createHmac('sha256', this.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
263
263
|
const sign = signTerm.toString('base64');
|
|
264
|
-
this.debugLog(sign);
|
|
264
|
+
this.debugLog(`sing: ${sign}`);
|
|
265
265
|
const options = {
|
|
266
266
|
hostname: HostDomain,
|
|
267
267
|
port: 443,
|
|
@@ -339,11 +339,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
339
339
|
} else {
|
|
340
340
|
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
341
341
|
}
|
|
342
|
-
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
343
|
-
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
344
|
-
} else {
|
|
345
|
-
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
346
|
-
}
|
|
347
342
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
348
343
|
if (!this.config.options?.irdevices) {
|
|
349
344
|
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
@@ -605,7 +600,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
605
600
|
// the accessory already exists
|
|
606
601
|
if (await this.registerDevice(device)) {
|
|
607
602
|
|
|
608
|
-
this.debugLog(superStringify(device.bot?.mode));
|
|
609
603
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
610
604
|
existingAccessory.context.model = device.deviceType;
|
|
611
605
|
existingAccessory.context.deviceID = device.deviceId;
|
|
@@ -628,8 +622,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
628
622
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
629
623
|
}
|
|
630
624
|
|
|
631
|
-
this.debugLog(superStringify(device.bot?.mode));
|
|
632
|
-
|
|
633
625
|
// create a new accessory
|
|
634
626
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
635
627
|
|