From f3e08b0a151760830982141e41b88703d15c4ad5 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Wed, 16 Sep 2015 03:12:56 -0400 Subject: [PATCH] add device types from Home Assistant based on the supported types declared in the config Instead of matching with a regex, we use a config of supported device types to attempt to load in. This allows the user to whitelist just the ones they want to add. --- platforms/HomeAssistant.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/platforms/HomeAssistant.js b/platforms/HomeAssistant.js index 6088b94..4c12a40 100644 --- a/platforms/HomeAssistant.js +++ b/platforms/HomeAssistant.js @@ -37,7 +37,8 @@ // "platform": "HomeAssistant", // "name": "HomeAssistant", // "host": "http://192.168.1.50:8123", -// "password": "xxx" +// "password": "xxx", +// "supported_types": ["light", "switch", "media_player", "scene"] // } // ] // @@ -56,6 +57,7 @@ function HomeAssistantPlatform(log, config){ // auth info this.host = config["host"]; this.password = config["password"]; + this.supportedTypes = config["supported_types"]; this.log = log; } @@ -121,22 +123,24 @@ HomeAssistantPlatform.prototype = { var that = this; var foundAccessories = []; - var lightsRE = /^light\./i - var switchRE = /^switch\./i - var mediaPlayerRE = /^media_player\./i - this._request('GET', '/states', {}, function(error, response, data){ for (var i = 0; i < data.length; i++) { entity = data[i] + entity_type = entity.entity_id.split('.')[0] + + if (that.supportedTypes.indexOf(entity_type) == -1) { + continue; + } + var accessory = null - if (entity.entity_id.match(lightsRE)) { + if (entity_type == 'light') { accessory = new HomeAssistantLight(that.log, entity, that) - }else if (entity.entity_id.match(switchRE)){ + }else if (entity_type == 'switch'){ accessory = new HomeAssistantSwitch(that.log, entity, that) - }else if (entity.entity_id.match(mediaPlayerRE) && entity.attributes && entity.attributes.supported_media_commands){ + }else if (entity_type == 'media_player' && entity.attributes && entity.attributes.supported_media_commands){ accessory = new HomeAssistantMediaPlayer(that.log, entity, that) }