mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-12 14:23:08 +01:00
The HTTP accessory now supports a body value.
This commit is contained in:
@@ -11,7 +11,9 @@ function HttpAccessory(log, config) {
|
|||||||
|
|
||||||
// url info
|
// url info
|
||||||
this.on_url = config["on_url"];
|
this.on_url = config["on_url"];
|
||||||
|
this.on_body = config["on_body"];
|
||||||
this.off_url = config["off_url"];
|
this.off_url = config["off_url"];
|
||||||
|
this.off_body = config["off_body"];
|
||||||
this.brightness_url = config["brightness_url"];
|
this.brightness_url = config["brightness_url"];
|
||||||
this.http_method = config["http_method"];
|
this.http_method = config["http_method"];
|
||||||
this.username = config["username"];
|
this.username = config["username"];
|
||||||
@@ -23,9 +25,10 @@ function HttpAccessory(log, config) {
|
|||||||
|
|
||||||
HttpAccessory.prototype = {
|
HttpAccessory.prototype = {
|
||||||
|
|
||||||
httpRequest: function(url, method, username, password, callback) {
|
httpRequest: function(url, body, method, username, password, callback) {
|
||||||
request({
|
request({
|
||||||
url: url,
|
url: url,
|
||||||
|
body: body,
|
||||||
method: method,
|
method: method,
|
||||||
auth: {
|
auth: {
|
||||||
user: username,
|
user: username,
|
||||||
@@ -40,16 +43,19 @@ HttpAccessory.prototype = {
|
|||||||
|
|
||||||
setPowerState: function(powerOn, callback) {
|
setPowerState: function(powerOn, callback) {
|
||||||
var url;
|
var url;
|
||||||
|
var body;
|
||||||
|
|
||||||
if (powerOn) {
|
if (powerOn) {
|
||||||
url = this.on_url;
|
url = this.on_url;
|
||||||
|
body = this.on_body;
|
||||||
this.log("Setting power state to on");
|
this.log("Setting power state to on");
|
||||||
} else {
|
} else {
|
||||||
url = this.off_url;
|
url = this.off_url;
|
||||||
|
body = this.off_body;
|
||||||
this.log("Setting power state to off");
|
this.log("Setting power state to off");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.httpRequest(url, this.http_method, this.username, this.password, function(error, response, body) {
|
this.httpRequest(url, body, this.http_method, this.username, this.password, function(error, response, body) {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.log('HTTP power function failed: %s', error.message);
|
this.log('HTTP power function failed: %s', error.message);
|
||||||
callback(error);
|
callback(error);
|
||||||
@@ -69,7 +75,7 @@ HttpAccessory.prototype = {
|
|||||||
|
|
||||||
this.log("Setting brightness to %s", level);
|
this.log("Setting brightness to %s", level);
|
||||||
|
|
||||||
this.httpRequest(url, this.http_method, this.username, this.password, function(error, response, body) {
|
this.httpRequest(url, "", this.http_method, this.username, this.password, function(error, response, body) {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.log('HTTP brightness function failed: %s', error);
|
this.log('HTTP brightness function failed: %s', error);
|
||||||
callback(error);
|
callback(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user