Merge pull request #35 from maddox/onread

Read State
This commit is contained in:
Nick Farina
2015-06-26 13:24:31 -07:00
3 changed files with 52 additions and 3 deletions

1
app.js
View File

@@ -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,

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