Skip to content

Commit

Permalink
Add longer wait/backoff if blinds position doesn't change #31
Browse files Browse the repository at this point in the history
  • Loading branch information
dxdc committed Apr 15, 2020
1 parent 26d8d09 commit 9b1ff37
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,18 @@ BlindsHTTPAccessory.prototype.setTargetPosition = function(pos, callback) {
let targetReached = false;
let positionRetries = 0;

let intervalsToSkip = 0;
let lastIntervalPosition = -1;

self.stepInterval = setInterval(function() {
if (targetReached) {
if (intervalsToSkip > 1) {
--intervalsToSkip;
} else if (intervalsToSkip === 1) {
intervalsToSkip = 0;
targetReached = false;
}

return; // avoid duplicate calls
}

Expand Down Expand Up @@ -466,8 +476,15 @@ BlindsHTTPAccessory.prototype.setTargetPosition = function(pos, callback) {
if (positionRetries > 10) {
self.log.error(`Didn't reach target after ${positionRetries} tries`);
self.manualStop = true;
} else if (self.lastPosition === lastIntervalPosition) {
if (self.verbose) {
self.log.info(`Blinds position didn't change: skipping ${positionRetries} cycle${positionRetries > 1 ? 's' : ''}`);
}
intervalsToSkip = positionRetries;
return;
}

lastIntervalPosition = self.lastPosition;
targetReached = false;
}
}.bind(self));
Expand Down

0 comments on commit 9b1ff37

Please sign in to comment.