@switchbot/homebridge-switchbot-ble
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -5,6 +5,6 @@ "use strict"; | ||
class Curtain { | ||
constructor(hap, log, name, bleMac, scanDuration, reverseDir) { | ||
constructor(hap, log, name, bleMac, scanDuration, reverseDir, moveTime) { | ||
this.currentPosition = 0; | ||
this.targetPosition = 0; | ||
this.positionStatus = 0; | ||
this.positionState = 0; | ||
this.log = log; | ||
@@ -15,3 +15,4 @@ this.name = name; | ||
this.reverseDir = reverseDir; | ||
this.positionStatus = 2; | ||
this.moveTime = moveTime; | ||
this.positionState = hap.Characteristic.PositionState.STOPPED; | ||
this.curtainService = new hap.Service.WindowCovering(name); | ||
@@ -22,6 +23,2 @@ this.curtainService.getCharacteristic(hap.Characteristic.CurrentPosition) | ||
callback(undefined, this.currentPosition); | ||
}) | ||
.on("set" /* SET */, (value, callback) => { | ||
log.info("Current position of the Curtain can't be set!"); | ||
callback(); | ||
}); | ||
@@ -34,9 +31,22 @@ this.curtainService.getCharacteristic(hap.Characteristic.TargetPosition) | ||
.on("set" /* SET */, (value, callback) => { | ||
const targetPosition = value; | ||
log.info("Target position of the Curtain setting: " + targetPosition + "%"); | ||
if (targetPosition === this.targetPosition) { | ||
var _a, _b, _c; | ||
this.targetPosition = value; | ||
log.info("Target position of the Curtain setting: " + this.targetPosition + "%"); | ||
clearTimeout(this.moveTimer); | ||
if (this.targetPosition > this.currentPosition) { | ||
this.positionState = hap.Characteristic.PositionState.INCREASING; | ||
} | ||
else if (this.targetPosition < this.currentPosition) { | ||
this.positionState = hap.Characteristic.PositionState.DECREASING; | ||
} | ||
else { | ||
this.positionState = hap.Characteristic.PositionState.STOPPED; | ||
} | ||
if (this.positionState === hap.Characteristic.PositionState.STOPPED) { | ||
(_a = this.curtainService) === null || _a === void 0 ? void 0 : _a.getCharacteristic(hap.Characteristic.TargetPosition).updateValue(this.targetPosition); | ||
(_b = this.curtainService) === null || _b === void 0 ? void 0 : _b.getCharacteristic(hap.Characteristic.CurrentPosition).updateValue(this.currentPosition); | ||
(_c = this.curtainService) === null || _c === void 0 ? void 0 : _c.getCharacteristic(hap.Characteristic.PositionState).updateValue(this.positionState); | ||
callback(); | ||
} | ||
else { | ||
this.targetPosition = targetPosition; | ||
const SwitchBot = require('node-switchbot'); | ||
@@ -86,8 +96,23 @@ const switchbot = new SwitchBot(); | ||
log.info('Done.'); | ||
this.currentPosition = this.targetPosition; | ||
log.info("Target position of the Curtain has been set to: " + this.targetPosition + "%"); | ||
this.moveTimer = setTimeout(() => { | ||
var _a, _b; | ||
// log.info("setTimeout", this.positionState.toString(), this.currentPosition.toString(), this.targetPosition.toString()); | ||
this.currentPosition = this.targetPosition; | ||
this.positionState = hap.Characteristic.PositionState.STOPPED; | ||
// this.curtainService?.getCharacteristic(hap.Characteristic.TargetPosition).updateValue(this.targetPosition); | ||
(_a = this.curtainService) === null || _a === void 0 ? void 0 : _a.getCharacteristic(hap.Characteristic.CurrentPosition).updateValue(this.currentPosition); | ||
(_b = this.curtainService) === null || _b === void 0 ? void 0 : _b.getCharacteristic(hap.Characteristic.PositionState).updateValue(this.positionState); | ||
}, this.moveTime); | ||
callback(); | ||
}).catch((error) => { | ||
log.error(error); | ||
this.targetPosition = this.currentPosition; | ||
this.moveTimer = setTimeout(() => { | ||
var _a, _b; | ||
this.targetPosition = this.currentPosition; | ||
this.positionState = hap.Characteristic.PositionState.STOPPED; | ||
(_a = this.curtainService) === null || _a === void 0 ? void 0 : _a.getCharacteristic(hap.Characteristic.TargetPosition).updateValue(this.targetPosition); | ||
// this.curtainService?.getCharacteristic(hap.Characteristic.CurrentPosition).updateValue(this.currentPosition); | ||
(_b = this.curtainService) === null || _b === void 0 ? void 0 : _b.getCharacteristic(hap.Characteristic.PositionState).updateValue(this.positionState); | ||
}, 1000); | ||
log.info("Target position of the Curtain setting failed!"); | ||
@@ -100,8 +125,4 @@ callback(); | ||
.on("get" /* GET */, (callback) => { | ||
// log.info("The position state of the Curtain was returned: " + this.positionStatus); | ||
callback(undefined, this.positionStatus); | ||
}) | ||
.on("set" /* SET */, (value, callback) => { | ||
log.info("The position state of the Curtain can't be set!"); | ||
callback(); | ||
log.info("The position state of the Curtain was returned: " + this.positionState); | ||
callback(undefined, this.positionState); | ||
}); | ||
@@ -108,0 +129,0 @@ this.informationService = new hap.Service.AccessoryInformation() |
@@ -56,3 +56,4 @@ "use strict"; | ||
const reverseDir = device.reverseDir || false; | ||
deviceList.push(new curtain_accessory_1.Curtain(hap, this.log, device.name, device.bleMac.toLowerCase(), scanDuration, reverseDir)); | ||
const moveTime = device.moveTime || 2000; | ||
deviceList.push(new curtain_accessory_1.Curtain(hap, this.log, device.name, device.bleMac.toLowerCase(), scanDuration, reverseDir, moveTime)); | ||
break; | ||
@@ -59,0 +60,0 @@ case 'meter': |
{ | ||
"name": "@switchbot/homebridge-switchbot-ble", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Homebridge integration for SwitchBot BLE series products", | ||
@@ -36,3 +36,3 @@ "license": "ISC", | ||
"devDependencies": { | ||
"@types/node": "14.14.7", | ||
"@types/node": "14.14.8", | ||
"homebridge": "^1.1.6", | ||
@@ -39,0 +39,0 @@ "rimraf": "^3.0.2", |
@@ -65,3 +65,4 @@ <span align="center"> | ||
"scanDuration": 2000, | ||
"reverseDir": false | ||
"reverseDir": false, | ||
"moveTime": 2000 | ||
}, | ||
@@ -89,2 +90,3 @@ { | ||
* `reverseDir` - Set to `true` to exchange the "opened" and "closed" directions of Curtain after calibration. Default is `false`. So you can swap the directions without recalibration. | ||
* `moveTime` - Set the actual running time of Curtian, which is also the time to switch from running state to opened/closeed state in the Home APP. Default is `2000`(unit: ms). | ||
* `scanInterval` - Scan interval. Currently indicates the cycle of updating the temperature and humidity value of Meter. Default is `60000`(unit: ms). | ||
@@ -99,2 +101,4 @@ | ||
## Release Note | ||
* v1.2.2 (2020-11-19) | ||
* Fixed Curtain state will not be updated in the Home APP. | ||
* v1.2.1 (2020-11-12) | ||
@@ -104,3 +108,3 @@ * Get temperature and humidity from Meter advertising periodically. | ||
* Add option for inverted curtain position. (Thanks to [@whatUwant](https://github.com/SwitchBot/homebridge-switchbot-ble/pull/4)) | ||
* Fixed HomeKit control direction reversal issue. (Thanks to [@roddenshaw](https://github.com/SwitchBot/homebridge-switchbot-ble/issues/5)) | ||
* Fixed HomeKit control direction reversal issue. | ||
* v1.1.0 (2020-10-29) | ||
@@ -107,0 +111,0 @@ * Add support for Curtain. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39691
398
116