-
-
Notifications
You must be signed in to change notification settings - Fork 37.3k
Address inconsistent behavior on flux_led component #14713
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28221ae
Address inconsistent behavior between different controllers.
oblogic7 5877753
Add white mode for Flux LED
oblogic7 4cd29fb
Merge remote-tracking branch 'upstream/dev' into flux_bug_fix_2.1
oblogic7 0ca1c40
Call _bulb.turnOn() after bulb properties have been set to prevent im…
oblogic7 0cedda0
Only use existing brightness if rgb is None to prevent unexpected rec…
oblogic7 2cd2265
Remove blank line
oblogic7 d3800ee
Undo change so current brightness is used in all cases.
oblogic7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ | |
| 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 @@ | |
| 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 @@ def is_on(self): | |
| @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 @@ def hs_color(self): | |
| @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 @@ def effect_list(self): | |
|
|
||
| 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 @@ def turn_on(self, **kwargs): | |
| 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() | ||
|
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. Can you confirm that
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. Yes, it does. |
||
|
|
||
| def turn_off(self, **kwargs): | ||
| """Turn the specified or all lights off.""" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Could you confirm that calling turn_on(rgb=[5,0,0], brighness=None) will really set the RGB color to [5,0,0] and not to [255,0,0] or anything else deformed by the previous brightness settings you re-use on line 254 ?
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.
Finally had a chance to test this and I found some inconsistent behavior. However, it appears that it is not with the handling of the values by the flux component, but some issue with the way the values are passed into
turn_on.I used the following payload to test:
rgb_coloris being converted tohs_colorbefore being passed into theturn_onmethod. The flux component then usescolor_util.color_hs_to_RGBto convert into a tuple of rgb values. This conversion results in0,255,0for the payload above instead of the expected0,5,0. This is the source of the inconsistent behavior that I'm experiencing.The flux library will only recalculate rgb values if a numeric value is passed for brightness. If
Noneis passed, then it does not recalculate. I am making a change so that existing brightness value is only passed ifrgb is None. This should prevent unexpected recalculation of the brightness when brightness is not included on the payload.I'm not familiar enough with HA internals to know where to fix the hs_color bug mentioned above.
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.
@oblogic7: Thanks for investigating furhter !
It seems that this breakage that changes rgb_color [0,5,0] to [0,255,0] has been introduced in PR #11288.
@armills: any clues/suggestions how to fix that ?
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.
After digging through the discussion on #11288, I see that @amelchio calls out this bug specifically.
https://github.com/home-assistant/home-assistant/pull/11288/files/1ee6a9f786c0508a7079aa2eaf282e03b2b83c9d#r175284144
I'm still checking out the changes, but I don't think the fix will be implemented on components unless there have been updates since that PR was merged. Maybe a new method has been added that I haven't found yet? If not, it looks to me like it will require more changes to the conversion methods.
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.
Popping in because I was tagged. I did not read all of these comments and I don't have flux_led hardware. Still, if you have specific questions about how things should work, I might be able to help.
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.
@amelchio Are you aware of a fix or work around for the issue that you point out here: https://github.com/home-assistant/home-assistant/pull/11288/files/1ee6a9f786c0508a7079aa2eaf282e03b2b83c9d#r175284144
If not, do you know if it will be a component level change or if it will be more involved?
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.
After #11288, the intention is that
rgb_colorno longer changes the brightness. Soturn_on(rgb=[5,0,0], brighness=None)andturn_on(rgb=[255,0,0], brighness=None)should act in the same way: set the light to red with the current brightness level.This must be implemented in each light platform, like
flux_led.pyin this case, andseems like a reasonable way to achive that.
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.
Great. That is how it was implemented. I will roll back the last change so that the current brightness is used. Thanks!