@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.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/README.md +16 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +32 -126
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +3 -5
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +14 -47
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +9 -46
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -56
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +34 -147
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +25 -2
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +75 -5
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +34 -50
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +2 -3
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +3 -5
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +2 -3
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +3 -5
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +3 -5
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +2 -3
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +2 -3
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +2 -3
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +3 -5
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +7 -11
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +2 -3
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +2 -3
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +2 -3
- 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 +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +1 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +4 -0
- package/dist/irdevice/irdevice.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 +2 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +2 -3
- 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/settings.d.ts +3 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +5 -5
- package/src/device/blindtilt.ts +42 -124
- package/src/device/bot.ts +3 -5
- package/src/device/ceilinglight.ts +19 -42
- package/src/device/colorbulb.ts +14 -41
- package/src/device/contact.ts +29 -55
- package/src/device/curtain.ts +43 -140
- package/src/device/device.ts +89 -7
- package/src/device/fan.ts +36 -51
- package/src/device/hub.ts +2 -3
- package/src/device/humidifier.ts +3 -5
- package/src/device/iosensor.ts +2 -3
- package/src/device/lightstrip.ts +3 -5
- package/src/device/lock.ts +3 -5
- package/src/device/meter.ts +2 -3
- package/src/device/meterplus.ts +2 -3
- package/src/device/motion.ts +2 -3
- package/src/device/plug.ts +3 -5
- package/src/device/robotvacuumcleaner.ts +7 -11
- package/src/device/waterdetector.ts +2 -3
- package/src/irdevice/airconditioner.ts +2 -3
- package/src/irdevice/airpurifier.ts +2 -3
- package/src/irdevice/camera.ts +2 -3
- package/src/irdevice/fan.ts +2 -3
- package/src/irdevice/irdevice.ts +5 -0
- package/src/irdevice/light.ts +2 -3
- package/src/irdevice/other.ts +2 -3
- package/src/irdevice/tv.ts +2 -3
- package/src/irdevice/vacuumcleaner.ts +2 -3
- package/src/irdevice/waterheater.ts +2 -3
- package/src/settings.ts +3 -2
package/src/device/curtain.ts
CHANGED
|
@@ -336,75 +336,48 @@ export class Curtain extends deviceBase {
|
|
|
336
336
|
const set_maxLux = this.device.curtain?.set_maxLux ?? 6001;
|
|
337
337
|
const spaceBetweenLevels = 9;
|
|
338
338
|
|
|
339
|
-
serviceData.lightLevel = 1;
|
|
340
339
|
// Brightness
|
|
341
340
|
switch (serviceData.lightLevel) {
|
|
342
341
|
case 1:
|
|
343
|
-
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * (serviceData.lightLevel === 1
|
|
344
|
-
? set_minLux : 2);
|
|
345
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} 1 LightLevel: ${serviceData.lightLevel},`
|
|
346
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
347
342
|
this.LightSensor!.CurrentAmbientLightLevel = set_minLux;
|
|
348
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
349
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
343
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
350
344
|
break;
|
|
351
345
|
case 2:
|
|
352
|
-
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * (Number(serviceData.lightLevel) - 1);
|
|
353
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} 1 LightLevel: ${serviceData.lightLevel},`
|
|
354
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
355
346
|
this.LightSensor!.CurrentAmbientLightLevel = (set_maxLux - set_minLux) / spaceBetweenLevels;
|
|
356
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
357
|
-
+ `
|
|
358
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} 3 LightLevel: ${serviceData.lightLevel},`
|
|
359
|
-
+ ` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
347
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},`
|
|
348
|
+
+ ` Calculation: ${(set_maxLux - set_minLux) / spaceBetweenLevels}`);
|
|
360
349
|
break;
|
|
361
350
|
case 3:
|
|
362
|
-
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * (Number(serviceData.lightLevel) - 1);
|
|
363
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} 1 LightLevel: ${serviceData.lightLevel},`
|
|
364
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
365
351
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 2;
|
|
366
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
367
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
368
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
352
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
369
353
|
break;
|
|
370
354
|
case 4:
|
|
371
355
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 3;
|
|
372
356
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
373
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
374
357
|
break;
|
|
375
358
|
case 5:
|
|
376
359
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 4;
|
|
377
360
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
378
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
379
361
|
break;
|
|
380
362
|
case 6:
|
|
381
363
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 5;
|
|
382
364
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
383
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
384
365
|
break;
|
|
385
366
|
case 7:
|
|
386
367
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 6;
|
|
387
368
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
388
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
389
369
|
break;
|
|
390
370
|
case 8:
|
|
391
371
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 7;
|
|
392
372
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
393
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
394
373
|
break;
|
|
395
374
|
case 9:
|
|
396
375
|
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * 8;
|
|
397
376
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel}`);
|
|
398
|
-
this.Battery.ChargingState = this.hap.Characteristic.ChargingState.CHARGING;
|
|
399
377
|
break;
|
|
400
378
|
case 10:
|
|
401
379
|
default:
|
|
402
|
-
this.LightSensor!.CurrentAmbientLightLevel = ((set_maxLux - set_minLux) / spaceBetweenLevels) * (Number(serviceData.lightLevel) - 1);
|
|
403
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} 1 LightLevel: ${serviceData.lightLevel},`
|
|
404
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
405
380
|
this.LightSensor!.CurrentAmbientLightLevel = set_maxLux;
|
|
406
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} 2 LightLevel: ${serviceData.lightLevel},`
|
|
407
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
408
381
|
this.debugLog();
|
|
409
382
|
}
|
|
410
383
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${serviceData.lightLevel},`
|
|
@@ -559,9 +532,8 @@ export class Curtain extends deviceBase {
|
|
|
559
532
|
await this.statusCodes(statusCode, deviceStatus);
|
|
560
533
|
}
|
|
561
534
|
} catch (e: any) {
|
|
562
|
-
this.apiError(e);
|
|
563
|
-
this.
|
|
564
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
535
|
+
await this.apiError(e);
|
|
536
|
+
await this.openAPIRefreshError(e);
|
|
565
537
|
}
|
|
566
538
|
}
|
|
567
539
|
|
|
@@ -596,8 +568,7 @@ export class Curtain extends deviceBase {
|
|
|
596
568
|
await this.openAPIpushChanges();
|
|
597
569
|
} else {
|
|
598
570
|
await this.offlineOff();
|
|
599
|
-
this.
|
|
600
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
571
|
+
await this.pushChangeDisabled();
|
|
601
572
|
}
|
|
602
573
|
// Refresh the status from the API
|
|
603
574
|
interval(15000)
|
|
@@ -714,26 +685,27 @@ export class Curtain extends deviceBase {
|
|
|
714
685
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition);
|
|
715
686
|
|
|
716
687
|
this.WindowCovering.TargetPosition = value;
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
688
|
+
await this.mqtt('TargetPosition', this.WindowCovering.TargetPosition);
|
|
689
|
+
await this.mqtt('HoldPosition', this.WindowCovering.HoldPosition);
|
|
690
|
+
await this.startUpdatingCurtainIfNeeded();
|
|
691
|
+
}
|
|
721
692
|
|
|
693
|
+
async startUpdatingCurtainIfNeeded() {
|
|
722
694
|
await this.setMinMax();
|
|
723
|
-
if (
|
|
695
|
+
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
724
696
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
725
697
|
this.setNewTarget = true;
|
|
726
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${
|
|
698
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.TargetPosition},`
|
|
727
699
|
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
728
|
-
} else if (
|
|
700
|
+
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
729
701
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
730
702
|
this.setNewTarget = true;
|
|
731
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${
|
|
703
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.TargetPosition},`
|
|
732
704
|
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
733
705
|
} else {
|
|
734
706
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
735
707
|
this.setNewTarget = false;
|
|
736
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${
|
|
708
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${this.WindowCovering.TargetPosition},`
|
|
737
709
|
+ ` CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
738
710
|
}
|
|
739
711
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
@@ -765,102 +737,33 @@ export class Curtain extends deviceBase {
|
|
|
765
737
|
|
|
766
738
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
767
739
|
await this.setMinMax();
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
this.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
this.accessory.context.PositionState = this.WindowCovering.PositionState;
|
|
786
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.WindowCovering.PositionState));
|
|
787
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
788
|
-
+ ` PositionState: ${this.WindowCovering.PositionState}`);
|
|
789
|
-
}
|
|
790
|
-
if (this.WindowCovering.TargetPosition === undefined || Number.isNaN(this.WindowCovering.TargetPosition)) {
|
|
791
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
792
|
-
} else {
|
|
793
|
-
if (this.device.mqttURL) {
|
|
794
|
-
this.mqttPublish('TargetPosition', this.WindowCovering.TargetPosition.toString());
|
|
795
|
-
}
|
|
796
|
-
this.accessory.context.TargetPosition = this.WindowCovering.TargetPosition;
|
|
797
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.WindowCovering.TargetPosition));
|
|
798
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
799
|
-
+ ` TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
800
|
-
}
|
|
801
|
-
if (this.WindowCovering.HoldPosition === undefined) {
|
|
802
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} HoldPosition: ${this.WindowCovering.HoldPosition}`);
|
|
803
|
-
} else {
|
|
804
|
-
if (this.device.mqttURL) {
|
|
805
|
-
this.mqttPublish('HoldPosition', this.WindowCovering.HoldPosition.toString());
|
|
806
|
-
}
|
|
807
|
-
this.accessory.context.HoldPosition = this.WindowCovering.HoldPosition;
|
|
808
|
-
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.WindowCovering.HoldPosition);
|
|
809
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
810
|
-
+ ` HoldPosition: ${this.WindowCovering.HoldPosition}`);
|
|
811
|
-
}
|
|
812
|
-
if (!this.device.curtain?.hide_lightsensor) {
|
|
813
|
-
if (this.LightSensor!.CurrentAmbientLightLevel === undefined || Number.isNaN(this.LightSensor!.CurrentAmbientLightLevel)) {
|
|
814
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
815
|
-
+ ` CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
816
|
-
} else {
|
|
817
|
-
if (this.device.mqttURL) {
|
|
818
|
-
this.mqttPublish('CurrentAmbientLightLevel', this.LightSensor!.CurrentAmbientLightLevel.toString());
|
|
819
|
-
}
|
|
820
|
-
this.accessory.context.CurrentAmbientLightLevel = this.LightSensor!.CurrentAmbientLightLevel;
|
|
821
|
-
this.LightSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor!.CurrentAmbientLightLevel);
|
|
822
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
823
|
-
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`);
|
|
824
|
-
if (this.device.history) {
|
|
825
|
-
this.historyService?.addEntry({
|
|
826
|
-
time: Math.round(new Date().valueOf() / 1000),
|
|
827
|
-
lux: this.LightSensor!.CurrentAmbientLightLevel,
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
833
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
834
|
-
} else {
|
|
835
|
-
if (this.device.mqttURL) {
|
|
836
|
-
this.mqttPublish('BatteryLevel', this.Battery.BatteryLevel.toString());
|
|
837
|
-
}
|
|
838
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
839
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
840
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
841
|
-
}
|
|
842
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
843
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
844
|
-
} else {
|
|
845
|
-
if (this.device.mqttURL) {
|
|
846
|
-
this.mqttPublish('StatusLowBattery', this.Battery.StatusLowBattery.toString());
|
|
847
|
-
}
|
|
848
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
849
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
850
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
851
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
852
|
-
}
|
|
853
|
-
if (this.Battery.ChargingState === undefined) {
|
|
854
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
|
|
855
|
-
} else {
|
|
856
|
-
if (this.device.mqttURL) {
|
|
857
|
-
this.mqttPublish('ChargingState', this.Battery.ChargingState.toString());
|
|
858
|
-
}
|
|
859
|
-
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
860
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
861
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
862
|
-
+ ` ChargingState: ${this.Battery.ChargingState}`);
|
|
740
|
+
// CurrentPosition
|
|
741
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.CurrentPosition,
|
|
742
|
+
this.WindowCovering.CurrentPosition, 'CurrentPosition');
|
|
743
|
+
// PositionState
|
|
744
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.PositionState,
|
|
745
|
+
this.WindowCovering.PositionState, 'PositionState');
|
|
746
|
+
// TargetPosition
|
|
747
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.TargetPosition,
|
|
748
|
+
this.WindowCovering.TargetPosition, 'TargetPosition');
|
|
749
|
+
// HoldPosition
|
|
750
|
+
await this.updateCharacteristic(this.WindowCovering.Service, this.hap.Characteristic.HoldPosition,
|
|
751
|
+
this.WindowCovering.HoldPosition, 'HoldPosition');
|
|
752
|
+
// CurrentAmbientLightLevel
|
|
753
|
+
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
|
|
754
|
+
const history = { time: Math.round(new Date().valueOf() / 1000), lux: this.LightSensor.CurrentAmbientLightLevel };
|
|
755
|
+
await this.updateCharacteristic(this.LightSensor?.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
|
|
756
|
+
this.LightSensor?.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel', history);
|
|
863
757
|
}
|
|
758
|
+
// BatteryLevel
|
|
759
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
760
|
+
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
761
|
+
// StatusLowBattery
|
|
762
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
763
|
+
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
764
|
+
// ChargingState
|
|
765
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
|
|
766
|
+
this.Battery.ChargingState, 'ChargingState');
|
|
864
767
|
}
|
|
865
768
|
|
|
866
769
|
async BLEPushConnection() {
|
package/src/device/device.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { BlindTiltMappingMode, SwitchBotModel, SwitchBotBLEModel, SwitchBotBLEMo
|
|
|
11
11
|
|
|
12
12
|
import type { MqttClient } from 'mqtt';
|
|
13
13
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
14
|
-
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
|
|
14
|
+
import type { API, CharacteristicValue, HAP, Logging, PlatformAccessory, Service } from 'homebridge';
|
|
15
15
|
import type { ad, device, serviceData, SwitchBotPlatformConfig, devicesConfig, deviceStatus } from '../settings.js';
|
|
16
16
|
|
|
17
17
|
export abstract class deviceBase {
|
|
@@ -384,6 +384,7 @@ export abstract class deviceBase {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
async monitorAdvertisementPackets(switchbot: any) {
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Scanning for ${this.device.bleModelName} devices...`);
|
|
387
388
|
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
388
389
|
// Set an event handler
|
|
389
390
|
let serviceData: serviceData = { model: this.device.bleModel, modelName: this.device.bleModelName } as serviceData;
|
|
@@ -423,6 +424,32 @@ export abstract class deviceBase {
|
|
|
423
424
|
}
|
|
424
425
|
}
|
|
425
426
|
|
|
427
|
+
async successfulPushChange_BLE(Characteristic: string, CharacteristicValue: CharacteristicValue, Connection: string) {
|
|
428
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} ${Characteristic}: ${CharacteristicValue}`
|
|
429
|
+
+ ` sent over ${Connection}, sent successfully`);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: string) {
|
|
433
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode} & deviceStatus`
|
|
434
|
+
+ ` StatusCode: ${deviceStatus.statusCode}`);
|
|
435
|
+
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} request to SwitchBot API,`
|
|
436
|
+
+ ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async failedBLEChanges(e: Error): Promise<void> {
|
|
440
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
441
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async bodyChange(bodyChange: string, Connection: string) {
|
|
445
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to ${Connection}, body: ${bodyChange},`);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
async pushChangeDisabled() {
|
|
449
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
450
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
451
|
+
}
|
|
452
|
+
|
|
426
453
|
async pushChangeRequest(bodyChange: string): Promise<{ body: any; statusCode: any; }> {
|
|
427
454
|
return await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
428
455
|
body: bodyChange,
|
|
@@ -431,16 +458,28 @@ export abstract class deviceBase {
|
|
|
431
458
|
});
|
|
432
459
|
}
|
|
433
460
|
|
|
434
|
-
async
|
|
435
|
-
this.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
461
|
+
async pushChange(pushChange: string) {
|
|
462
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${pushChange}`);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
async pushChangeError(Change: string, e: Error) {
|
|
466
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed ${Change} with ${this.device.connectionType}`
|
|
467
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
async noChanges(Change: string, CharacteristicValue: CharacteristicValue, CharacteristicValueCached: CharacteristicValue) {
|
|
471
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, ${Change}: ${CharacteristicValue}, `
|
|
472
|
+
+ `${Change}Cached: ${CharacteristicValueCached}`);
|
|
439
473
|
}
|
|
440
474
|
|
|
441
475
|
async successfulRefreshStatus(statusCode: any, deviceStatus: any) {
|
|
442
476
|
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
443
|
-
|
|
477
|
+
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async openAPIRefreshError(e: Error) {
|
|
481
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
482
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
444
483
|
}
|
|
445
484
|
|
|
446
485
|
async statusCodes(statusCode: any, deviceStatus: any) {
|
|
@@ -466,6 +505,49 @@ export abstract class deviceBase {
|
|
|
466
505
|
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
467
506
|
}
|
|
468
507
|
|
|
508
|
+
/**
|
|
509
|
+
* Update the characteristic value and log the change.
|
|
510
|
+
* params: Service, Characteristic, CharacteristicValue, CharacteristicName, history
|
|
511
|
+
* @param Service: Service
|
|
512
|
+
* @param Characteristic: Characteristic
|
|
513
|
+
* @param CharacteristicValue: CharacteristicValue | undefined
|
|
514
|
+
* @param CharacteristicName: string
|
|
515
|
+
* @param history: object
|
|
516
|
+
* @return: void
|
|
517
|
+
*
|
|
518
|
+
*/
|
|
519
|
+
async updateCharacteristic(Service: Service, Characteristic: any,
|
|
520
|
+
CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string, history?: object): Promise<void> {
|
|
521
|
+
if (CharacteristicValue === undefined) {
|
|
522
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${CharacteristicName}: ${CharacteristicValue}`);
|
|
523
|
+
} else {
|
|
524
|
+
await this.mqtt(CharacteristicName, CharacteristicValue);
|
|
525
|
+
if (this.device.history) {
|
|
526
|
+
this.historyService?.addEntry(history);
|
|
527
|
+
}
|
|
528
|
+
Service.updateCharacteristic(Characteristic, CharacteristicValue);
|
|
529
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
530
|
+
+ ` ${CharacteristicName}: ${CharacteristicValue}`);
|
|
531
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} context before: ${this.accessory.context[CharacteristicName]}`);
|
|
532
|
+
this.accessory.context[CharacteristicName] = CharacteristicValue;
|
|
533
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} context after: ${this.accessory.context[CharacteristicName]}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async mqtt(CharacteristicName: string, CharacteristicValue: CharacteristicValue) {
|
|
538
|
+
if (this.device.mqttURL) {
|
|
539
|
+
this.mqttPublish(CharacteristicName, CharacteristicValue.toString());
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
async noChangeSet(value: CharacteristicValue, CharacteristicName: string) {
|
|
544
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ${CharacteristicName}: ${value}`);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
async changeSet(value: CharacteristicValue, CharacteristicName: string) {
|
|
548
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ${CharacteristicName}: ${value}`);
|
|
549
|
+
}
|
|
550
|
+
|
|
469
551
|
async getDeviceContext(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
|
|
470
552
|
// Set the accessory context
|
|
471
553
|
switch (device.deviceType) {
|
package/src/device/fan.ts
CHANGED
|
@@ -265,9 +265,9 @@ export class Fan extends deviceBase {
|
|
|
265
265
|
if (switchbot === undefined) {
|
|
266
266
|
await this.BLERefreshConnection(switchbot);
|
|
267
267
|
} else {
|
|
268
|
-
// Start to monitor advertisement packets
|
|
269
|
-
(async () => {
|
|
270
268
|
// Start to monitor advertisement packets
|
|
269
|
+
(async () => {
|
|
270
|
+
// Start to monitor advertisement packets
|
|
271
271
|
const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
272
272
|
// Update HomeKit
|
|
273
273
|
if (serviceData.model !== '' && serviceData.modelName !== '') {
|
|
@@ -295,9 +295,8 @@ export class Fan extends deviceBase {
|
|
|
295
295
|
await this.statusCodes(statusCode, deviceStatus);
|
|
296
296
|
}
|
|
297
297
|
} catch (e: any) {
|
|
298
|
-
this.apiError(e);
|
|
299
|
-
this.
|
|
300
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
298
|
+
await this.apiError(e);
|
|
299
|
+
await this.openAPIRefreshError(e);
|
|
301
300
|
}
|
|
302
301
|
}
|
|
303
302
|
|
|
@@ -370,8 +369,7 @@ export class Fan extends deviceBase {
|
|
|
370
369
|
await this.openAPIpushChanges();
|
|
371
370
|
} else {
|
|
372
371
|
await this.offlineOff();
|
|
373
|
-
this.
|
|
374
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
372
|
+
await this.pushChangeDisabled();
|
|
375
373
|
}
|
|
376
374
|
// Refresh the status from the API
|
|
377
375
|
interval(15000)
|
|
@@ -405,16 +403,13 @@ export class Fan extends deviceBase {
|
|
|
405
403
|
},
|
|
406
404
|
});
|
|
407
405
|
})
|
|
408
|
-
.then(() => {
|
|
409
|
-
this.
|
|
410
|
-
this.
|
|
411
|
-
+ `Active: ${this.Fan.Active} sent over BLE, sent successfully`);
|
|
412
|
-
this.Fan.Active = false;
|
|
406
|
+
.then(async () => {
|
|
407
|
+
await this.successfulPushChange_BLE('Active', this.Fan.Active, 'BLE API');
|
|
408
|
+
await this.updateHomeKitCharacteristics();
|
|
413
409
|
})
|
|
414
410
|
.catch(async (e: any) => {
|
|
415
|
-
this.apiError(e);
|
|
416
|
-
this.
|
|
417
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
411
|
+
await this.apiError(e);
|
|
412
|
+
await this.pushChangeError('BLEpushChanges', e);
|
|
418
413
|
await this.BLEPushConnection();
|
|
419
414
|
});
|
|
420
415
|
} else {
|
|
@@ -451,8 +446,7 @@ export class Fan extends deviceBase {
|
|
|
451
446
|
}
|
|
452
447
|
} catch (e: any) {
|
|
453
448
|
this.apiError(e);
|
|
454
|
-
this.
|
|
455
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
449
|
+
await this.pushChangeError('openAPIpushChanges', e);
|
|
456
450
|
}
|
|
457
451
|
} else {
|
|
458
452
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.`
|
|
@@ -469,14 +463,14 @@ export class Fan extends deviceBase {
|
|
|
469
463
|
}
|
|
470
464
|
|
|
471
465
|
async pushRotationSpeedChanges(): Promise<void> {
|
|
472
|
-
this.
|
|
466
|
+
await this.pushChange('pushRotationSpeedChanges');
|
|
473
467
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
474
468
|
const bodyChange = JSON.stringify({
|
|
475
469
|
command: 'setWindSpeed',
|
|
476
470
|
parameter: `${this.Fan.RotationSpeed}`,
|
|
477
471
|
commandType: 'command',
|
|
478
472
|
});
|
|
479
|
-
this.
|
|
473
|
+
await this.bodyChange(bodyChange, 'SwitchBot OpenAPI');
|
|
480
474
|
try {
|
|
481
475
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
482
476
|
const deviceStatus: any = await body.json();
|
|
@@ -490,30 +484,23 @@ export class Fan extends deviceBase {
|
|
|
490
484
|
}
|
|
491
485
|
} catch (e: any) {
|
|
492
486
|
this.apiError(e);
|
|
493
|
-
this.
|
|
494
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
487
|
+
await this.pushChangeError('pushRotationSpeedChanges', e);
|
|
495
488
|
}
|
|
496
489
|
} else {
|
|
497
|
-
this.
|
|
498
|
-
+ `pushRotationSpeedChangesCached: ${this.accessory.context.RotationSpeed}`);
|
|
490
|
+
await this.noChanges('RotationSpeed', this.Fan.RotationSpeed, this.accessory.context.RotationSpeed);
|
|
499
491
|
}
|
|
500
492
|
}
|
|
501
493
|
|
|
502
494
|
async pushSwingModeChanges(): Promise<void> {
|
|
503
|
-
this.
|
|
495
|
+
await this.pushChange('pushSwingModeChanges');
|
|
504
496
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
505
|
-
|
|
506
|
-
if (this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED) {
|
|
507
|
-
parameter = 'on';
|
|
508
|
-
} else {
|
|
509
|
-
parameter = 'off';
|
|
510
|
-
}
|
|
497
|
+
const parameter = this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED ? 'on' : 'off';
|
|
511
498
|
const bodyChange = JSON.stringify({
|
|
512
499
|
command: 'setOscillation',
|
|
513
500
|
parameter: `${parameter}`,
|
|
514
501
|
commandType: 'command',
|
|
515
502
|
});
|
|
516
|
-
this.
|
|
503
|
+
await this.bodyChange(bodyChange, 'SwitchBot OpenAPI');
|
|
517
504
|
try {
|
|
518
505
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
519
506
|
const deviceStatus: any = await body.json();
|
|
@@ -527,12 +514,10 @@ export class Fan extends deviceBase {
|
|
|
527
514
|
}
|
|
528
515
|
} catch (e: any) {
|
|
529
516
|
this.apiError(e);
|
|
530
|
-
this.
|
|
531
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
517
|
+
await this.pushChangeError('pushSwingModeChanges', e);
|
|
532
518
|
}
|
|
533
519
|
} else {
|
|
534
|
-
this.
|
|
535
|
-
+ `SwingModeCached: ${this.accessory.context.SwingMode}`);
|
|
520
|
+
await this.noChanges('SwingMode', this.Fan.SwingMode, this.accessory.context.SwingMode);
|
|
536
521
|
}
|
|
537
522
|
}
|
|
538
523
|
|
|
@@ -540,10 +525,10 @@ export class Fan extends deviceBase {
|
|
|
540
525
|
* Handle requests to set the value of the "On" characteristic
|
|
541
526
|
*/
|
|
542
527
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
543
|
-
if (this.Fan.Active
|
|
544
|
-
this.
|
|
528
|
+
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
529
|
+
await this.changeSet(value, 'Active');
|
|
545
530
|
} else {
|
|
546
|
-
this.
|
|
531
|
+
await this.noChangeSet(value, 'Active');
|
|
547
532
|
}
|
|
548
533
|
|
|
549
534
|
this.Fan.Active = value;
|
|
@@ -554,10 +539,10 @@ export class Fan extends deviceBase {
|
|
|
554
539
|
* Handle requests to set the value of the "On" characteristic
|
|
555
540
|
*/
|
|
556
541
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
557
|
-
if (this.Fan.RotationSpeed
|
|
558
|
-
this.
|
|
542
|
+
if (this.Fan.RotationSpeed !== this.accessory.context.RotationSpeed) {
|
|
543
|
+
await this.changeSet(value, 'RotationSpeed');
|
|
559
544
|
} else {
|
|
560
|
-
this.
|
|
545
|
+
await this.noChangeSet(value, 'RotationSpeed');
|
|
561
546
|
}
|
|
562
547
|
|
|
563
548
|
this.Fan.RotationSpeed = value;
|
|
@@ -568,10 +553,10 @@ export class Fan extends deviceBase {
|
|
|
568
553
|
* Handle requests to set the value of the "On" characteristic
|
|
569
554
|
*/
|
|
570
555
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
571
|
-
if (this.Fan.SwingMode
|
|
572
|
-
this.
|
|
556
|
+
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
557
|
+
await this.changeSet(value, 'SwingMode');
|
|
573
558
|
} else {
|
|
574
|
-
this.
|
|
559
|
+
await this.noChangeSet(value, 'SwingMode');
|
|
575
560
|
}
|
|
576
561
|
|
|
577
562
|
this.Fan.SwingMode = value;
|
|
@@ -582,10 +567,10 @@ export class Fan extends deviceBase {
|
|
|
582
567
|
* Handle requests to set the value of the "On" characteristic
|
|
583
568
|
*/
|
|
584
569
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
585
|
-
if (this.LightBulb.On
|
|
586
|
-
this.
|
|
570
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
571
|
+
await this.changeSet(value, 'On');
|
|
587
572
|
} else {
|
|
588
|
-
this.
|
|
573
|
+
await this.noChangeSet(value, 'On');
|
|
589
574
|
}
|
|
590
575
|
|
|
591
576
|
this.LightBulb.On = value;
|
|
@@ -596,12 +581,12 @@ export class Fan extends deviceBase {
|
|
|
596
581
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
597
582
|
*/
|
|
598
583
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
599
|
-
if (this.LightBulb.Brightness
|
|
600
|
-
this.
|
|
584
|
+
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
585
|
+
await this.changeSet(value, 'Brightness');
|
|
601
586
|
} else if (this.LightBulb.On) {
|
|
602
|
-
this.
|
|
587
|
+
await this.changeSet(value, 'Brightness');
|
|
603
588
|
} else {
|
|
604
|
-
this.
|
|
589
|
+
await this.noChangeSet(value, 'Brightness');
|
|
605
590
|
}
|
|
606
591
|
|
|
607
592
|
this.LightBulb.Brightness = value;
|
package/src/device/hub.ts
CHANGED
|
@@ -256,9 +256,8 @@ export class Hub extends deviceBase {
|
|
|
256
256
|
await this.statusCodes(statusCode, deviceStatus);
|
|
257
257
|
}
|
|
258
258
|
} catch (e: any) {
|
|
259
|
-
this.apiError(e);
|
|
260
|
-
this.
|
|
261
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
259
|
+
await this.apiError(e);
|
|
260
|
+
await this.openAPIRefreshError(e);
|
|
262
261
|
}
|
|
263
262
|
}
|
|
264
263
|
|
package/src/device/humidifier.ts
CHANGED
|
@@ -314,9 +314,8 @@ export class Humidifier extends deviceBase {
|
|
|
314
314
|
await this.statusCodes(statusCode, deviceStatus);
|
|
315
315
|
}
|
|
316
316
|
} catch (e: any) {
|
|
317
|
-
this.apiError(e);
|
|
318
|
-
this.
|
|
319
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
317
|
+
await this.apiError(e);
|
|
318
|
+
await this.openAPIRefreshError(e);
|
|
320
319
|
}
|
|
321
320
|
}
|
|
322
321
|
|
|
@@ -356,8 +355,7 @@ export class Humidifier extends deviceBase {
|
|
|
356
355
|
await this.openAPIpushChanges();
|
|
357
356
|
} else {
|
|
358
357
|
await this.offlineOff();
|
|
359
|
-
this.
|
|
360
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
358
|
+
await this.pushChangeDisabled();
|
|
361
359
|
}
|
|
362
360
|
// Refresh the status from the API
|
|
363
361
|
interval(15000)
|