diff --git a/app.js b/app.js index 15828ab..4f94b23 100644 --- a/app.js +++ b/app.js @@ -123,6 +123,7 @@ function createHAPServer(name, services) { //loop through characteristics for (var k = 0; k < services[j].characteristics.length; k++) { var options = { + onRead: services[j].characteristics[k].onRead, type: services[j].characteristics[k].cType, perms: services[j].characteristics[k].perms, format: services[j].characteristics[k].format, diff --git a/lib/HAP-NodeJS b/lib/HAP-NodeJS index 19a4bee..b130842 160000 --- a/lib/HAP-NodeJS +++ b/lib/HAP-NodeJS @@ -1 +1 @@ -Subproject commit 19a4bee7d82674ac0051706687def1e3570c2b68 +Subproject commit b130842359214062eb61a220577ebd7de98d0dd9 diff --git a/platforms/Wink.js b/platforms/Wink.js index f7a36f1..7b6083f 100644 --- a/platforms/Wink.js +++ b/platforms/Wink.js @@ -56,6 +56,40 @@ function WinkAccessory(log, device) { } WinkAccessory.prototype = { + getPowerState: function(callback){ + if (!this.device) { + this.log("No '"+this.name+"' device found (yet?)"); + return; + } + + var that = this; + + this.log("checking power state for: " + this.name); + wink.user().device(this.name, function(light_obj){ + powerState = light_obj.desired_state.powered + that.log("power state for " + that.name + " is: " + powerState) + callback(powerState); + }); + + + }, + + getBrightness: function(callback){ + if (!this.device) { + this.log("No '"+this.name+"' device found (yet?)"); + return; + } + + var that = this; + + this.log("checking brightness level for: " + this.name); + wink.user().device(this.name, function(light_obj){ + level = light_obj.desired_state.brightness * 100 + that.log("brightness level for " + that.name + " is: " + level) + callback(level); + }); + + }, setPowerState: function(powerOn) { if (!this.device) { @@ -174,7 +208,14 @@ WinkAccessory.prototype = { designedMaxLength: 255 },{ cType: types.POWER_STATE_CTYPE, - onUpdate: function(value) { that.setPowerState(value); }, + onUpdate: function(value) { + that.setPowerState(value); + }, + onRead: function(callback) { + that.getPowerState(function(powerState){ + callback(powerState); + }); + }, perms: ["pw","pr","ev"], format: "bool", initialValue: 0, @@ -184,7 +225,14 @@ WinkAccessory.prototype = { designedMaxLength: 1 },{ cType: types.BRIGHTNESS_CTYPE, - onUpdate: function(value) { that.setBrightness(value); }, + onUpdate: function(value) { + that.setBrightness(value); + }, + onRead: function(callback) { + that.getBrightness(function(level){ + callback(level); + }); + }, perms: ["pw","pr","ev"], format: "int", initialValue: 0,