From 3c05c8d1db2bb09cfb580c9145845944b6b95ee7 Mon Sep 17 00:00:00 2001 From: Harald Nagel Date: Thu, 28 Jan 2016 05:55:36 +0000 Subject: [PATCH] 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)