From 6631ebfdfa5a735f14058be8e76f57af807a555a Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Mon, 20 Jul 2015 20:16:54 -0700 Subject: [PATCH 01/10] - Added git submodule @ https://github.com/rkabadi/pyedimax - Added edimax.py module to interface with Edimax SP-1101W and SP-2101W --- .gitmodules | 3 ++ homeassistant/components/switch/edimax.py | 52 +++++++++++++++++++++++ homeassistant/external/pyedimax | 1 + 3 files changed, 56 insertions(+) create mode 100644 homeassistant/components/switch/edimax.py create mode 160000 homeassistant/external/pyedimax diff --git a/.gitmodules b/.gitmodules index ca0b1f024b8..5d994cf6ceb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "homeassistant/external/pymysensors"] path = homeassistant/external/pymysensors url = https://github.com/theolind/pymysensors +[submodule "homeassistant/external/pyedimax"] + path = homeassistant/external/pyedimax + url = https://github.com/rkabadi/pyedimax diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py new file mode 100644 index 00000000000..615b52ea80c --- /dev/null +++ b/homeassistant/components/switch/edimax.py @@ -0,0 +1,52 @@ +""" +homeassistant.components.switch.edimax +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Support for Edimax switches. +""" +import logging + +from homeassistant.components.switch import SwitchDevice + + +# pylint: disable=unused-argument +def setup_platform(hass, config, add_devices_callback, discovery_info=None): + """ Find and return Edimax Smart Plugs. """ + try: + # pylint: disable=no-name-in-module, import-error + from homeassistant.external.pyedimax.smartplug import SmartPlug + except ImportError: + logging.getLogger(__name__).exception(( + "Failed to import pyedimax. " + "Did you maybe not run `git submodule init` " + "and `git submodule update`?")) + + return + + + add_devices_callback([ + SmartPlugSwitch(SmartPlug( + host = config.get('host'), + auth=( + config.get('user', 'admin'), + config.get('password', '1234')))) + ]) + + +class SmartPlugSwitch(SwitchDevice): + """ Represents a Edimax Smart Plug switch within Home Assistant. """ + def __init__(self, smartplug): + self.smartplug = smartplug + + @property + def is_on(self): + """ True if switch is on. """ + return self.smartplug.get_state() + + def turn_on(self, **kwargs): + """ Turns the switch on. """ + self.smartplug.state = 'ON' + + def turn_off(self): + """ Turns the switch off. """ + self.smartplug.state = 'OFF' \ No newline at end of file diff --git a/homeassistant/external/pyedimax b/homeassistant/external/pyedimax new file mode 160000 index 00000000000..3815f3bd99f --- /dev/null +++ b/homeassistant/external/pyedimax @@ -0,0 +1 @@ +Subproject commit 3815f3bd99fb9dcd4d9e5e6fc58626f5873e43db From fac194f66cf35c256c234c9e26a8bdeee69919c0 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Mon, 20 Jul 2015 23:27:25 -0700 Subject: [PATCH 02/10] - 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. """ From 6a7e28cc8565eec9a540cb0d8ea61f75e4372131 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Sat, 25 Jul 2015 18:46:47 -0700 Subject: [PATCH 03/10] - Added support for getting power on SP2101W devices (returns None on SP1101W) --- .coveragerc | 1 + .../www_static/polymer/home-assistant-js | 2 +- homeassistant/components/switch/edimax.py | 27 +++++++++++++++---- homeassistant/external/netdisco | 2 +- homeassistant/external/pyedimax | 2 +- homeassistant/external/pymysensors | 2 +- homeassistant/external/pynetgear | 2 +- homeassistant/external/pywemo | 2 +- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.coveragerc b/.coveragerc index 39a3dee22bf..a2ad399f1a3 100644 --- a/.coveragerc +++ b/.coveragerc @@ -53,6 +53,7 @@ omit = homeassistant/components/sensor/systemmonitor.py homeassistant/components/sensor/time_date.py homeassistant/components/sensor/transmission.py + homeassistant/components/sensor/edimax.py homeassistant/components/switch/hikvisioncam.py homeassistant/components/switch/wemo.py homeassistant/components/thermostat/nest.py diff --git a/homeassistant/components/frontend/www_static/polymer/home-assistant-js b/homeassistant/components/frontend/www_static/polymer/home-assistant-js index 94d8682c1e7..232302b2f58 160000 --- a/homeassistant/components/frontend/www_static/polymer/home-assistant-js +++ b/homeassistant/components/frontend/www_static/polymer/home-assistant-js @@ -1 +1 @@ -Subproject commit 94d8682c1e7679ae744e8419896d5d7b0bdd16cc +Subproject commit 232302b2f589fa216b6531e65dae5dafd851f6f0 diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index 3754b452a2d..1b8ec4e0a4a 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -9,6 +9,7 @@ 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): """ Find and return Edimax Smart Plugs. """ @@ -24,14 +25,14 @@ 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')) + auth = (config.get(CONF_USERNAME, 'admin'), + config.get(CONF_PASSWORD, '1234')) if not host: - logging.getLogger(__name__).error('Missing config variable %s', CONF_HOST) + logging.getLogger(__name__).error( + 'Missing config variable %s', CONF_HOST) return False - add_devices_callback([SmartPlugSwitch(SmartPlug(host, auth))]) @@ -46,6 +47,22 @@ class SmartPlugSwitch(SwitchDevice): #TODO: dynamically get name from device using requests return 'Edimax Smart Plug' + @property + def current_power_mwh(self): + """ Current power usage in mwh. """ + try: + return float(self.smartplug.now_power) / 1000000.0 + except ValueError: + return None + + @property + def today_power_mw(self): + """ Today total power usage in mw. """ + try: + return float(self.smartplug.now_energy_day) / 1000.0 + except ValueError: + return None + @property def is_on(self): """ True if switch is on. """ @@ -57,4 +74,4 @@ class SmartPlugSwitch(SwitchDevice): def turn_off(self): """ Turns the switch off. """ - self.smartplug.state = 'OFF' \ No newline at end of file + self.smartplug.state = 'OFF' diff --git a/homeassistant/external/netdisco b/homeassistant/external/netdisco index b2cad7c2b95..0e2a4d4e3ec 160000 --- a/homeassistant/external/netdisco +++ b/homeassistant/external/netdisco @@ -1 +1 @@ -Subproject commit b2cad7c2b959efa8eee9b5ac62d87232bf0b5176 +Subproject commit 0e2a4d4e3eccc0895872d1046ef748b05d26ba90 diff --git a/homeassistant/external/pyedimax b/homeassistant/external/pyedimax index 3815f3bd99f..674ada04c42 160000 --- a/homeassistant/external/pyedimax +++ b/homeassistant/external/pyedimax @@ -1 +1 @@ -Subproject commit 3815f3bd99fb9dcd4d9e5e6fc58626f5873e43db +Subproject commit 674ada04c42da5c1103205293a078be73f661fd6 diff --git a/homeassistant/external/pymysensors b/homeassistant/external/pymysensors index cd5ef892eee..7fb5c0ef877 160000 --- a/homeassistant/external/pymysensors +++ b/homeassistant/external/pymysensors @@ -1 +1 @@ -Subproject commit cd5ef892eeec0ad027727f7e8f757e7f2927da97 +Subproject commit 7fb5c0ef877c285d5d98ca0c0c6cbee552164d34 diff --git a/homeassistant/external/pynetgear b/homeassistant/external/pynetgear index e946ecf7926..8863fdd3565 160000 --- a/homeassistant/external/pynetgear +++ b/homeassistant/external/pynetgear @@ -1 +1 @@ -Subproject commit e946ecf7926b9b2adaa1e3127a9738201a1b1fc7 +Subproject commit 8863fdd356556bc82e6d236ad2bc662e7d091ff0 diff --git a/homeassistant/external/pywemo b/homeassistant/external/pywemo index ca94e41faa4..eef7dae12a0 160000 --- a/homeassistant/external/pywemo +++ b/homeassistant/external/pywemo @@ -1 +1 @@ -Subproject commit ca94e41faa48c783f600a2efd550c6b7dae01b0d +Subproject commit eef7dae12a073db7b8ac58340bf1cd6a1fea78c6 From bb0ace3a615b799c27b442619dba4a3c62dcadda Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Sat, 25 Jul 2015 23:59:48 -0700 Subject: [PATCH 04/10] - Reverted submodule updates --- homeassistant/components/switch/edimax.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index 1b8ec4e0a4a..426c016b59e 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -37,7 +37,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): class SmartPlugSwitch(SwitchDevice): - """ Represents a Edimax Smart Plug switch within Home Assistant. """ + """ Represents an Edimax Smart Plug switch within Home Assistant. """ def __init__(self, smartplug): self.smartplug = smartplug From 613c0122c0768f8133b8f6a9c979359d6f88d185 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Sun, 26 Jul 2015 00:08:57 -0700 Subject: [PATCH 05/10] - Reverted submodule updates. This is the 2nd attempt since the first one did not work --- .../components/frontend/www_static/polymer/home-assistant-js | 2 +- homeassistant/external/netdisco | 2 +- homeassistant/external/pymysensors | 2 +- homeassistant/external/pynetgear | 2 +- homeassistant/external/pywemo | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/frontend/www_static/polymer/home-assistant-js b/homeassistant/components/frontend/www_static/polymer/home-assistant-js index 232302b2f58..94d8682c1e7 160000 --- a/homeassistant/components/frontend/www_static/polymer/home-assistant-js +++ b/homeassistant/components/frontend/www_static/polymer/home-assistant-js @@ -1 +1 @@ -Subproject commit 232302b2f589fa216b6531e65dae5dafd851f6f0 +Subproject commit 94d8682c1e7679ae744e8419896d5d7b0bdd16cc diff --git a/homeassistant/external/netdisco b/homeassistant/external/netdisco index 0e2a4d4e3ec..b2cad7c2b95 160000 --- a/homeassistant/external/netdisco +++ b/homeassistant/external/netdisco @@ -1 +1 @@ -Subproject commit 0e2a4d4e3eccc0895872d1046ef748b05d26ba90 +Subproject commit b2cad7c2b959efa8eee9b5ac62d87232bf0b5176 diff --git a/homeassistant/external/pymysensors b/homeassistant/external/pymysensors index 7fb5c0ef877..cd5ef892eee 160000 --- a/homeassistant/external/pymysensors +++ b/homeassistant/external/pymysensors @@ -1 +1 @@ -Subproject commit 7fb5c0ef877c285d5d98ca0c0c6cbee552164d34 +Subproject commit cd5ef892eeec0ad027727f7e8f757e7f2927da97 diff --git a/homeassistant/external/pynetgear b/homeassistant/external/pynetgear index 8863fdd3565..e946ecf7926 160000 --- a/homeassistant/external/pynetgear +++ b/homeassistant/external/pynetgear @@ -1 +1 @@ -Subproject commit 8863fdd356556bc82e6d236ad2bc662e7d091ff0 +Subproject commit e946ecf7926b9b2adaa1e3127a9738201a1b1fc7 diff --git a/homeassistant/external/pywemo b/homeassistant/external/pywemo index eef7dae12a0..ca94e41faa4 160000 --- a/homeassistant/external/pywemo +++ b/homeassistant/external/pywemo @@ -1 +1 @@ -Subproject commit eef7dae12a073db7b8ac58340bf1cd6a1fea78c6 +Subproject commit ca94e41faa48c783f600a2efd550c6b7dae01b0d From f6811e858ac80f47a71394931ff9e95d4b092ee4 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Wed, 29 Jul 2015 00:24:42 -0700 Subject: [PATCH 06/10] - Removed https://github.com/rkabadi/pyedimax as submodule - Added https://github.com/rkabadi/pyedimax to requirements - Modified edimax.py to import pyedimax from python3 default packages --- .gitmodules | 3 --- homeassistant/components/switch/edimax.py | 6 ++---- homeassistant/external/pyedimax | 1 - requirements.txt | 3 +++ 4 files changed, 5 insertions(+), 8 deletions(-) delete mode 160000 homeassistant/external/pyedimax diff --git a/.gitmodules b/.gitmodules index 5d994cf6ceb..ca0b1f024b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,6 +22,3 @@ [submodule "homeassistant/external/pymysensors"] path = homeassistant/external/pymysensors url = https://github.com/theolind/pymysensors -[submodule "homeassistant/external/pyedimax"] - path = homeassistant/external/pyedimax - url = https://github.com/rkabadi/pyedimax diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index 426c016b59e..e988ffec0f0 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -15,12 +15,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return Edimax Smart Plugs. """ try: # pylint: disable=no-name-in-module, import-error - from homeassistant.external.pyedimax.smartplug import SmartPlug + from pyedimax.smartplug import SmartPlug except ImportError: logging.getLogger(__name__).exception(( - "Failed to import pyedimax. " - "Did you maybe not run `git submodule init` " - "and `git submodule update`?")) + "Failed to import pyedimax. ")) return diff --git a/homeassistant/external/pyedimax b/homeassistant/external/pyedimax deleted file mode 160000 index 674ada04c42..00000000000 --- a/homeassistant/external/pyedimax +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 674ada04c42da5c1103205293a078be73f661fd6 diff --git a/requirements.txt b/requirements.txt index 83780721c2c..d77fe9b3b89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -79,3 +79,6 @@ PyMata==2.07a # Mysensors serial gateway pyserial>=2.7 + +# PyEdimax +git+https://github.com/rkabadi/pyedimax.git \ No newline at end of file From 6a239bf18a7e010b09e7606fd09afc03a06f1691 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Thu, 30 Jul 2015 00:10:16 -0700 Subject: [PATCH 07/10] Used validate_config to ensure 'host' parameter in edimax config. Added name option to edimax config --- homeassistant/components/switch/edimax.py | 45 ++++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index e988ffec0f0..58cc757a1f8 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -6,9 +6,17 @@ Support for Edimax switches. """ import logging -from homeassistant.components.switch import SwitchDevice -from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD +from homeassistant.helpers import validate_config +from homeassistant.components.switch import SwitchDevice, DOMAIN +from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_NAME +# constants +DEFAULT_USERNAME = 'admin' +DEFAULT_PASSWORD = '1234' +DEVICE_DEFAULT_NAME = 'Edimax Smart Plug' + +# setup logger +_LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): @@ -17,33 +25,34 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): # pylint: disable=no-name-in-module, import-error from pyedimax.smartplug import SmartPlug except ImportError: - logging.getLogger(__name__).exception(( - "Failed to import pyedimax. ")) - - return - - host = config.get(CONF_HOST) - auth = (config.get(CONF_USERNAME, 'admin'), - config.get(CONF_PASSWORD, '1234')) - - if not host: - logging.getLogger(__name__).error( - 'Missing config variable %s', CONF_HOST) + _LOGGER.error('Failed to import pyedimax') return False - add_devices_callback([SmartPlugSwitch(SmartPlug(host, auth))]) + # pylint: disable=global-statement + # check for required values in configuration file + if not validate_config({DOMAIN: config}, + {DOMAIN: [CONF_HOST]}, + _LOGGER): + return False + + host = config.get(CONF_HOST) + auth = (config.get(CONF_USERNAME, DEFAULT_USERNAME), + config.get(CONF_PASSWORD, DEFAULT_PASSWORD)) + name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME) + + add_devices_callback([SmartPlugSwitch(SmartPlug(host, auth), name)]) class SmartPlugSwitch(SwitchDevice): """ Represents an Edimax Smart Plug switch within Home Assistant. """ - def __init__(self, smartplug): + def __init__(self, smartplug, name): self.smartplug = smartplug + self._name = name @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' + return self._name @property def current_power_mwh(self): From f351ab9544d50dc39b806e3a31c05bc17f76b2a9 Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Thu, 30 Jul 2015 00:37:11 -0700 Subject: [PATCH 08/10] Updated branch to avoid conflicts in requirements.txt --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements.txt b/requirements.txt index f0f49e5a248..b4adce86d22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -91,3 +91,6 @@ pywemo>=0.1 # Wink (*.wink) https://github.com/balloob/python-wink/archive/master.zip#pywink>=0.1 + +# PyEdimax +https://github.com/rkabadi/pyedimax/archive/master.zip \ No newline at end of file From ffde7e183e81031de7fd6fabbc5f65b137ac205b Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Thu, 30 Jul 2015 21:05:00 -0700 Subject: [PATCH 09/10] Fixed flake8 violations --- homeassistant/components/switch/edimax.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index 58cc757a1f8..ab461f4de07 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -8,7 +8,8 @@ import logging from homeassistant.helpers import validate_config from homeassistant.components.switch import SwitchDevice, DOMAIN -from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_NAME +from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD,\ + CONF_NAME # constants DEFAULT_USERNAME = 'admin' @@ -18,6 +19,7 @@ DEVICE_DEFAULT_NAME = 'Edimax Smart Plug' # setup logger _LOGGER = logging.getLogger(__name__) + # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return Edimax Smart Plugs. """ From c248d5455e7f21971527df8ab4637e3f8189882c Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Sun, 2 Aug 2015 18:01:31 -0700 Subject: [PATCH 10/10] Added REQUIREMENTS lilst to edimax.py --- homeassistant/components/switch/edimax.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index ab461f4de07..171183900df 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -15,6 +15,7 @@ from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD,\ DEFAULT_USERNAME = 'admin' DEFAULT_PASSWORD = '1234' DEVICE_DEFAULT_NAME = 'Edimax Smart Plug' +REQUIREMENTS = ['https://github.com/rkabadi/pyedimax/archive/master.zip'] # setup logger _LOGGER = logging.getLogger(__name__)