Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added debounce to set temperature #115

Merged
merged 1 commit into from
Sep 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/nest-thermostat-accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Created by kraigm on 12/15/15.
*/

var Promise = require('bluebird');
var debounce = require('lodash.debounce');
var inherits = require('util').inherits;
var Accessory, Service, Characteristic, uuid;
var NestDeviceAccessory = require('./nest-device-accessory')();
Expand Down Expand Up @@ -179,7 +181,15 @@ NestThermostatAccessory.prototype.setTargetHeatingCooling = function (targetHeat
.asCallback(callback);
};

NestThermostatAccessory.prototype.setTargetTemperature = function (targetTemperature, callback) {
NestThermostatAccessory.prototype.setTargetTemperature = function(targetTemperature, callback) {
this.log('Trying to set temperature ' + targetTemperature);
this.setTargetTemperatureDebounced(targetTemperature, function() {
this.log('Temperature set to ' + targetTemperature);
}.bind(this));
return Promise.resolve().asCallback(callback);
};

NestThermostatAccessory.prototype.setTargetTemperatureDebounced = debounce(function (targetTemperature, callback) {
var usesFahrenheit = this.usesFahrenheit();
if (usesFahrenheit) {
// Convert to Fahrenheit and round to nearest integer
Expand Down Expand Up @@ -213,7 +223,7 @@ NestThermostatAccessory.prototype.setTargetTemperature = function (targetTempera
return this.cancelAutoAway()
.then(this.updateDevicePropertyAsync.bind(this, key, targetTemperature, prop + "target temperature"))
.asCallback(callback);
};
}, 5000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 5s delay is right on the cusp of making me question if I actually completed an action. Consider making this user-configurable. Alternatively, decrease the delay, perhaps to 2 or 3s.


NestThermostatAccessory.prototype.usesFahrenheit = function () {
return this.getTemperatureUnits() == Characteristic.TemperatureDisplayUnits.FAHRENHEIT;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"homebridge": ">=0.2.5"
},
"dependencies": {
"firebase": "^2.3.2",
"bluebird": "^3.2.2",
"firebase": "^2.3.2",
"lodash.debounce": "^4.0.8",
"request-promise": "^1.0.2",
"unofficial-nest-api": "git+https://github.com/kraigm/unofficial_nodejs_nest.git#3cbd337adc32fab3b481659b38d86f9fcd6a9c02"
}
Expand Down