-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Introduce support for color temperature #25503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,9 @@ | |
| from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL | ||
| from homeassistant.components.light import ( | ||
| ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE, | ||
| EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, | ||
| SUPPORT_COLOR, SUPPORT_WHITE_VALUE, Light, PLATFORM_SCHEMA) | ||
| ATTR_COLOR_TEMP, EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, | ||
| SUPPORT_EFFECT, SUPPORT_COLOR, SUPPORT_WHITE_VALUE, SUPPORT_COLOR_TEMP, | ||
| Light, PLATFORM_SCHEMA) | ||
| import homeassistant.helpers.config_validation as cv | ||
| import homeassistant.util.color as color_util | ||
|
|
||
|
|
@@ -27,7 +28,7 @@ | |
| DOMAIN = 'flux_led' | ||
|
|
||
| SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT | | ||
| SUPPORT_COLOR) | ||
| SUPPORT_COLOR | SUPPORT_COLOR_TEMP) | ||
|
|
||
| MODE_RGB = 'rgb' | ||
| MODE_RGBW = 'rgbw' | ||
|
|
@@ -36,6 +37,11 @@ | |
| # RGB value is ignored when this mode is specified. | ||
| MODE_WHITE = 'w' | ||
|
|
||
| # Constant color temp values for 2 flux_led special modes | ||
| # Warm-white and Cool-white. Details on #23704 | ||
| COLOR_TEMP_WARM_WHITE = 333 | ||
| COLOR_TEMP_COOL_WHITE = 250 | ||
|
yeralin marked this conversation as resolved.
|
||
|
|
||
| # List of supported effects which aren't already declared in LIGHT | ||
| EFFECT_RED_FADE = 'red_fade' | ||
| EFFECT_GREEN_FADE = 'green_fade' | ||
|
|
@@ -269,15 +275,19 @@ def _turn_on(self, **kwargs): | |
| brightness = kwargs.get(ATTR_BRIGHTNESS) | ||
| effect = kwargs.get(ATTR_EFFECT) | ||
| white = kwargs.get(ATTR_WHITE_VALUE) | ||
| color_temp = kwargs.get(ATTR_COLOR_TEMP) | ||
|
|
||
| if all(item is None for item in [hs_color, brightness, effect, white]): | ||
| if all(item is None for item in | ||
| [hs_color, brightness, effect, white, color_temp]): | ||
| return | ||
|
|
||
| # handle W only mode (use brightness instead of white value) | ||
| if self._mode == MODE_WHITE: | ||
| if brightness is not None: | ||
| self._bulb.setWarmWhite255(brightness) | ||
| return | ||
|
|
||
| # handle effects | ||
| if effect is not None: | ||
| # Random color effect | ||
| if effect == EFFECT_RANDOM: | ||
|
|
@@ -294,6 +304,20 @@ def _turn_on(self, **kwargs): | |
| elif effect in EFFECT_MAP: | ||
| self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) | ||
| return | ||
|
|
||
| # handle special modes | ||
| if color_temp is not None: | ||
| if brightness is None: | ||
| brightness = self.brightness | ||
| if color_temp == COLOR_TEMP_WARM_WHITE: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this magic value. Using the frontend slider will give erratic behavior when this value is hit. If only two temperatures are available I think it is better to decide a cutoff (like 3500 kelvin) and make all temperatures above/below the same. But I will be surprised if only two temperatures are available since mixing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot mix
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, maybe there is some product differentiation or maybe you found a bug. There is so much different flux_led hardware, I still don't think this is true for it all. For example, this commit suggests white mixing is possible. |
||
| self._bulb.setRgbw(w=brightness) | ||
| elif color_temp == COLOR_TEMP_COOL_WHITE: | ||
| self._bulb.setRgbw(w2=brightness) | ||
| else: | ||
| self._bulb.setRgbw( | ||
| *color_util.color_temperature_to_rgb(color_temp)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do this conversion, it gives poor results and setting RGB is not what
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, what can be the alternative?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always set some white light even if it is the wrong temperature. |
||
| return | ||
|
|
||
| # Preserve current brightness on color/white level change | ||
| if hs_color is not None: | ||
| if brightness is None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong as now we are advertising support for color temperature with RGB (not just RGBW).