From fac194f66cf35c256c234c9e26a8bdeee69919c0 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Mon, 20 Jul 2015 23:27:25 -0700 Subject: [PATCH] - Added for smartplug - Added error check for host param in config.yaml - Fixed SmartPlugSwitch is_on method - Edimax smartplug works now! --- homeassistant/components/switch/edimax.py | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index 615b52ea80c..3754b452a2d 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -7,7 +7,7 @@ Support for Edimax switches. import logging from homeassistant.components.switch import SwitchDevice - +from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): @@ -23,14 +23,16 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): return + host = config.get(CONF_HOST) + auth=(config.get(CONF_USERNAME, 'admin'), + config.get(CONF_PASSWORD, '1234')) - add_devices_callback([ - SmartPlugSwitch(SmartPlug( - host = config.get('host'), - auth=( - config.get('user', 'admin'), - config.get('password', '1234')))) - ]) + if not host: + logging.getLogger(__name__).error('Missing config variable %s', CONF_HOST) + return False + + + add_devices_callback([SmartPlugSwitch(SmartPlug(host, auth))]) class SmartPlugSwitch(SwitchDevice): @@ -38,10 +40,16 @@ class SmartPlugSwitch(SwitchDevice): def __init__(self, smartplug): self.smartplug = smartplug + @property + def name(self): + """ Returns the name of the Smart Plug, if any. """ + #TODO: dynamically get name from device using requests + return 'Edimax Smart Plug' + @property def is_on(self): """ True if switch is on. """ - return self.smartplug.get_state() + return self.smartplug.state == 'ON' def turn_on(self, **kwargs): """ Turns the switch on. """