From e19e9a1f2b0cbe1fd2629bf07a0eda317ca3cb64 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Sun, 8 Oct 2017 16:31:32 +0200 Subject: [PATCH] switch.tplink, light.tplink: bump the pyhs100 version and adapt to api changes (#9454) * bump the pyhs100 version and fix api changes * switch.tplink: avoid I/O during __init__ * initialize _name to None in __init__ * update requirements_all.txt for the new version --- homeassistant/components/light/tplink.py | 6 +++--- homeassistant/components/switch/tplink.py | 18 +++++++----------- requirements_all.txt | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/light/tplink.py b/homeassistant/components/light/tplink.py index 14288b8848d..3e0589836e8 100644 --- a/homeassistant/components/light/tplink.py +++ b/homeassistant/components/light/tplink.py @@ -17,7 +17,7 @@ from homeassistant.util.color import ( from typing import Tuple -REQUIREMENTS = ['pyHS100==0.2.4.2'] +REQUIREMENTS = ['pyHS100==0.3.0'] _LOGGER = logging.getLogger(__name__) @@ -124,7 +124,7 @@ class TPLinkSmartBulb(Light): def update(self): """Update the TP-Link Bulb's state.""" - from pyHS100 import SmartPlugException + from pyHS100 import SmartDeviceException try: self._state = ( self.smartbulb.state == self.smartbulb.BULB_STATE_ON) @@ -136,7 +136,7 @@ class TPLinkSmartBulb(Light): self._color_temp = kelvin_to_mired( self.smartbulb.color_temp) self._rgb = hsv_to_rgb(self.smartbulb.hsv) - except (SmartPlugException, OSError) as ex: + except (SmartDeviceException, OSError) as ex: _LOGGER.warning('Could not read state for %s: %s', self.name, ex) @property diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index 4b83cedc4c1..df0050ff979 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -14,7 +14,7 @@ from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) from homeassistant.const import (CONF_HOST, CONF_NAME, ATTR_VOLTAGE) import homeassistant.helpers.config_validation as cv -REQUIREMENTS = ['pyHS100==0.2.4.2'] +REQUIREMENTS = ['pyHS100==0.3.0'] _LOGGER = logging.getLogger(__name__) @@ -45,15 +45,8 @@ class SmartPlugSwitch(SwitchDevice): def __init__(self, smartplug, name): """Initialize the switch.""" self.smartplug = smartplug - - # Use the name set on the device if not set - if name is None: - self._name = self.smartplug.alias - else: - self._name = name - + self._name = None self._state = None - _LOGGER.debug("Setting up TP-Link Smart Plug") # Set up emeter cache self._emeter_params = {} @@ -82,11 +75,14 @@ class SmartPlugSwitch(SwitchDevice): def update(self): """Update the TP-Link switch's state.""" - from pyHS100 import SmartPlugException + from pyHS100 import SmartDeviceException try: self._state = self.smartplug.state == \ self.smartplug.SWITCH_STATE_ON + if self._name is None: + self._name = self.smartplug.alias + if self.smartplug.has_emeter: emeter_readings = self.smartplug.get_emeter_realtime() @@ -107,5 +103,5 @@ class SmartPlugSwitch(SwitchDevice): # device returned no daily history pass - except (SmartPlugException, OSError) as ex: + except (SmartDeviceException, OSError) as ex: _LOGGER.warning('Could not read state for %s: %s', self.name, ex) diff --git a/requirements_all.txt b/requirements_all.txt index 16cf4dc59c1..80563dd41e9 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -550,7 +550,7 @@ pyCEC==0.4.13 # homeassistant.components.light.tplink # homeassistant.components.switch.tplink -pyHS100==0.2.4.2 +pyHS100==0.3.0 # homeassistant.components.rfxtrx pyRFXtrx==0.20.1