add methods to Wink accessory to fetch brightness and power state

This commit is contained in:
Jon Maddox
2015-06-25 02:00:37 -04:00
parent 08ce5a9ecc
commit 396b56e3a5

View File

@@ -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) {