From 21ec435430a7943484ce611255d1dd92633b07b2 Mon Sep 17 00:00:00 2001 From: Harald Nagel Date: Thu, 28 Jan 2016 03:01:32 +0000 Subject: [PATCH 1/4] Move Insteon API KEY into configuration.yaml --- homeassistant/components/insteon.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/insteon.py b/homeassistant/components/insteon.py index 43685f5efc3..908fdaa9ea0 100644 --- a/homeassistant/components/insteon.py +++ b/homeassistant/components/insteon.py @@ -12,12 +12,11 @@ from homeassistant.helpers import validate_config from homeassistant.loader import get_component from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import ( - CONF_USERNAME, CONF_PASSWORD, ATTR_DISCOVERED, + CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY, ATTR_DISCOVERED, ATTR_SERVICE, EVENT_PLATFORM_DISCOVERED) DOMAIN = "insteon" REQUIREMENTS = ['insteon_hub==0.4.5'] -API_KEY = "3eb14d15-a486-4d9e-99af-179d0e9417c11444718937.80636061" INSTEON = None DISCOVER_LIGHTS = "insteon.lights" _LOGGER = logging.getLogger(__name__) @@ -35,10 +34,23 @@ def setup(hass, config): return False import insteon + if config[DOMAIN].get(CONF_USERNAME) is None: + _LOGGER.error("No Insteon username found in config.") + return username = config[DOMAIN][CONF_USERNAME] + + if config[DOMAIN].get(CONF_PASSWORD) is None: + _LOGGER.error("No Insteon password found in config.") + return password = config[DOMAIN][CONF_PASSWORD] + + if config[DOMAIN].get(CONF_API_KEY) is None: + _LOGGER.error("No Insteon api_key found in config.") + return + api_key = config[DOMAIN][CONF_API_KEY] + global INSTEON - INSTEON = insteon.Insteon(username, password, API_KEY) + INSTEON = insteon.Insteon(username, password, api_key) comp_name = 'light' discovery = DISCOVER_LIGHTS From 3c05c8d1db2bb09cfb580c9145845944b6b95ee7 Mon Sep 17 00:00:00 2001 From: Harald Nagel Date: Thu, 28 Jan 2016 05:55:36 +0000 Subject: [PATCH 2/4] Use validate_config, watch for import exception --- homeassistant/components/insteon.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/insteon.py b/homeassistant/components/insteon.py index 908fdaa9ea0..2121ddee0f4 100644 --- a/homeassistant/components/insteon.py +++ b/homeassistant/components/insteon.py @@ -29,29 +29,27 @@ def setup(hass, config): """ if not validate_config( config, - {DOMAIN: [CONF_USERNAME, CONF_PASSWORD]}, + {DOMAIN: [CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY]}, _LOGGER): return False - import insteon - if config[DOMAIN].get(CONF_USERNAME) is None: - _LOGGER.error("No Insteon username found in config.") - return + try: + import insteon + except ImportError: + _LOGGER.error("Error while importing dependency Insteon.") + return False + username = config[DOMAIN][CONF_USERNAME] - - if config[DOMAIN].get(CONF_PASSWORD) is None: - _LOGGER.error("No Insteon password found in config.") - return password = config[DOMAIN][CONF_PASSWORD] - - if config[DOMAIN].get(CONF_API_KEY) is None: - _LOGGER.error("No Insteon api_key found in config.") - return api_key = config[DOMAIN][CONF_API_KEY] global INSTEON INSTEON = insteon.Insteon(username, password, api_key) + if INSTEON is None: + _LOGGER.error("Could not connect to Insteon service.") + return + comp_name = 'light' discovery = DISCOVER_LIGHTS component = get_component(comp_name) From f192a15a8f441c77f412a2996c1c37c2ac15d4a0 Mon Sep 17 00:00:00 2001 From: Harald Nagel Date: Fri, 29 Jan 2016 02:35:04 +0000 Subject: [PATCH 3/4] Remove unnecessary try around import --- homeassistant/components/insteon.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/homeassistant/components/insteon.py b/homeassistant/components/insteon.py index 2121ddee0f4..254262990ed 100644 --- a/homeassistant/components/insteon.py +++ b/homeassistant/components/insteon.py @@ -33,11 +33,7 @@ def setup(hass, config): _LOGGER): return False - try: - import insteon - except ImportError: - _LOGGER.error("Error while importing dependency Insteon.") - return False + import insteon username = config[DOMAIN][CONF_USERNAME] password = config[DOMAIN][CONF_PASSWORD] From eebb736bf83c572b797931c571e7416223436461 Mon Sep 17 00:00:00 2001 From: Harald Nagel Date: Fri, 29 Jan 2016 04:36:40 +0000 Subject: [PATCH 4/4] Add ability to control dimmable sources --- homeassistant/components/light/insteon.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/light/insteon.py b/homeassistant/components/light/insteon.py index 07c4d19b202..c1632133d8f 100644 --- a/homeassistant/components/light/insteon.py +++ b/homeassistant/components/light/insteon.py @@ -13,4 +13,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in INSTEON.devices: if device.DeviceCategory == "Switched Lighting Control": devs.append(InsteonToggleDevice(device)) + if device.DeviceCategory == "Dimmable Lighting Control": + devs.append(InsteonToggleDevice(device)) add_devices(devs)