Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add)#22210
Conversation
amelchio
left a comment
There was a problem hiding this comment.
This is tricky, we need to find someone that can test it.
| if ipaddr in light_ips: | ||
| continue | ||
| device['name'] = '{} {}'.format(device['id'], ipaddr) | ||
| device[ATTR_MODE] = MODE_RGBW |
There was a problem hiding this comment.
The device[ATTR_MODE] value is always read in __init__() so this will make it always raise an exception. I think it could work if you set it to None instead.
Just a note for others, the mode is set automatically if not explicitly defined: https://github.com/home-assistant/home-assistant/blob/08e93224e0689c9a20a2b6b43057f60348bb7c14/homeassistant/components/flux_led/light.py#L185-L191
(whether that works for all devices, I don't know)
|
Great. I can review after the weekend. Meanwhile, is this tested with affected devices? |
|
The problem is that I don't have a only-white controller, so I can't test it. The behaviour for other types has not changed. |
| if not self.is_on: | ||
| self._bulb.turnOn() | ||
| if kwargs.get(ATTR_BRIGHTNESS) is None: | ||
| return |
There was a problem hiding this comment.
This is wrong. I think you are addressing a UI issue but we can turn on with any parameters using light.turn_on.
Also, preferably turn on unconditionally because our local state could be stale.
I am not quite sure what you are trying to do so I cannot advise on a better way :)
There was a problem hiding this comment.
One (in my opinion) not so optimal thing is, that turn_on is for turning stuff on and changing the state of an entity. What I want to do is that when the lamp is off and the user want to turn it on, it just turns on and nothing else (except when brightness is set, because it's possible to turn the light on with the brightness slider as well). When the lamp is already on, then the state should be changed.
There was a problem hiding this comment.
Yes, light.turn_on is indeed overloaded but each light platform should not work around that. It is quite possible to turn on to an RGB color, for example with an automation.
Instead, only call self._bulb.setRgb() and friends if relevant kwargs are actually passed.
There was a problem hiding this comment.
Oh yeah, I forgot the automation, thank you. I will correct this.
|
I will test the stuff in the evening at home. |
|
So, I have now tested the changes, they are fully working for RGBW devices (now waiting time is reduced to 1 second as well, this is enough) |
amelchio
left a comment
There was a problem hiding this comment.
This is getting really complex, so many cases to handle :-(. I have some proposals that I think will simplify the code a bit.
| def _turn_on(self, **kwargs): | ||
| """Turn the specified or all lights on.""" | ||
| self._bulb.turnOn() | ||
| if not self.is_on: |
There was a problem hiding this comment.
Is there a reason for this condition? As I said, the state can be stale so it is better to not trust it.
| self._custom_effect[CONF_COLORS], | ||
| self._custom_effect[CONF_SPEED_PCT], | ||
| self._custom_effect[CONF_TRANSITION]) | ||
| if all(None for item in [hs_color, brightness, effect, white]): |
There was a problem hiding this comment.
That looks weird, it will never be true? You probably meant it like this:
if all(item is None for item in [hs_color, brightness, effect, white]):| # handle RGB mode | ||
| if brightness is not None: | ||
| self._bulb.setWarmWhite255(brightness) | ||
| return |
There was a problem hiding this comment.
Unindent this return and remove the else: below
| self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) | ||
| return | ||
| # Preserve current brightness on color/white level change | ||
| if brightness is None: |
There was a problem hiding this comment.
Move this block into the if hs_color is not None: below.
|
|
||
| if hs_color is not None: | ||
| color = (hs_color[0], hs_color[1], brightness / 255 * 100) | ||
| elif brightness is not None and hs_color is None: |
There was a problem hiding this comment.
Remove and hs_color is None, that's the "else" part of the "elif".
amelchio
left a comment
There was a problem hiding this comment.
Thanks, I think that improved the readability. One issue left though.
| return | ||
| # Preserve current brightness on color/white level change | ||
| if hs_color is not None: | ||
| if brightness is not None: |
There was a problem hiding this comment.
Should be if brightness is None.
There was a problem hiding this comment.
Thank you very much for your patience 😅
amelchio
left a comment
There was a problem hiding this comment.
Looks good now, I just moved some code to fix a too long line.
It would still be good to get someone to test the fixes with the light types that you do not have around.
|
Actually, can we just remove the bit that I moved since the same code seems to be present a bit further down in |
|
Oh yeah, thank you, I was just a bit confused. Thank you very much and hopefully there are no more problems with the logic of this component! |
|
So since a few flux updates ago, my RGBW Led Strip has started 'toggling' between RGB and W. This problem was introduced several months ago but fixed. I was hoping that it would get fixed with this PR but sadly not. Essentially it can't light all 4 channels at once - turning on the W turns off the RGB and vice versa. |
|
I think it makes sense to turn off RGB when setting W and vice-versa. However, if setting both, we should allow that. I think there is an inconclusive architecture issue about this behavior :-/ Anyway, please file a new GitHub issue about this since we should not be discussing in closed tickets. |
This reverts commit 4813818.
* Revert Black * Revert "Introduce support for color temperature (#25503)" This reverts commit e1d884a. * Revert "Fix flux_led only-white controllers (#22210)" This reverts commit 4813818. * Revert "Fix MagicHome LEDs with flux_led component (#20733)" This reverts commit 1444a68. * Re-Black * Use mode detection for scanned bulbs
* Revert Black * Revert "Introduce support for color temperature (#25503)" This reverts commit e1d884a. * Revert "Fix flux_led only-white controllers (#22210)" This reverts commit 4813818. * Revert "Fix MagicHome LEDs with flux_led component (#20733)" This reverts commit 1444a68. * Re-Black * Use mode detection for scanned bulbs
Description:
When using only-white Magic Home controllers, the update routine didn't work properly. Now only-white controllers are treated as before my update for RGBW controllers.
Old description:
When flux_led devices are found with automatic discovery, they are automatically seen as RGBW devices, even when they are actually RGB devices, This pull request fixes this issue.
Issue #22161 will be completely fixed in the next pull request, because it needs an update to the
flux_ledmodule as wellRelated issue (if applicable): fixes #22405
Checklist:
tox. Your PR cannot be merged unless tests passIf the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: