Http Accessory improvements : accessory type (switch or light), and ligtht brightness handling toggle

This commit is contained in:
Kevin Mathy
2015-10-30 22:55:53 +01:00
parent 3da52388e8
commit 255a064c08

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 = {
@@ -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,30 @@ 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('get', this.getPowerOn.bind(this))
.on('set', this.setPowerOn.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];
}
}
};