Add RGB support to switch.flux (#8417)

This commit is contained in:
Dougal Matthews 2017-07-14 04:53:19 +02:00 committed by Paulus Schoutsen
parent 4fde0ffe9c
commit d8abef9210
2 changed files with 65 additions and 2 deletions

View file

@ -37,6 +37,7 @@ CONF_MODE = 'mode'
MODE_XY = 'xy'
MODE_MIRED = 'mired'
MODE_RGB = 'rgb'
DEFAULT_MODE = MODE_XY
PLATFORM_SCHEMA = vol.Schema({
@ -55,7 +56,7 @@ PLATFORM_SCHEMA = vol.Schema({
vol.All(vol.Coerce(int), vol.Range(min=0, max=255)),
vol.Optional(CONF_DISABLE_BRIGTNESS_ADJUST): cv.boolean,
vol.Optional(CONF_MODE, default=DEFAULT_MODE):
vol.Any(MODE_XY, MODE_MIRED)
vol.Any(MODE_XY, MODE_MIRED, MODE_RGB)
})
@ -79,6 +80,15 @@ def set_lights_temp(hass, lights, mired, brightness):
transition=30)
def set_lights_rgb(hass, lights, rgb):
"""Set color of array of lights."""
for light in lights:
if is_on(hass, light):
turn_on(hass, light,
rgb_color=rgb,
transition=30)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Flux switches."""
@ -194,7 +204,8 @@ class FluxSwitch(SwitchDevice):
temp = self._sunset_colortemp - temp_offset
else:
temp = self._sunset_colortemp + temp_offset
x_val, y_val, b_val = color_RGB_to_xy(*color_temperature_to_rgb(temp))
rgb = color_temperature_to_rgb(temp)
x_val, y_val, b_val = color_RGB_to_xy(*rgb)
brightness = self._brightness if self._brightness else b_val
if self._disable_brightness_adjust:
brightness = None
@ -205,6 +216,11 @@ class FluxSwitch(SwitchDevice):
"of %s cycle complete at %s", x_val, y_val,
brightness, round(
percentage_complete * 100), time_state, now)
elif self._mode == MODE_RGB:
set_lights_rgb(self.hass, self._lights, rgb)
_LOGGER.info("Lights updated to rgb:%s, %s%% "
"of %s cycle complete at %s", rgb,
round(percentage_complete * 100), time_state, now)
else:
# Convert to mired and clamp to allowed values
mired = color_temperature_kelvin_to_mired(temp)