Skip to content

Commit

Permalink
Issue #130
Browse files Browse the repository at this point in the history
Reset transitiontime to default 0.4s after being used.
  • Loading branch information
ebaauw committed Jun 30, 2017
1 parent 8c571b0 commit aa98d66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
23 changes: 20 additions & 3 deletions lib/HueBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ function HueBridge(platform, host) {
this.platform = platform;
this.name = host;
this.url = 'http://' + host + '/api';
this.defaultTransitiontime = 0.4;
this.state = {
heartrate: this.platform.config.heartrate,
transitiontime: 0.4,
transitiontime: this.defaultTransitiontime,
request: 0,
touchlink: false
};
Expand Down Expand Up @@ -371,6 +372,22 @@ HueBridge.prototype.refresh = function() {
this.hk.touchlink = this.state.touchlink ? 1 : 0;
};

HueBridge.prototype.resetTransitionTime = function() {
if (this.state.resetTimer) {
return;
}
this.state.resetTimer = setTimeout(function () {
this.log.info(
'%s: reset homekit transition time from %ss to %ss', this.name,
this.state.transitiontime, this.defaultTransitiontime
);
this.state.transitiontime = this.defaultTransitiontime;
this.service.getCharacteristic(Characteristic.TransitionTime)
.updateValue(this.state.transitiontime);
delete this.state.resetTimer;
}.bind(this), this.platform.config.waitTimeUpdate);
};

// ===== Heartbeat =============================================================

HueBridge.prototype.heartbeat = function(beat) {
Expand Down Expand Up @@ -528,7 +545,7 @@ HueBridge.prototype.setHeartrate = function(rate, callback) {
return callback();
}
this.log.info(
'%s: homekit heartrate changed from %s to %s', this.name,
'%s: homekit heartrate changed from %ss to %ss', this.name,
this.state.heartrate, rate
);
this.state.heartrate = rate;
Expand All @@ -541,7 +558,7 @@ HueBridge.prototype.setTransitionTime = function(transitiontime, callback) {
return callback();
}
this.log.info(
'%s: homekit transition time changed from %s to %s', this.name,
'%s: homekit transition time changed from %ss to %ss', this.name,
this.state.transitiontime, transitiontime
);
this.state.transitiontime = transitiontime;
Expand Down
3 changes: 2 additions & 1 deletion lib/HueLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,10 +822,11 @@ HueLight.prototype.put = function() {
// jshint -W106
const desiredState = this.desiredState;
if (
this.bridge.state.transitiontime !== 0.4 &&
this.bridge.state.transitiontime !== this.bridge.defaultTransitiontime &&
desiredState.transitiontime === undefined
) {
desiredState.transitiontime = this.bridge.state.transitiontime * 10;
this.bridge.resetTransitionTime();
}
this.desiredState = null;
this.bridge.request('put', this.resourcePath, desiredState)
Expand Down

0 comments on commit aa98d66

Please sign in to comment.