Address inconsistent behavior on flux_led component (#14713)

* Address inconsistent behavior between different controllers.
Correct issue with comparison that was preventing white value slider from being shown.

* Add white mode for Flux LED

* Call _bulb.turnOn() after bulb properties have been set to prevent immediate on action

* Only use existing brightness if rgb is None to prevent unexpected recalculation of passed rgb values.

* Remove blank line

* Undo change so current brightness is used in all cases.
pull/15166/head
Matt Snyder 2018-06-26 14:23:57 -05:00 committed by Anders Melchiorsen
parent 3921dc77a6
commit 15af6b1ad9
1 changed files with 28 additions and 8 deletions

View File

@ -33,6 +33,10 @@ SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
MODE_RGB = 'rgb'
MODE_RGBW = 'rgbw'
# This mode enables white value to be controlled by brightness.
# RGB value is ignored when this mode is specified.
MODE_WHITE = 'w'
# List of supported effects which aren't already declared in LIGHT
EFFECT_RED_FADE = 'red_fade'
EFFECT_GREEN_FADE = 'green_fade'
@ -84,7 +88,7 @@ FLUX_EFFECT_LIST = [
DEVICE_SCHEMA = vol.Schema({
vol.Optional(CONF_NAME): cv.string,
vol.Optional(ATTR_MODE, default=MODE_RGBW):
vol.All(cv.string, vol.In([MODE_RGBW, MODE_RGB])),
vol.All(cv.string, vol.In([MODE_RGBW, MODE_RGB, MODE_WHITE])),
vol.Optional(CONF_PROTOCOL):
vol.All(cv.string, vol.In(['ledenet'])),
})
@ -181,6 +185,9 @@ class FluxLight(Light):
@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
if self._mode == MODE_WHITE:
return self.white_value
return self._bulb.brightness
@property
@ -191,9 +198,12 @@ class FluxLight(Light):
@property
def supported_features(self):
"""Flag supported features."""
if self._mode is MODE_RGBW:
if self._mode == MODE_RGBW:
return SUPPORT_FLUX_LED | SUPPORT_WHITE_VALUE
if self._mode == MODE_WHITE:
return SUPPORT_BRIGHTNESS
return SUPPORT_FLUX_LED
@property
@ -208,9 +218,6 @@ class FluxLight(Light):
def turn_on(self, **kwargs):
"""Turn the specified or all lights on."""
if not self.is_on:
self._bulb.turnOn()
hs_color = kwargs.get(ATTR_HS_COLOR)
if hs_color:
@ -247,10 +254,23 @@ class FluxLight(Light):
if rgb is None:
rgb = self._bulb.getRgb()
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
if white is None and self._mode == MODE_RGBW:
white = self.white_value
if white is not None:
self._bulb.setWarmWhite255(white)
# handle W only mode (use brightness instead of white value)
if self._mode == MODE_WHITE:
self._bulb.setRgbw(0, 0, 0, w=brightness)
# handle RGBW mode
elif self._mode == MODE_RGBW:
self._bulb.setRgbw(*tuple(rgb), w=white, brightness=brightness)
# handle RGB mode
else:
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
if not self.is_on:
self._bulb.turnOn()
def turn_off(self, **kwargs):
"""Turn the specified or all lights off."""