diff --git a/platforms/Nest.js b/platforms/Nest.js index 1e81fa2..6f90e7c 100644 --- a/platforms/Nest.js +++ b/platforms/Nest.js @@ -41,14 +41,26 @@ NestPlatform.prototype = { } } function subscribe() { - nest.subscribe(subscribeDone, ['shared']); + nest.subscribe(subscribeDone, ['device','shared']); } function subscribeDone(deviceId, data, type) { // data if set, is also stored here: nest.lastStatus.shared[thermostatID] if (deviceId && that.accessoryLookup[deviceId]) { that.log('Update to Device: ' + deviceId + " type: " + type); - that.accessoryLookup[deviceId].updateData(data); + var accessory = that.accessoryLookup[deviceId]; + if (accessory) { + switch (type) { + case 'shared': + accessory.updateData(data); + break; + case 'device': + accessory.device = data; + accessory.updateData(); + break; + } + } + } setTimeout(subscribe, 2000); } @@ -106,6 +118,14 @@ function NestThermostatAccessory(log, name, device, deviceId, initialData) { if (callback) callback(null, curHeatingCooling); }.bind(this)); + this.getService(Service.Thermostat) + .getCharacteristic(Characteristic.CurrentRelativeHumidity) + .on('get', function(callback) { + var curHumidity = this.getCurrentRelativeHumidity(); + this.log("Current humidity for " + this.name + " is: " + curHumidity); + if (callback) callback(null, curHumidity); + }.bind(this)); + this.getService(Service.Thermostat) .getCharacteristic(Characteristic.TargetTemperature) .on('get', function(callback) { @@ -141,6 +161,7 @@ NestThermostatAccessory.prototype.updateData = function(data) { thermostat.getCharacteristic(Characteristic.TemperatureDisplayUnits).getValue(); thermostat.getCharacteristic(Characteristic.CurrentTemperature).getValue(); thermostat.getCharacteristic(Characteristic.CurrentHeatingCoolingState).getValue(); + thermostat.getCharacteristic(Characteristic.CurrentRelativeHumidity).getValue(); thermostat.getCharacteristic(Characteristic.TargetHeatingCoolingState).getValue(); thermostat.getCharacteristic(Characteristic.TargetTemperature).getValue(); }; @@ -186,6 +207,10 @@ NestThermostatAccessory.prototype.getCurrentTemperature = function(){ return this.currentData.current_temperature; }; +NestThermostatAccessory.prototype.getCurrentRelativeHumidity = function(){ + return this.device.current_humidity; +}; + NestThermostatAccessory.prototype.getTargetTemperature = function() { switch (this.getTargetHeatingCooling()) { case Characteristic.CurrentHeatingCoolingState.HEAT | Characteristic.CurrentHeatingCoolingState.COOL: