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

View File

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