From c5f416a91fd5ce17a4bece0bda640add27795b91 Mon Sep 17 00:00:00 2001 From: RossGGG Date: Thu, 18 Feb 2016 23:04:50 -0800 Subject: [PATCH 1/3] Update index.js Added a configurable option to consolidate Indigo devices that share a device address into a single accessory with multiple services. An example of where this would be useful is for FanLinc devices: Indigo must report these as two separate devices (one to control the fan, and one to control the light) because of how it handles device type controls in its own GUI, however HomeKit supports having these controls listed under a single device which makes more sense since they are associated with one physical device in your home. --- index.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9c6af2b..07d91fc 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ Configuration example for your Homebridge config.json: "username": "myusername", "password": "mypassword", "includeActions": true, + "consolidateDevices": true, "includeIds": [ "12345", "67890" ], "excludeIds": [ "98765", "43210" ], "treatAsSwitchIds": [ "13579", "24680" ], @@ -38,6 +39,7 @@ Fields: "username": Username to log into Indigo web server, if applicable (optional) "password": Password to log into Indigo web server, if applicable (optional) "includeActions": If true, creates HomeKit switches for your actions (optional, defaults to false) + "consolidateDevices": If true, devices with the same device address will be seen in HomeKit as one accessory with multiple services (optional, defaults to false) "includeIds": Array of Indigo IDs to include (optional - if provided, only these Indigo IDs will map to HomeKit devices) "excludeIds": Array of Indigo IDs to exclude (optional - if provided, these Indigo IDs will not be mapped to HomeKit devices) "treatAsSwitchIds": Array of Indigo IDs to treat as switches (instead of lightbulbs) - devices must support on/off to qualify @@ -228,7 +230,27 @@ IndigoPlatform.prototype.addAccessory = function(item, callback) { if (this.includeItemId(json.id)) { var accessory = this.createAccessoryFromJSON(item.restURL, json); if (accessory) { - this.foundAccessories.push(accessory); + var deviceLinked = false; + + if (this.consolidateDevices) { + for (var key in this.foundAccessories) { + if (this.foundAccessories.hasOwnProperty(key)) { + it = this.foundAccessories[key]; + + if (accessory.addressStr != "unknown" && accessory.addressStr === it.addressStr) { + this.log("Consolidating: " + accessory.name + " Link to: " + it.name); + it.linkedDevices.push(accessory); + var deviceLinked = true; + + break; + } + } + } + } + + if (deviceLinked === false) { + this.foundAccessories.push(accessory); + } } else { this.log("Ignoring unknown accessory type %s", json.type); } @@ -341,6 +363,7 @@ function IndigoAccessory(platform, deviceURL, json) { this.platform = platform; this.log = platform.log; this.deviceURL = deviceURL; + this.linkedDevices = []; this.updateFromJSON(json); @@ -360,7 +383,19 @@ function IndigoAccessory(platform, deviceURL, json) { } IndigoAccessory.prototype.getServices = function() { - return this.services; + var services = this.services; + + if (this.linkedDevices.length > 0) { + for (var key in this.linkedDevices) { + if (this.linkedDevices.hasOwnProperty(key)) { + it = this.linkedDevices[key]; + + services = services.concat(it.getServices().slice(1)); + } + } + } + + return services; }; // Updates object fields with values from json From 9ddc29b38feeea1f2eb52f6c40552aa44b49e494 Mon Sep 17 00:00:00 2001 From: RossGGG Date: Thu, 18 Feb 2016 23:09:55 -0800 Subject: [PATCH 2/3] Update README.md Added consolidateDevices option to the configuration sample and fields description. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4d7f806..5dff755 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Configuration sample: "username": "myusername", "password": "mypassword", "includeActions": true, + "consolidateDevices": true, "includeIds": [ "12345", "67890" ], "excludeIds": [ "98765", "43210" ], "treatAsSwitchIds": [ "13579", "24680" ], @@ -54,6 +55,7 @@ Fields: * "username": Username to log into Indigo web server, if applicable (optional) * "password": Password to log into Indigo web server, if applicable (optional) * "includeActions": If true, creates HomeKit switches for your actions (optional, defaults to false) +* "consolidateDevices": If true, devices with the same device address will be seen in HomeKit as one device with multiple services. * "includeIds": Array of Indigo IDs to include (optional - if provided, only these Indigo IDs will map to HomeKit devices) * "excludeIds": Array of Indigo IDs to exclude (optional - if provided, these Indigo IDs will not be mapped to HomeKit devices) * "treatAsSwitchIds": Array of Indigo IDs to treat as switches (instead of lightbulbs) - devices must support on/off to qualify @@ -71,6 +73,8 @@ expose everything, then omit both of these keys from your configuration. Also note that any Indigo devices or actions that have Remote Display unchecked in Indigo will NOT be exposed to HomeKit, because Indigo excludes those devices from its RESTful API. +The consolidateDevices option is useful in situations such as with a FanLinc, where Indigo separates the fan controls and light controls each into their own separate device even though there is only one physical device. With this option set to true HomeKit will show these controls under one device to reflect that. + HomeKit limits bridges to 100 devices, so if you have more than 99 Indigo devices (and action groups, if you're including them), then you will want to use includeIds or excludeIds to get your list down to under 100. From a2cd92de70a54c0af4b930462bfd1ff13161df7b Mon Sep 17 00:00:00 2001 From: RossGGG Date: Thu, 18 Feb 2016 23:11:36 -0800 Subject: [PATCH 3/3] Update sampleconfig.json Added consolidateDevices option. --- sampleconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/sampleconfig.json b/sampleconfig.json index 7d9d9e1..4ea1836 100644 --- a/sampleconfig.json +++ b/sampleconfig.json @@ -19,6 +19,7 @@ "username": "myusername", "password": "mypassword", "includeActions": true, + "consolidateDevices": true, "includeIds": [ "12345", "67890" ], "excludeIds": [ "98765", "43210" ], "treatAsSwitchIds": [ "13579", "24680" ],