From 46f3088a7081d5b4491555b1c21d784149160f72 Mon Sep 17 00:00:00 2001 From: Alan Fischer Date: Thu, 15 Jun 2017 16:28:24 -0600 Subject: [PATCH] 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 --- homeassistant/components/light/vera.py | 19 +++++++++++-------- homeassistant/components/vera.py | 2 +- requirements_all.txt | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index 98e127acc98..ad24c1872f5 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -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() diff --git a/homeassistant/components/vera.py b/homeassistant/components/vera.py index 00b2421bdd5..5d37f0f93d8 100644 --- a/homeassistant/components/vera.py +++ b/homeassistant/components/vera.py @@ -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__) diff --git a/requirements_all.txt b/requirements_all.txt index f843532ceca..09fb62062ad 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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