-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
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
Merged
Merged
Fix flux_led only-white controllers (and remove explicit declaration as RGBW in automatic add) #22210
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
08e9322
Remove explicit declaration of automatic found devices as RGBW
5f9ccd2
fixes for Magic Home only-white controllers
e23c366
mode is now set to None instead of removed entirely
52cb222
flux_led now changes no values when turned on from off state.
b66a628
Merge 'upstream/dev'
amelchio 05d8200
better checking for changed values in turn_on
0254abb
Merge branch 'flux_led_fix' of github.com:autinerd/home-assistant int…
f568097
Reduce waiting time to 1 second
b46cbbe
Correction of turn on logic
afd673d
Merge branch 'flux_led_fix' of github.com:autinerd/home-assistant int…
f780d73
Remove accidentally inserted 'not'
f104fc0
Remove lint
amelchio b476390
Remove redundant code
amelchio 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 |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -253,16 +253,15 @@ def effect(self): | |
| for effect, code in EFFECT_MAP.items(): | ||
| if current_mode == code: | ||
| return effect | ||
|
|
||
| return None | ||
|
|
||
| async def async_turn_on(self, **kwargs): | ||
| """Turn the specified or all lights on and wait for state.""" | ||
| await self.hass.async_add_executor_job(partial(self._turn_on, | ||
| **kwargs)) | ||
| # The bulb needs a second to tell its new values, | ||
| # so we wait 2 seconds before updating | ||
| await sleep(2) | ||
| # The bulb needs a bit to tell its new values, | ||
| # so we wait 1 second before updating | ||
| await sleep(1) | ||
|
|
||
| def _turn_on(self, **kwargs): | ||
| """Turn the specified or all lights on.""" | ||
|
|
@@ -273,55 +272,47 @@ def _turn_on(self, **kwargs): | |
| effect = kwargs.get(ATTR_EFFECT) | ||
| white = kwargs.get(ATTR_WHITE_VALUE) | ||
|
|
||
| # 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" | ||
| " an effect is specified for a flux bulb") | ||
|
|
||
| # Random color effect | ||
| if effect == EFFECT_RANDOM: | ||
| self._bulb.setRgb(random.randint(0, 255), | ||
| random.randint(0, 255), | ||
| random.randint(0, 255)) | ||
| if all(item is None for item in [hs_color, brightness, effect, white]): | ||
| return | ||
|
|
||
| if effect == EFFECT_CUSTOM: | ||
| if self._custom_effect: | ||
| self._bulb.setCustomPattern( | ||
| self._custom_effect[CONF_COLORS], | ||
| self._custom_effect[CONF_SPEED_PCT], | ||
| self._custom_effect[CONF_TRANSITION]) | ||
| # 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 | ||
|
|
||
| # Effect selection | ||
| if effect in EFFECT_MAP: | ||
| self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) | ||
| if effect is not None: | ||
| # Random color effect | ||
| if effect == EFFECT_RANDOM: | ||
| self._bulb.setRgb(random.randint(0, 255), | ||
| random.randint(0, 255), | ||
| random.randint(0, 255)) | ||
| elif effect == EFFECT_CUSTOM: | ||
| if self._custom_effect: | ||
| self._bulb.setCustomPattern( | ||
| self._custom_effect[CONF_COLORS], | ||
| self._custom_effect[CONF_SPEED_PCT], | ||
| self._custom_effect[CONF_TRANSITION]) | ||
| # Effect selection | ||
| elif effect in EFFECT_MAP: | ||
| self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) | ||
| return | ||
|
|
||
| # Preserve current brightness on color/white level change | ||
| if brightness is None: | ||
| brightness = self.brightness | ||
|
|
||
| if hs_color: | ||
| self._color = (hs_color[0], hs_color[1], brightness / 255 * 100) | ||
| elif brightness and (hs_color is None) and self._mode != MODE_WHITE: | ||
| 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) | ||
|
|
||
| if hs_color is not None: | ||
| if brightness is None: | ||
|
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. Move this block into the |
||
| brightness = self.brightness | ||
| color = (hs_color[0], hs_color[1], brightness / 255 * 100) | ||
| elif brightness is not None: | ||
| color = (self._color[0], self._color[1], | ||
| brightness / 255 * 100) | ||
| # 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)) | ||
| self._bulb.setRgbw(*color_util.color_hsv_to_RGB(*color)) | ||
| else: | ||
| self._bulb.setRgbw(w=white) | ||
| # handle RGB mode | ||
| else: | ||
| self._bulb.setRgb(*color_util.color_hsv_to_RGB(*self._color)) | ||
| return | ||
| self._bulb.setRgb(*color_util.color_hsv_to_RGB(*color)) | ||
|
|
||
| def turn_off(self, **kwargs): | ||
| """Turn the specified or all lights off.""" | ||
|
|
@@ -333,10 +324,6 @@ def update(self): | |
| try: | ||
| self._connect() | ||
| self._error_reported = False | ||
| if 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] | ||
| except socket.error: | ||
| self._disconnect() | ||
| if not self._error_reported: | ||
|
|
@@ -345,7 +332,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] | ||
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.
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)