mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
improve handling of flux_led lights in RGBW mode (#7221)
allows simultaneous control of both RGB and White channels.
This commit is contained in:
parent
f20a81d0c5
commit
c14b829f27
@ -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_RGB_COLOR, ATTR_EFFECT, EFFECT_COLORLOOP,
|
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE,
|
||||||
EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
|
EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
|
||||||
SUPPORT_RGB_COLOR, Light,
|
SUPPORT_RGB_COLOR, SUPPORT_WHITE_VALUE, Light,
|
||||||
PLATFORM_SCHEMA)
|
PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
@ -27,7 +27,9 @@ ATTR_MODE = 'mode'
|
|||||||
|
|
||||||
DOMAIN = 'flux_led'
|
DOMAIN = 'flux_led'
|
||||||
|
|
||||||
SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
|
SUPPORT_FLUX_LED_RGB = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
|
||||||
|
SUPPORT_RGB_COLOR)
|
||||||
|
SUPPORT_FLUX_LED_RGBW = (SUPPORT_WHITE_VALUE | SUPPORT_EFFECT |
|
||||||
SUPPORT_RGB_COLOR)
|
SUPPORT_RGB_COLOR)
|
||||||
|
|
||||||
MODE_RGB = 'rgb'
|
MODE_RGB = 'rgb'
|
||||||
@ -180,7 +182,16 @@ class FluxLight(Light):
|
|||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
|
if self._mode == MODE_RGB:
|
||||||
return self._bulb.brightness
|
return self._bulb.brightness
|
||||||
|
return None # not used for RGBW
|
||||||
|
|
||||||
|
@property
|
||||||
|
def white_value(self):
|
||||||
|
"""Return the white value of this light between 0..255."""
|
||||||
|
if self._mode == MODE_RGBW:
|
||||||
|
return self._bulb.getRgbw()[3]
|
||||||
|
return None # not used for RGB
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rgb_color(self):
|
def rgb_color(self):
|
||||||
@ -190,7 +201,11 @@ class FluxLight(Light):
|
|||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return SUPPORT_FLUX_LED
|
if self._mode == MODE_RGBW:
|
||||||
|
return SUPPORT_FLUX_LED_RGBW
|
||||||
|
elif self._mode == MODE_RGB:
|
||||||
|
return SUPPORT_FLUX_LED_RGB
|
||||||
|
return 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect_list(self):
|
def effect_list(self):
|
||||||
@ -204,17 +219,23 @@ class FluxLight(Light):
|
|||||||
|
|
||||||
rgb = kwargs.get(ATTR_RGB_COLOR)
|
rgb = kwargs.get(ATTR_RGB_COLOR)
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
|
white_value = kwargs.get(ATTR_WHITE_VALUE)
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
|
||||||
if rgb is not None and brightness is not None:
|
if rgb is not None and brightness is not None:
|
||||||
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
|
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
|
||||||
|
elif rgb is not None and white_value is not None:
|
||||||
|
self._bulb.setRgbw(*tuple(rgb), w=white_value)
|
||||||
elif rgb is not None:
|
elif rgb is not None:
|
||||||
self._bulb.setRgb(*tuple(rgb))
|
# self.white_value and self.brightness are appropriately
|
||||||
|
# returning None for MODE_RGB and MODE_RGBW respectively
|
||||||
|
self._bulb.setRgbw(*tuple(rgb),
|
||||||
|
w=self.white_value,
|
||||||
|
brightness=self.brightness)
|
||||||
elif brightness is not None:
|
elif brightness is not None:
|
||||||
if self._mode == 'rgbw':
|
self._bulb.setRgb(*self.rgb_color, brightness=brightness)
|
||||||
self._bulb.setWarmWhite255(brightness)
|
elif white_value is not None:
|
||||||
elif self._mode == 'rgb':
|
self._bulb.setRgbw(*self.rgb_color, w=white_value)
|
||||||
(red, green, blue) = self._bulb.getRgb()
|
|
||||||
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),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user