Merge pull request #361 from kemathy/master

Http accessory improvement
This commit is contained in:
Nick Farina
2015-11-02 11:55:42 -08:00
2 changed files with 101 additions and 84 deletions
+21 -8
View File
@@ -16,6 +16,9 @@ function HttpAccessory(log, config) {
this.http_method = config["http_method"];
this.username = config["username"];
this.password = config["password"];
this.service = config["service"] || "Switch";
this.name = config["name"];
this.brightnessHandling = config["brightnessHandling"] || "no";
}
HttpAccessory.prototype = {
@@ -30,7 +33,7 @@ HttpAccessory.prototype = {
sendImmediately: false
}
},
function (error, response, body) {
function(error, response, body) {
callback(error, response, body)
})
},
@@ -41,8 +44,7 @@ HttpAccessory.prototype = {
if (powerOn) {
url = this.on_url;
this.log("Setting power state to on");
}
else {
} else {
url = this.off_url;
this.log("Setting power state to off");
}
@@ -51,8 +53,7 @@ HttpAccessory.prototype = {
if (error) {
this.log('HTTP power function failed: %s', error.message);
callback(error);
}
else {
} else {
this.log('HTTP power function succeeded!');
this.log(response);
this.log(body);
@@ -72,8 +73,7 @@ HttpAccessory.prototype = {
if (error) {
this.log('HTTP brightness function failed: %s', error);
callback(error);
}
else {
} else {
this.log('HTTP brightness function succeeded!');
callback();
}
@@ -96,16 +96,29 @@ HttpAccessory.prototype = {
.setCharacteristic(Characteristic.Model, "HTTP Model")
.setCharacteristic(Characteristic.SerialNumber, "HTTP Serial Number");
var lightbulbService = new Service.Lightbulb();
if (this.service == "Switch") {
var switchService = new Service.Switch(this.name);
switchService
.getCharacteristic(Characteristic.On)
.on('set', this.setPowerState.bind(this));
return [switchService];
} else if (this.service == "Light") {
var lightbulbService = new Service.Lightbulb(this.name);
lightbulbService
.getCharacteristic(Characteristic.On)
.on('set', this.setPowerState.bind(this));
if (this.brightnessHandling == "yes") {
lightbulbService
.addCharacteristic(new Characteristic.Brightness())
.on('set', this.setBrightness.bind(this));
}
return [informationService, lightbulbService];
}
}
};
+5 -1
View File
@@ -203,7 +203,11 @@
"on_url": "https://192.168.1.22:3030/devices/23222/on",
"off_url": "https://192.168.1.22:3030/devices/23222/off",
"brightness_url": "https://192.168.1.22:3030/devices/23222/brightness/%b",
"http_method": "POST"
"username": "",
"password": "",
"http_method": "POST",
"service": "Switch",
"brightnessHandling": "no"
},
{
"accessory": "HttpHygrometer",