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

Brightness / Dimness settings fixes #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions accessories/light_bulbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions lib/wink-accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,33 @@ 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);

if (this.device.desired_state == undefined) {
callback(Error("Unsupported"));
this.log("Desired State Undefined");
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;
}
}
} 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"));
this.log("Unconnected");
return;
}

Expand Down Expand Up @@ -114,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);
}

},
Expand Down