From f2f598bd264bb9536065058a65f49c49153f2920 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 26 Nov 2015 16:37:00 +0100 Subject: [PATCH] Use host as config var instead of resource --- homeassistant/components/switch/mystrom.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/switch/mystrom.py b/homeassistant/components/switch/mystrom.py index 3acbfb24ce6..36a62fe33e4 100644 --- a/homeassistant/components/switch/mystrom.py +++ b/homeassistant/components/switch/mystrom.py @@ -16,29 +16,27 @@ DEFAULT_NAME = 'myStrom Switch' _LOGGER = logging.getLogger(__name__) -# pylint: disable=unused-argument, too-many-function-args def setup_platform(hass, config, add_devices, discovery_info=None): """ Find and return myStrom switches. """ - resource = config.get('resource') + host = config.get('host') - if resource is None: - _LOGGER.error('Missing required variable: resource') + if host is None: + _LOGGER.error('Missing required variable: host') return False + resource = 'http://{}'.format(host) + try: requests.get(resource, timeout=10) - except requests.exceptions.MissingSchema: - _LOGGER.error("Missing resource or schema in configuration. " - "Add http:// to your URL.") - return False except requests.exceptions.ConnectionError: - _LOGGER.error("No route to device. " - "Please check the IP address in the configuration file.") + _LOGGER.error("No route to device %s. " + "Please check the IP address in the configuration file", + host) return False add_devices([MyStromSwitch( config.get('name', DEFAULT_NAME), - config.get('resource'))]) + resource)]) class MyStromSwitch(SwitchDevice):