Update example platforms for async conventions (#1998)

This commit is contained in:
Adam Mills 2017-02-08 12:30:58 -05:00 committed by Fabian Affolter
parent 38e6098ad8
commit daa11ee550
2 changed files with 20 additions and 4 deletions

View file

@ -76,11 +76,14 @@ class AwesomeLight(Light):
def __init__(self, light):
"""Initialize an AwesomeLight."""
self._light = light
self._name = light.name
self._state = None
self._brightness = None
@property
def name(self):
"""Return the display name of this light."""
return self._light.name
return self._name
@property
def brightness(self):
@ -89,12 +92,12 @@ class AwesomeLight(Light):
This method is optional. Removing it indicates to Home Assistant
that brightness is not supported for this light.
"""
return self._light.brightness
return self._brightness
@property
def is_on(self):
"""Return true if light is on."""
return self._light.is_on()
return self._state
def turn_on(self, **kwargs):
"""Instruct the light to turn on.
@ -115,4 +118,6 @@ class AwesomeLight(Light):
This is the only method that should fetch new data for Home Assistant.
"""
self._light.update()
self._state = self._light.is_on()
self._brightness = self._light.brightness
```