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:
parent
e89e64263c
commit
e19e9a1f2b
3 changed files with 11 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue