From 431a381c8dae9f5339ffb33dbeece8e4d6dd4870 Mon Sep 17 00:00:00 2001 From: Sean Gollschewsky Date: Sun, 30 Jul 2017 05:53:37 +0100 Subject: [PATCH] Move I/O outside of properties for light/tplink platform (#8699) * Add new component for TPLink light bulbs. * Update with result of gen_requirements_all. * Add new component light.tplink. * Move I/O outside of properties as per https://goo.gl/Nvioub. --- homeassistant/components/light/tplink.py | 29 ++++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/light/tplink.py b/homeassistant/components/light/tplink.py index 333661870d14d2..4fadb69468ae46 100644 --- a/homeassistant/components/light/tplink.py +++ b/homeassistant/components/light/tplink.py @@ -53,6 +53,8 @@ def __init__(self, smartbulb, name): self._name = name self._state = None + self._color_temp = None + self._brightness = None _LOGGER.debug("Setting up TP-Link Smart Bulb") @property @@ -70,7 +72,6 @@ def turn_on(self, **kwargs): if ATTR_BRIGHTNESS in kwargs: brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255) self.smartbulb.brightness = brightness_to_percentage(brightness) - self.smartbulb.state = self.smartbulb.BULB_STATE_ON def turn_off(self): @@ -80,33 +81,31 @@ def turn_off(self): @property def color_temp(self): """Return the color temperature of this light in mireds for HA.""" - if self.smartbulb.is_color: - if (self.smartbulb.color_temp is not None and - self.smartbulb.color_temp != 0): - return kelvin_to_mired(self.smartbulb.color_temp) - else: - return None - else: - return None + return self._color_temp @property def brightness(self): """Return the brightness of this light between 0..255.""" - return brightness_from_percentage(self.smartbulb.brightness) + return self._brightness @property def is_on(self): """True if device is on.""" - return self.smartbulb.state == \ - self.smartbulb.BULB_STATE_ON + return self._state def update(self): """Update the TP-Link Bulb's state.""" from pyHS100 import SmartPlugException try: - self._state = self.smartbulb.state == \ - self.smartbulb.BULB_STATE_ON - + self._state = ( + self.smartbulb.state == self.smartbulb.BULB_STATE_ON) + self._brightness = brightness_from_percentage( + self.smartbulb.brightness) + if self.smartbulb.is_color: + if (self.smartbulb.color_temp is not None and + self.smartbulb.color_temp != 0): + self._color_temp = kelvin_to_mired( + self.smartbulb.color_temp) except (SmartPlugException, OSError) as ex: _LOGGER.warning('Could not read state for %s: %s', self.name, ex)