diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index bcc1b329fa8..44fecf37e56 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -1,5 +1,5 @@ """ -Support for TPLink HS100/HS110 smart switch. +Support for TPLink HS100/HS110/HS200 smart switch. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/switch.tplink/ @@ -15,12 +15,10 @@ from homeassistant.const import (CONF_HOST, CONF_NAME) import homeassistant.helpers.config_validation as cv REQUIREMENTS = ['https://github.com/GadgetReactor/pyHS100/archive/' - '1f771b7d8090a91c6a58931532e42730b021cbde.zip#pyHS100==0.2.0'] + '45fc3548882628bcde3e3d365db341849457bef2.zip#pyHS100==0.2.2'] _LOGGER = logging.getLogger(__name__) -DEFAULT_NAME = 'TPLink Switch HS100' - ATTR_CURRENT_CONSUMPTION = 'Current consumption' ATTR_TOTAL_CONSUMPTION = 'Total consumption' ATTR_DAILY_CONSUMPTION = 'Daily consumption' @@ -29,14 +27,14 @@ ATTR_CURRENT = 'Current' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, + vol.Optional(CONF_NAME): cv.string, }) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the TPLink switch platform.""" - from pyHS100.pyHS100 import SmartPlug + from pyHS100 import SmartPlug host = config.get(CONF_HOST) name = config.get(CONF_NAME) @@ -49,10 +47,15 @@ class SmartPlugSwitch(SwitchDevice): def __init__(self, smartplug, name): """Initialize the switch.""" self.smartplug = smartplug - self._name = name + + # Use the name set on the device if not set + if name is None: + self._name = self.smartplug.alias + else: + self._name = name + self._state = None - self._emeter_present = (smartplug.model == 110) - _LOGGER.debug("Setting up TP-Link Smart Plug HS%i", smartplug.model) + _LOGGER.debug("Setting up TP-Link Smart Plug") # Set up emeter cache self._emeter_params = {} @@ -64,15 +67,15 @@ class SmartPlugSwitch(SwitchDevice): @property def is_on(self): """Return true if switch is on.""" - return self._state == 'ON' + return self.smartplug.is_on def turn_on(self, **kwargs): """Turn the switch on.""" - self.smartplug.state = 'ON' + self.smartplug.turn_on() def turn_off(self): """Turn the switch off.""" - self.smartplug.state = 'OFF' + self.smartplug.turn_off() @property def device_state_attributes(self): @@ -84,7 +87,7 @@ class SmartPlugSwitch(SwitchDevice): try: self._state = self.smartplug.state - if self._emeter_present: + if self.smartplug.has_emeter: emeter_readings = self.smartplug.get_emeter_realtime() self._emeter_params[ATTR_CURRENT_CONSUMPTION] \ diff --git a/requirements_all.txt b/requirements_all.txt index b5d803f5c73..f39a560f2f8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -180,7 +180,7 @@ http://github.com/technicalpickles/python-nest/archive/b8391d2b3cb8682f8b0c2bdff https://github.com/Danielhiversen/flux_led/archive/0.10.zip#flux_led==0.10 # homeassistant.components.switch.tplink -https://github.com/GadgetReactor/pyHS100/archive/1f771b7d8090a91c6a58931532e42730b021cbde.zip#pyHS100==0.2.0 +https://github.com/GadgetReactor/pyHS100/archive/45fc3548882628bcde3e3d365db341849457bef2.zip#pyHS100==0.2.2 # homeassistant.components.switch.dlink https://github.com/LinuxChristian/pyW215/archive/v0.3.7.zip#pyW215==0.3.7