Skip to content

Commit

Permalink
Move I/O outside of properties for light/tplink platform (home-assist…
Browse files Browse the repository at this point in the history
…ant#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.
  • Loading branch information
gollo authored and balloob committed Jul 30, 2017
1 parent 22088d1 commit 431a381
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions homeassistant/components/light/tplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)

Expand Down

0 comments on commit 431a381

Please sign in to comment.