From 2120f3aab694f51d2988659ce54cb2303b903859 Mon Sep 17 00:00:00 2001 From: scoobyshi Date: Mon, 2 Jan 2017 16:17:55 -0500 Subject: [PATCH 1/2] Debug statements and removed offending condition. --- lib/wink-accessory.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/wink-accessory.js b/lib/wink-accessory.js index d2543b6..97b35ba 100644 --- a/lib/wink-accessory.js +++ b/lib/wink-accessory.js @@ -68,8 +68,11 @@ var refreshUntil = function (maxTimes, predicate, callback, interval, incrementI var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback) { this.log("Changing target property '" + sProperty + "' of the " + this.device.device_group + " called " + this.device.name + " to " + sTarget); + this.log("Debug Logs Follow..."); + if (this.device.desired_state == undefined) { callback(Error("Unsupported")); + this.log("Desired State Undefined"); return; } @@ -77,16 +80,21 @@ var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback for (var i = 0; i < sProperty.length; i++) { if (this.device.desired_state[sProperty[i]] == undefined) { callback(Error("Unsupported")); + this.log("Desired State Array Undefined"); return; } } - } else if (this.device.desired_state[sProperty] == undefined) { + } + + /* else if (this.device.desired_state[sProperty] == undefined) { callback(Error("Unsupported")); + this.log("Desired State Array of 1 Undefined"); return; - } + } */ if (!this.device.last_reading.connection) { callback(Error("Unconnected")); + this.log("Unconnected"); return; } @@ -102,6 +110,9 @@ var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback data.desired_state[sProperty] = sTarget; } + this.log("Reading Data: " + JSON.stringify(this.device)); + this.log("Request Data: " + JSON.stringify(data)); + var that = this; var update = function (retry) { that.control.update(data, From ff9e6e4ceae282e2b75fc11cb32457b5bc93c912 Mon Sep 17 00:00:00 2001 From: scoobyshi Date: Sat, 7 Jan 2017 21:39:30 -0500 Subject: [PATCH 2/2] Fixes for brightness settings to work consistently --- accessories/light_bulbs.js | 7 ++++--- lib/wink-accessory.js | 16 +++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/accessories/light_bulbs.js b/accessories/light_bulbs.js index 93be668..d3ff99a 100755 --- a/accessories/light_bulbs.js +++ b/accessories/light_bulbs.js @@ -46,7 +46,8 @@ function WinkLightAccessory(platform, device) { that.updateWinkProperty(callback, "powered", value); }); - if (that.device.desired_state.brightness !== undefined) + //Check if there is a node for brightness, if so add the characteristic + if (that.device.last_reading.brightness !== undefined) this .getService(Service.Lightbulb) .getCharacteristic(Characteristic.Brightness) @@ -59,7 +60,7 @@ function WinkLightAccessory(platform, device) { that.updateWinkProperty(callback, "brightness", that.brightness); }); - if (that.device.desired_state.hue !== undefined) + if (that.device.last_reading.hue !== undefined) this .getService(Service.Lightbulb) .getCharacteristic(Characteristic.Hue) @@ -73,7 +74,7 @@ function WinkLightAccessory(platform, device) { [that.hue, that.saturation, that.brightness, 'hsb']); }); - if (that.device.desired_state.saturation !== undefined) + if (that.device.last_reading.saturation !== undefined) this .getService(Service.Lightbulb) .getCharacteristic(Characteristic.Saturation) diff --git a/lib/wink-accessory.js b/lib/wink-accessory.js index 97b35ba..5ef27b9 100644 --- a/lib/wink-accessory.js +++ b/lib/wink-accessory.js @@ -68,7 +68,6 @@ var refreshUntil = function (maxTimes, predicate, callback, interval, incrementI var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback) { this.log("Changing target property '" + sProperty + "' of the " + this.device.device_group + " called " + this.device.name + " to " + sTarget); - this.log("Debug Logs Follow..."); if (this.device.desired_state == undefined) { callback(Error("Unsupported")); @@ -76,9 +75,10 @@ var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback return; } + //Check if there is an attribute in last_reading, if so, then we can apply desired_state if (sProperty instanceof Array) { for (var i = 0; i < sProperty.length; i++) { - if (this.device.desired_state[sProperty[i]] == undefined) { + if (this.device.last_reading[sProperty[i]] == undefined) { callback(Error("Unsupported")); this.log("Desired State Array Undefined"); return; @@ -86,11 +86,11 @@ var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback } } - /* else if (this.device.desired_state[sProperty] == undefined) { + else if (this.device.last_reading[sProperty] == undefined) { callback(Error("Unsupported")); this.log("Desired State Array of 1 Undefined"); return; - } */ + } if (!this.device.last_reading.connection) { callback(Error("Unconnected")); @@ -110,9 +110,6 @@ var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback data.desired_state[sProperty] = sTarget; } - this.log("Reading Data: " + JSON.stringify(this.device)); - this.log("Request Data: " + JSON.stringify(data)); - var that = this; var update = function (retry) { that.control.update(data, @@ -125,12 +122,13 @@ var updateWinkProperty = function (callback, sProperty, sTarget, bIgnoreFeedback if (!err) { that.refreshUntil(8, function (sProperty) { + //Check if desired_state is cleared, if so then its applied, thus completed is true if (sProperty instanceof Array) { for (var i = 0; i < sProperty.length; i++) { - return ((that.device.last_reading[sProperty[i]] == that.device.desired_state[sProperty[i]]) || bIgnoreFeedback); + return ((that.device.desired_state[sProperty[i]] == undefined) || bIgnoreFeedback); } } else { - return ((that.device.last_reading[sProperty] == that.device.desired_state[sProperty]) || bIgnoreFeedback); + return ((that.device.desired_state[sProperty] == undefined) || bIgnoreFeedback); } },