Color control for Abode RGB lights (#17347)

* Color control support for Abode lights

* Updated add_devices to add_entities

* Update line length

* Changed elif to if for pylint warning
This commit is contained in:
shred86 2018-10-11 22:47:14 -08:00 committed by Anders Melchiorsen
parent 1c23a36f46
commit 7bb60068d7

View file

@ -8,9 +8,10 @@ import logging
from math import ceil from math import ceil
from homeassistant.components.abode import AbodeDevice, DOMAIN as ABODE_DOMAIN from homeassistant.components.abode import AbodeDevice, DOMAIN as ABODE_DOMAIN
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_COLOR_TEMP,
SUPPORT_BRIGHTNESS, SUPPORT_COLOR, Light) SUPPORT_BRIGHTNESS, SUPPORT_COLOR, SUPPORT_COLOR_TEMP, Light)
import homeassistant.util.color as color_util from homeassistant.util.color import (
color_temperature_kelvin_to_mired, color_temperature_mired_to_kelvin)
DEPENDENCIES = ['abode'] DEPENDENCIES = ['abode']
@ -45,10 +46,13 @@ class AbodeLight(AbodeDevice, Light):
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Turn on the light.""" """Turn on the light."""
if (ATTR_HS_COLOR in kwargs and if ATTR_COLOR_TEMP in kwargs and self._device.is_color_capable:
self._device.is_dimmable and self._device.has_color): self._device.set_color_temp(
self._device.set_color(color_util.color_hs_to_RGB( int(color_temperature_mired_to_kelvin(
*kwargs[ATTR_HS_COLOR])) kwargs[ATTR_COLOR_TEMP])))
if ATTR_HS_COLOR in kwargs and self._device.is_color_capable:
self._device.set_color(kwargs[ATTR_HS_COLOR])
if ATTR_BRIGHTNESS in kwargs and self._device.is_dimmable: if ATTR_BRIGHTNESS in kwargs and self._device.is_dimmable:
# Convert HASS brightness (0-255) to Abode brightness (0-99) # Convert HASS brightness (0-255) to Abode brightness (0-99)
@ -77,18 +81,23 @@ class AbodeLight(AbodeDevice, Light):
# Convert Abode brightness (0-99) to HASS brightness (0-255) # Convert Abode brightness (0-99) to HASS brightness (0-255)
return ceil(brightness * 255 / 99.0) return ceil(brightness * 255 / 99.0)
@property
def color_temp(self):
"""Return the color temp of the light."""
if self._device.has_color:
return color_temperature_kelvin_to_mired(self._device.color_temp)
@property @property
def hs_color(self): def hs_color(self):
"""Return the color of the light.""" """Return the color of the light."""
if self._device.is_dimmable and self._device.has_color: if self._device.has_color:
return color_util.color_RGB_to_hs(*self._device.color) return self._device.color
@property @property
def supported_features(self): def supported_features(self):
"""Flag supported features.""" """Flag supported features."""
if self._device.is_dimmable and self._device.has_color: if self._device.is_dimmable and self._device.is_color_capable:
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
if self._device.is_dimmable: if self._device.is_dimmable:
return SUPPORT_BRIGHTNESS return SUPPORT_BRIGHTNESS
return 0 return 0