Skip to content

Commit

Permalink
Polling with existing timeouts #55
Browse files Browse the repository at this point in the history
  • Loading branch information
dxdc committed Jun 29, 2021
1 parent 3d1b79b commit e5cab41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,14 @@ BlindsHTTPAccessory.prototype.replaceUrlPosition = function (url, pos) {
};

BlindsHTTPAccessory.prototype.setTargetPosition = function (pos, callback) {
if (this.stopTimeout !== null) {
clearTimeout(this.stopTimeout);
this.stopTimeout = null;
}
if (this.stepInterval !== null) {
clearInterval(this.stepInterval);
this.stepInterval = null;
}
if (this.lagTimeout !== null) {
clearTimeout(this.lagTimeout);
this.lagTimeout = null;
}
clearTimeout(this.stopTimeout);
this.stopTimeout = null;

clearInterval(this.stepInterval);
this.stepInterval = null;

clearTimeout(this.lagTimeout);
this.lagTimeout = null;

this.manualStop = false;
this.currentTargetPosition = pos;
Expand Down Expand Up @@ -573,6 +569,8 @@ BlindsHTTPAccessory.prototype.setTargetPosition = function (pos, callback) {
BlindsHTTPAccessory.prototype.endMoveRequest = function (moveMessage) {
clearInterval(this.stepInterval);
this.stepInterval = null;
clearTimeout(this.lagTimeout);
this.lagTimeout = null;

this.log.info(`End ${moveMessage} to ${this.lastPosition}% (target ${this.currentTargetPosition}%)`);

Expand All @@ -588,12 +586,11 @@ BlindsHTTPAccessory.prototype.endMoveRequest = function (moveMessage) {

BlindsHTTPAccessory.prototype.sendStopRequest = function (targetService, on, callback) {
if (on) {
clearTimeout(this.stopTimeout);
this.stopTimeout = null;

if (targetService) {
this.log.info('Requesting manual stop');
if (this.stopTimeout !== null) {
clearTimeout(this.stopTimeout);
this.stopTimeout = null;
}
} else {
this.log.info('Requesting stop');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-blinds",
"version": "1.3.25-beta.2",
"version": "1.3.25-beta.3",
"description": "A homebridge plugin to control my blinds",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e5cab41

Please sign in to comment.