mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-05 06:13:13 +01:00
Merge pull request #29 from gizmocuz/master
- Implemented optional configuration parameter for 'roomid' and fixed duplicate inserts
This commit is contained in:
@@ -17,7 +17,8 @@
|
|||||||
// "platform": "Domoticz",
|
// "platform": "Domoticz",
|
||||||
// "name": "Domoticz",
|
// "name": "Domoticz",
|
||||||
// "server": "127.0.0.1",
|
// "server": "127.0.0.1",
|
||||||
// "port": "8080"
|
// "port": "8080",
|
||||||
|
// "roomid": 123 (0=no roomplan)
|
||||||
// }
|
// }
|
||||||
// ],
|
// ],
|
||||||
//
|
//
|
||||||
@@ -31,6 +32,10 @@ function DomoticzPlatform(log, config){
|
|||||||
this.log = log;
|
this.log = log;
|
||||||
this.server = config["server"];
|
this.server = config["server"];
|
||||||
this.port = config["port"];
|
this.port = config["port"];
|
||||||
|
this.roomid = 0;
|
||||||
|
if (typeof config["roomid"] != 'undefined') {
|
||||||
|
this.roomid = config["roomid"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortByKey(array, key) {
|
function sortByKey(array, key) {
|
||||||
@@ -46,25 +51,51 @@ DomoticzPlatform.prototype = {
|
|||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
var foundAccessories = [];
|
var foundAccessories = [];
|
||||||
//Get Lights
|
if (this.roomid == 0) {
|
||||||
request.get({
|
//Get Lights
|
||||||
url: "http://" + this.server + ":" + this.port + "/json.htm?type=devices&filter=light&used=true&order=Name",
|
request.get({
|
||||||
json: true
|
url: "http://" + this.server + ":" + this.port + "/json.htm?type=devices&filter=light&used=true&order=Name",
|
||||||
}, function(err, response, json) {
|
json: true
|
||||||
if (!err && response.statusCode == 200) {
|
}, function(err, response, json) {
|
||||||
if (json['result'] != undefined) {
|
if (!err && response.statusCode == 200) {
|
||||||
var sArray=sortByKey(json['result'],"Name");
|
if (json['result'] != undefined) {
|
||||||
sArray.map(function(s) {
|
var sArray=sortByKey(json['result'],"Name");
|
||||||
accessory = new DomoticzAccessory(that.log, that.server, that.port, false, s.idx, s.Name, s.HaveDimmer, s.MaxDimLevel, (s.SubType=="RGB")||(s.SubType=="RGBW"));
|
sArray.map(function(s) {
|
||||||
foundAccessories.push(accessory);
|
accessory = new DomoticzAccessory(that.log, that.server, that.port, false, s.idx, s.Name, s.HaveDimmer, s.MaxDimLevel, (s.SubType=="RGB")||(s.SubType=="RGBW"));
|
||||||
})
|
foundAccessories.push(accessory);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
callback(foundAccessories);
|
||||||
|
} else {
|
||||||
|
that.log("There was a problem connecting to Domoticz.");
|
||||||
}
|
}
|
||||||
callback(foundAccessories);
|
});
|
||||||
} else {
|
}
|
||||||
that.log("There was a problem connecting to Domoticz.");
|
else {
|
||||||
}
|
//Get all devices specified in the room
|
||||||
});
|
request.get({
|
||||||
|
url: "http://" + this.server + ":" + this.port + "/json.htm?type=devices&plan=" + this.roomid,
|
||||||
|
json: true
|
||||||
|
}, function(err, response, json) {
|
||||||
|
if (!err && response.statusCode == 200) {
|
||||||
|
if (json['result'] != undefined) {
|
||||||
|
var sArray=sortByKey(json['result'],"Name");
|
||||||
|
sArray.map(function(s) {
|
||||||
|
//only accept switches for now
|
||||||
|
if (typeof s.SwitchType != 'undefined') {
|
||||||
|
accessory = new DomoticzAccessory(that.log, that.server, that.port, false, s.idx, s.Name, s.HaveDimmer, s.MaxDimLevel, (s.SubType=="RGB")||(s.SubType=="RGBW"));
|
||||||
|
foundAccessories.push(accessory);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
callback(foundAccessories);
|
||||||
|
} else {
|
||||||
|
that.log("There was a problem connecting to Domoticz.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
//Get Scenes
|
//Get Scenes
|
||||||
|
foundAccessories = [];
|
||||||
request.get({
|
request.get({
|
||||||
url: "http://" + this.server + ":" + this.port + "/json.htm?type=scenes",
|
url: "http://" + this.server + ":" + this.port + "/json.htm?type=scenes",
|
||||||
json: true
|
json: true
|
||||||
|
|||||||
Reference in New Issue
Block a user