-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add) #22210
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
Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add) #22210
Changes from 5 commits
08e9322
5f9ccd2
e23c366
52cb222
b66a628
05d8200
0254abb
f568097
b46cbbe
afd673d
f780d73
f104fc0
b476390
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 |
|---|---|---|
|
|
@@ -146,7 +146,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): | |
| if ipaddr in light_ips: | ||
| continue | ||
| device['name'] = '{} {}'.format(device['id'], ipaddr) | ||
| device[ATTR_MODE] = MODE_RGBW | ||
| device[ATTR_MODE] = None | ||
| device[CONF_PROTOCOL] = None | ||
| device[CONF_CUSTOM_EFFECT] = None | ||
| light = FluxLight(device) | ||
|
|
@@ -266,13 +266,21 @@ async def async_turn_on(self, **kwargs): | |
|
|
||
| def _turn_on(self, **kwargs): | ||
| """Turn the specified or all lights on.""" | ||
| self._bulb.turnOn() | ||
| if not self.is_on: | ||
|
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. Is there a reason for this condition? As I said, the state can be stale so it is better to not trust it. |
||
| self._bulb.turnOn() | ||
| if kwargs.get(ATTR_BRIGHTNESS) is None: | ||
| return | ||
|
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. This is wrong. I think you are addressing a UI issue but we can turn on with any parameters using 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 :)
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. One (in my opinion) not so optimal thing is, that
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. Yes, Instead, only call
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. Oh yeah, I forgot the automation, thank you. I will correct this. |
||
|
|
||
| hs_color = kwargs.get(ATTR_HS_COLOR) | ||
| brightness = kwargs.get(ATTR_BRIGHTNESS) | ||
| effect = kwargs.get(ATTR_EFFECT) | ||
| white = kwargs.get(ATTR_WHITE_VALUE) | ||
|
|
||
| # handle W only mode (use brightness instead of white value) | ||
| if self._mode == MODE_WHITE: | ||
| self._bulb.setWarmWhite255(brightness) | ||
| return | ||
|
|
||
| # Show warning if effect set with rgb, brightness, or white level | ||
| if effect and (brightness or white or hs_color): | ||
| _LOGGER.warning("RGB, brightness and white level are ignored when" | ||
|
|
@@ -284,7 +292,6 @@ def _turn_on(self, **kwargs): | |
| random.randint(0, 255), | ||
| random.randint(0, 255)) | ||
| return | ||
|
|
||
| if effect == EFFECT_CUSTOM: | ||
| if self._custom_effect: | ||
| self._bulb.setCustomPattern( | ||
|
|
@@ -308,12 +315,8 @@ def _turn_on(self, **kwargs): | |
| self._color = (self._color[0], self._color[1], | ||
| brightness / 255 * 100) | ||
|
|
||
| # 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: | ||
| if self._mode == MODE_RGBW: | ||
| if white is None: | ||
| self._bulb.setRgbw(*color_util.color_hsv_to_RGB(*self._color)) | ||
| else: | ||
|
|
@@ -333,7 +336,7 @@ def update(self): | |
| try: | ||
| self._connect() | ||
| self._error_reported = False | ||
| if self._bulb.getRgb() != (0, 0, 0): | ||
| if self._mode != MODE_WHITE and self._bulb.getRgb() != (0, 0, 0): | ||
| color = self._bulb.getRgbw() | ||
| self._color = color_util.color_RGB_to_hsv(*color[0:3]) | ||
| self._white_value = color[3] | ||
|
|
@@ -345,7 +348,9 @@ def update(self): | |
| self._error_reported = True | ||
| return | ||
| self._bulb.update_state(retry=2) | ||
| if self._bulb.getRgb() != (0, 0, 0): | ||
| if self._mode != MODE_WHITE and self._bulb.getRgb() != (0, 0, 0): | ||
| color = self._bulb.getRgbw() | ||
| self._color = color_util.color_RGB_to_hsv(*color[0:3]) | ||
| self._white_value = color[3] | ||
| elif self._mode == MODE_WHITE: | ||
| self._white_value = self._bulb.getRgbw()[3] | ||
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.
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 toNoneinstead.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)