mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 07:47:08 +00:00
Allow independent control of white level on flux_led component (#13985)
* Allow independent control of white level on flux_led component. Also preserve brightness on color change. * Limit white value support to RGBW mode. * Requested changes. * Correct liniting issues * Formatting
This commit is contained in:
parent
e4655a7e63
commit
c2d00be91e
@ -12,9 +12,9 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL
|
from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, EFFECT_COLORLOOP,
|
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE,
|
||||||
EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
|
EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
|
||||||
SUPPORT_COLOR, Light, PLATFORM_SCHEMA)
|
SUPPORT_COLOR, SUPPORT_WHITE_VALUE, Light, PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
@ -191,8 +191,16 @@ class FluxLight(Light):
|
|||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
|
if self._mode is MODE_RGBW:
|
||||||
|
return SUPPORT_FLUX_LED | SUPPORT_WHITE_VALUE
|
||||||
|
|
||||||
return SUPPORT_FLUX_LED
|
return SUPPORT_FLUX_LED
|
||||||
|
|
||||||
|
@property
|
||||||
|
def white_value(self):
|
||||||
|
"""Return the white value of this light between 0..255."""
|
||||||
|
return self._bulb.getRgbw()[3]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect_list(self):
|
def effect_list(self):
|
||||||
"""Return the list of supported effects."""
|
"""Return the list of supported effects."""
|
||||||
@ -212,24 +220,31 @@ class FluxLight(Light):
|
|||||||
|
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
white = kwargs.get(ATTR_WHITE_VALUE)
|
||||||
|
|
||||||
if rgb is not None and brightness is not None:
|
# color change only
|
||||||
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
|
if rgb is not None:
|
||||||
elif rgb is not None:
|
self._bulb.setRgb(*tuple(rgb), brightness=self.brightness)
|
||||||
self._bulb.setRgb(*tuple(rgb))
|
|
||||||
|
# brightness change only
|
||||||
elif brightness is not None:
|
elif brightness is not None:
|
||||||
if self._mode == MODE_RGBW:
|
(red, green, blue) = self._bulb.getRgb()
|
||||||
self._bulb.setWarmWhite255(brightness)
|
self._bulb.setRgb(red, green, blue, brightness=brightness)
|
||||||
elif self._mode == MODE_RGB:
|
|
||||||
(red, green, blue) = self._bulb.getRgb()
|
# random color effect
|
||||||
self._bulb.setRgb(red, green, blue, brightness=brightness)
|
|
||||||
elif effect == EFFECT_RANDOM:
|
elif effect == EFFECT_RANDOM:
|
||||||
self._bulb.setRgb(random.randint(0, 255),
|
self._bulb.setRgb(random.randint(0, 255),
|
||||||
random.randint(0, 255),
|
random.randint(0, 255),
|
||||||
random.randint(0, 255))
|
random.randint(0, 255))
|
||||||
|
|
||||||
|
# effect selection
|
||||||
elif effect in EFFECT_MAP:
|
elif effect in EFFECT_MAP:
|
||||||
self._bulb.setPresetPattern(EFFECT_MAP[effect], 50)
|
self._bulb.setPresetPattern(EFFECT_MAP[effect], 50)
|
||||||
|
|
||||||
|
# white change only
|
||||||
|
elif white is not None:
|
||||||
|
self._bulb.setWarmWhite255(white)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the specified or all lights off."""
|
"""Turn the specified or all lights off."""
|
||||||
self._bulb.turnOff()
|
self._bulb.turnOff()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user