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
This commit is contained in:
1 parent
e89e64263c
commit
e19e9a1f2b
3 files changed
+11
-15
No files matched your search
@@ -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)
|
||||
Reference in new issue
Block a user