Skip to content

Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add)#22210

Merged
balloob merged 13 commits into
home-assistant:devfrom
autinerd:flux_led_fix
Apr 16, 2019
Merged

Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add)#22210
balloob merged 13 commits into
home-assistant:devfrom
autinerd:flux_led_fix

Conversation

@autinerd
Copy link
Copy Markdown
Contributor

@autinerd autinerd commented Mar 20, 2019

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_led module as well

Related issue (if applicable): fixes #22405

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@ghost ghost added the in progress label Mar 20, 2019
Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@autinerd autinerd changed the title Remove explicit declaration of automatic found devices as RGBW in flux_led Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add) Apr 4, 2019
@autinerd
Copy link
Copy Markdown
Contributor Author

autinerd commented Apr 5, 2019

@amelchio this pull request shall remove the bug from #22405 and my previous pull request

@amelchio
Copy link
Copy Markdown
Contributor

amelchio commented Apr 5, 2019

Great. I can review after the weekend. Meanwhile, is this tested with affected devices?

@autinerd
Copy link
Copy Markdown
Contributor Author

autinerd commented Apr 5, 2019

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.

@ghost ghost assigned amelchio Apr 9, 2019
if not self.is_on:
self._bulb.turnOn()
if kwargs.get(ATTR_BRIGHTNESS) is None:
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I forgot the automation, thank you. I will correct this.

@autinerd
Copy link
Copy Markdown
Contributor Author

I will test the stuff in the evening at home.

@autinerd
Copy link
Copy Markdown
Contributor Author

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)

Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove and hs_color is None, that's the "else" part of the "elif".

Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be if brightness is None.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your patience 😅

Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@amelchio
Copy link
Copy Markdown
Contributor

Actually, can we just remove the bit that I moved since the same code seems to be present a bit further down in update()?

@balloob
Copy link
Copy Markdown
Member

balloob commented Apr 15, 2019

@autinerd I think that when @amelchio said "we", he meant that it's a change you should make to get this PR approved.

@balloob balloob merged commit 4813818 into home-assistant:dev Apr 16, 2019
@ghost ghost removed the in progress label Apr 16, 2019
@autinerd
Copy link
Copy Markdown
Contributor Author

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!

@kineticscreen
Copy link
Copy Markdown

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.

@amelchio
Copy link
Copy Markdown
Contributor

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.

amelchio added a commit to amelchio/home-assistant that referenced this pull request Aug 2, 2019
@amelchio amelchio mentioned this pull request Aug 2, 2019
4 tasks
pvizeli pushed a commit that referenced this pull request Aug 2, 2019
* 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
balloob pushed a commit that referenced this pull request Aug 5, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flux_Led Not working with single colour Magic Home led controller since 0.90

5 participants