mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-17 06:13:11 +01:00
Add SSL and basic auth support for Domoticz platform.
This commit is contained in:
@@ -22,6 +22,14 @@
|
|||||||
// }
|
// }
|
||||||
// ],
|
// ],
|
||||||
//
|
//
|
||||||
|
// If your server uses HTTPS, you can specify "ssl": true in your config. If
|
||||||
|
// your server uses a self-signed certificate, you'll need to run the following
|
||||||
|
// before starting the server or you will get an error:
|
||||||
|
//
|
||||||
|
// export NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||||
|
//
|
||||||
|
// For basic auth support, specify the "user" and "password" in your config.
|
||||||
|
//
|
||||||
// When you attempt to add a device, it will ask for a "PIN code".
|
// When you attempt to add a device, it will ask for a "PIN code".
|
||||||
// The default code for all HomeBridge accessories is 031-45-154.
|
// The default code for all HomeBridge accessories is 031-45-154.
|
||||||
//
|
//
|
||||||
@@ -30,8 +38,11 @@ var request = require("request");
|
|||||||
|
|
||||||
function DomoticzPlatform(log, config){
|
function DomoticzPlatform(log, config){
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
this.user = config["user"];
|
||||||
|
this.password = config["password"];
|
||||||
this.server = config["server"];
|
this.server = config["server"];
|
||||||
this.port = config["port"];
|
this.port = config["port"];
|
||||||
|
this.protocol = config["ssl"] ? "https" : "http";
|
||||||
this.roomid = 0;
|
this.roomid = 0;
|
||||||
if (typeof config["roomid"] != 'undefined') {
|
if (typeof config["roomid"] != 'undefined') {
|
||||||
this.roomid = config["roomid"];
|
this.roomid = config["roomid"];
|
||||||
@@ -46,15 +57,22 @@ function sortByKey(array, key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DomoticzPlatform.prototype = {
|
DomoticzPlatform.prototype = {
|
||||||
|
urlForQuery: function(query) {
|
||||||
|
var serverString = this.server;
|
||||||
|
if (this.user && this.password) {
|
||||||
|
serverString = this.user + ":" + this.password + "@" + serverString;
|
||||||
|
}
|
||||||
|
return this.protocol + "://" + serverString + ":" + this.port + "/json.htm?" + query;
|
||||||
|
},
|
||||||
|
|
||||||
accessories: function(callback) {
|
accessories: function(callback) {
|
||||||
this.log("Fetching Domoticz lights and switches...");
|
this.log("Fetching Domoticz lights and switches...");
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
var foundAccessories = [];
|
var foundAccessories = [];
|
||||||
if (this.roomid == 0) {
|
if (this.roomid == 0) {
|
||||||
//Get Lights
|
//Get Lights
|
||||||
request.get({
|
request.get({
|
||||||
url: "http://" + this.server + ":" + this.port + "/json.htm?type=devices&filter=light&used=true&order=Name",
|
url: this.urlForQuery("type=devices&filter=light&used=true&order=Name"),
|
||||||
json: true
|
json: true
|
||||||
}, function(err, response, json) {
|
}, function(err, response, json) {
|
||||||
if (!err && response.statusCode == 200) {
|
if (!err && response.statusCode == 200) {
|
||||||
@@ -67,14 +85,14 @@ DomoticzPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
callback(foundAccessories);
|
callback(foundAccessories);
|
||||||
} else {
|
} else {
|
||||||
that.log("There was a problem connecting to Domoticz.");
|
that.log("There was a problem connecting to Domoticz. (" + err + ")");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Get all devices specified in the room
|
//Get all devices specified in the room
|
||||||
request.get({
|
request.get({
|
||||||
url: "http://" + this.server + ":" + this.port + "/json.htm?type=devices&plan=" + this.roomid,
|
url: this.urlForQuery("type=devices&plan=" + this.roomid),
|
||||||
json: true
|
json: true
|
||||||
}, function(err, response, json) {
|
}, function(err, response, json) {
|
||||||
if (!err && response.statusCode == 200) {
|
if (!err && response.statusCode == 200) {
|
||||||
@@ -97,7 +115,7 @@ DomoticzPlatform.prototype = {
|
|||||||
//Get Scenes
|
//Get Scenes
|
||||||
foundAccessories = [];
|
foundAccessories = [];
|
||||||
request.get({
|
request.get({
|
||||||
url: "http://" + this.server + ":" + this.port + "/json.htm?type=scenes",
|
url: this.urlForQuery("type=scenes"),
|
||||||
json: true
|
json: true
|
||||||
}, function(err, response, json) {
|
}, function(err, response, json) {
|
||||||
if (!err && response.statusCode == 200) {
|
if (!err && response.statusCode == 200) {
|
||||||
|
|||||||
Reference in New Issue
Block a user