Vera fix for dimmable vs rgb lights (#8007)

* Differentiate between dimmable & rgb lights

* Updated requirements

* Cache _has_color for supported_features

* simplify & cleanup code

* Create vera.py
This commit is contained in:
Alan Fischer 2017-06-15 16:28:24 -06:00 committed by Pascal Vizeli
parent deed760008
commit 46f3088a70
3 changed files with 13 additions and 10 deletions

View file

@ -16,8 +16,6 @@ _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['vera']
SUPPORT_VERA = SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
@ -32,29 +30,32 @@ class VeraLight(VeraDevice, Light):
def __init__(self, vera_device, controller):
"""Initialize the light."""
self._state = False
self._color = None
self._brightness = None
VeraDevice.__init__(self, vera_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
@property
def brightness(self):
"""Return the brightness of the light."""
if self.vera_device.is_dimmable:
return self.vera_device.get_brightness()
return self._brightness
@property
def rgb_color(self):
"""Return the color of the light."""
if self.vera_device.is_dimmable:
return self.vera_device.get_color()
return self._color
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_VERA
if self._color:
return SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR
else:
return SUPPORT_BRIGHTNESS
def turn_on(self, **kwargs):
"""Turn the light on."""
if ATTR_RGB_COLOR in kwargs and self.vera_device.is_dimmable:
if ATTR_RGB_COLOR in kwargs and self._color:
self.vera_device.set_color(kwargs[ATTR_RGB_COLOR])
elif ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS])
@ -78,3 +79,5 @@ class VeraLight(VeraDevice, Light):
def update(self):
"""Call to update state."""
self._state = self.vera_device.is_switched_on()
self._brightness = self.vera_device.get_brightness()
self._color = self.vera_device.get_color()

View file

@ -20,7 +20,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP)
from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['pyvera==0.2.32']
REQUIREMENTS = ['pyvera==0.2.33']
_LOGGER = logging.getLogger(__name__)

View file

@ -742,7 +742,7 @@ pyunifi==2.12
# pyuserinput==0.1.11
# homeassistant.components.vera
pyvera==0.2.32
pyvera==0.2.33
# homeassistant.components.notify.html5
pywebpush==1.0.4