diff --git a/.coveragerc b/.coveragerc index fbad345ff4a..c7b5b07e02b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -223,6 +223,7 @@ omit = homeassistant/components/switch/pulseaudio_loopback.py homeassistant/components/switch/rest.py homeassistant/components/switch/rpi_rf.py + homeassistant/components/switch/tplink.py homeassistant/components/switch/transmission.py homeassistant/components/switch/wake_on_lan.py homeassistant/components/thermostat/eq3btsmart.py diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py new file mode 100644 index 00000000000..6db6c96d17e --- /dev/null +++ b/homeassistant/components/switch/tplink.py @@ -0,0 +1,53 @@ +"""Support for TPLink HS100/HS110 smart switch. + +It is able to monitor current switch status, as well as turn on and off +the switch. Will work with both HS100 and HS110 switch models. +""" + +from homeassistant.components.switch import SwitchDevice +from homeassistant.const import ( + CONF_HOST, CONF_NAME) + +# constants +DEVICE_DEFAULT_NAME = 'HS100' +REQUIREMENTS = ['https://github.com/gadgetreactor/pyHS100/archive/' + 'master.zip#pyHS100==0.1.2'] + +# pylint: disable=unused-argument + + +def setup_platform(hass, config, add_devices_callback, discovery_info=None): + """Setup the TPLink platform in configuration.yaml.""" + from pyHS100.pyHS100 import SmartPlug + host = config.get(CONF_HOST) + name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME) + + add_devices_callback([SmartPlugSwitch(SmartPlug(host), + name)]) + + +class SmartPlugSwitch(SwitchDevice): + """Representation of a TPLink Smart Plug switch.""" + + def __init__(self, smartplug, name): + """Initialize the switch.""" + self.smartplug = smartplug + self._name = name + + @property + def name(self): + """Return the name of the Smart Plug, if any.""" + return self._name + + @property + def is_on(self): + """Return true if switch is on.""" + return self.smartplug.state == 'ON' + + def turn_on(self, **kwargs): + """Turn the switch on.""" + self.smartplug.state = 'ON' + + def turn_off(self): + """Turn the switch off.""" + self.smartplug.state = 'OFF' diff --git a/requirements_all.txt b/requirements_all.txt index 5731ee57e24..9b864fcad75 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -128,6 +128,9 @@ https://github.com/danieljkemp/onkyo-eiscp/archive/python3.zip#onkyo-eiscp==0.9. # homeassistant.components.device_tracker.fritz # https://github.com/deisi/fritzconnection/archive/b5c14515e1c8e2652b06b6316a7f3913df942841.zip#fritzconnection==0.4.6 +# homeassistant.components.switch.tplink +https://github.com/gadgetreactor/pyHS100/archive/master.zip#pyHS100==0.1.2 + # homeassistant.components.netatmo https://github.com/jabesq/netatmo-api-python/archive/v0.5.0.zip#lnetatmo==0.5.0