From 6631ebfdfa5a735f14058be8e76f57af807a555a Mon Sep 17 00:00:00 2001 From: Rohit Kabadi Date: Mon, 20 Jul 2015 20:16:54 -0700 Subject: [PATCH] - 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