From 27d18abefe7507a69a33dff03b2a8707046f821b Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Wed, 24 Jun 2015 21:22:03 -0400 Subject: [PATCH 1/7] bump the version of HAP-NodeJS to get onRead support --- lib/HAP-NodeJS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HAP-NodeJS b/lib/HAP-NodeJS index 19a4bee..40de0e9 160000 --- a/lib/HAP-NodeJS +++ b/lib/HAP-NodeJS @@ -1 +1 @@ -Subproject commit 19a4bee7d82674ac0051706687def1e3570c2b68 +Subproject commit 40de0e9a32eeff2986495faf78a8018d339cd52b From 847f0731c81498511fd6e08584f6b7e5ac04f68f Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Wed, 24 Jun 2015 22:20:12 -0400 Subject: [PATCH 2/7] read in the onRead --- app.js | 1 + 1 file changed, 1 insertion(+) 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, From 08ce5a9ecc84dd811570ee43c44dc0515b09c921 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 25 Jun 2015 01:42:21 -0400 Subject: [PATCH 3/7] bump HAP-NodeJS again to pull in async onreads --- lib/HAP-NodeJS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HAP-NodeJS b/lib/HAP-NodeJS index 40de0e9..18fc477 160000 --- a/lib/HAP-NodeJS +++ b/lib/HAP-NodeJS @@ -1 +1 @@ -Subproject commit 40de0e9a32eeff2986495faf78a8018d339cd52b +Subproject commit 18fc4770c6c3bb5de4a8a2b23b7bafda36219290 From 396b56e3a535ad1f946f4898811eb8431cd539bf Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 25 Jun 2015 02:00:37 -0400 Subject: [PATCH 4/7] add methods to Wink accessory to fetch brightness and power state --- platforms/Wink.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/platforms/Wink.js b/platforms/Wink.js index f7a36f1..58b09a9 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) { From b147a26738794c7c322ff8fcd9ecd0aad18f91d7 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 25 Jun 2015 02:00:52 -0400 Subject: [PATCH 5/7] add onRead functions to fetch state --- platforms/Wink.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/platforms/Wink.js b/platforms/Wink.js index 58b09a9..fd0fc53 100644 --- a/platforms/Wink.js +++ b/platforms/Wink.js @@ -209,6 +209,11 @@ WinkAccessory.prototype = { },{ cType: types.POWER_STATE_CTYPE, onUpdate: function(value) { that.setPowerState(value); }, + onRead: function(callback) { + that.getPowerState(function(powerState){ + callback(powerState); + }); + }, perms: ["pw","pr","ev"], format: "bool", initialValue: 0, @@ -219,6 +224,11 @@ WinkAccessory.prototype = { },{ cType: types.BRIGHTNESS_CTYPE, onUpdate: function(value) { that.setBrightness(value); }, + onRead: function(callback) { + that.getBrightness(function(level){ + callback(level); + }); + }, perms: ["pw","pr","ev"], format: "int", initialValue: 0, From 5e89bbe74d3192aa2e64f4495306dd05e71d0d52 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 25 Jun 2015 02:01:01 -0400 Subject: [PATCH 6/7] clean up --- platforms/Wink.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platforms/Wink.js b/platforms/Wink.js index fd0fc53..7b6083f 100644 --- a/platforms/Wink.js +++ b/platforms/Wink.js @@ -208,7 +208,9 @@ 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); @@ -223,7 +225,9 @@ 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); From e3786b183611c9799ffd08f99519d35c4911d4a0 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Fri, 26 Jun 2015 16:19:38 -0400 Subject: [PATCH 7/7] bump HAP-NodeJS to get the final async onRead stuff --- lib/HAP-NodeJS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HAP-NodeJS b/lib/HAP-NodeJS index 18fc477..b130842 160000 --- a/lib/HAP-NodeJS +++ b/lib/HAP-NodeJS @@ -1 +1 @@ -Subproject commit 18fc4770c6c3bb5de4a8a2b23b7bafda36219290 +Subproject commit b130842359214062eb61a220577ebd7de98d0dd9