Merge pull request #29 from gizmocuz/master

- Implemented optional configuration parameter for 'roomid' and fixed duplicate inserts
This commit is contained in:
Nick Farina
2015-06-14 08:29:22 -07:00
+32 -1
View File
@@ -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,6 +51,7 @@ DomoticzPlatform.prototype = {
var that = this; var that = this;
var foundAccessories = []; var foundAccessories = [];
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: "http://" + this.server + ":" + this.port + "/json.htm?type=devices&filter=light&used=true&order=Name",
@@ -64,7 +70,32 @@ DomoticzPlatform.prototype = {
that.log("There was a problem connecting to Domoticz."); 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