Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ will NOT be exposed to HomeKit, because Indigo excludes those devices from its R
var request = require("request");
var async = require("async");
var inherits = require('util').inherits;
var parser = require("xml2json");
var Service, Characteristic, Accessory, uuid;

module.exports = function(homebridge) {
Expand Down Expand Up @@ -94,6 +95,10 @@ function fixInheritance(subclass, superclass) {
function IndigoPlatform(log, config) {
this.log = log;

if (config.version) {
this.version = config.version;
}

var protocol = "http";
if (config.protocol) {
protocol = config.protocol;
Expand Down Expand Up @@ -149,9 +154,16 @@ function IndigoPlatform(log, config) {
IndigoPlatform.prototype.accessories = function(callback) {
this.foundAccessories = [];

var requestURLs = [ this.path + "/devices.json/" ];
if (this.includeActions) {
requestURLs.push(this.path + "/actions.json/");
if (this.version == '5') {
var requestURLs = [ this.path + "/devices.xml/" ];
if (this.includeActions) {
requestURLs.push(this.path + "/actions.xml/");
}
} else {
var requestURLs = [ this.path + "/devices.json/" ];
if (this.includeActions) {
requestURLs.push(this.path + "/actions.json/");
}
}

async.eachSeries(requestURLs,
Expand Down Expand Up @@ -291,6 +303,32 @@ IndigoPlatform.prototype.indigoRequestJSON = function(path, method, qs, callback
}
var json;
try {
if (this.version == '5') {
// see toJson options here: https://github.com/buglabs/node-xml2json
var json = parser.toJson(body, {coerce: true, sanitize: false});

// replace the "$t" (toJson does this as tag for link text) with "name"
// replace the "href" tag with "restURL"
json = json.replace(/\$t/g, 'name');
json = json.replace(/"href":/g, '"restURL":');

// the JSON returned by toJson is more complex than needed here
// so take off the outer layer

// here we handle devices.xml and actions.xml pieces
json = json.replace(/^{"devices":{"device":/, '');
json = json.replace(/^{"actions":{"action":/, '');
json = json.replace(/]}}$/, ']');

// we need to insert an appropriate "restParent"
json = json.replace(/^{"device":{/, '{"restParent":"devices",');
json = json.replace(/{"action":{/, '{"restParent":"actions",');

// cleanup any trailing brace
json = json.replace(/}$/, '');

body = json;
}
var json = JSON.parse(body);
} catch (e) {
var msg2 = "Error parsing Indigo response for " + path +
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "homebridge-indigo",
"description": "Indigo plugin for homebridge: https://github.com/nfarina/homebridge",
"version": "0.2.11",
"version": "0.2.12",
"repository": {
"type": "git",
"url": "https://github.com/webdeck/homebridge-indigo.git"
Expand All @@ -13,7 +13,7 @@
"bugs": {
"url": "https://github.com/webdeck/homebridge-indigo/issues"
},
"homepage": "https://github.com/rodtoll/homebridge-indigo",
"homepage": "https://github.com/webdeck/homebridge-indigo",
"preferGlobal": true,
"keywords": [
"homebridge-plugin",
Expand All @@ -29,6 +29,7 @@
"dependencies": {
"async": "^1.4.2",
"inherits": "^2.0.1",
"request": "2.49.x"
"request": "2.49.x",
"xml2json": "^0.9.0"
}
}