-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Fix Avea color state refresh #171003
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 Avea color state refresh #171003
Changes from all commits
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 |
|---|---|---|
|
|
@@ -193,6 +193,16 @@ def turn_off(self, **kwargs: Any) -> None: | |
|
|
||
| def update(self) -> None: | ||
| """Fetch new state data for this light.""" | ||
| if (brightness := self._light.get_brightness()) is not None: | ||
| connected = self._light.connect() | ||
|
|
||
| try: | ||
| brightness = self._light.get_brightness() | ||
| rgb_color = self._light.get_rgb() | ||
| finally: | ||
| if connected: | ||
| self._light.disconnect() | ||
|
|
||
| if brightness is not None: | ||
| self._attr_is_on = brightness != 0 | ||
| self._attr_brightness = round(255 * (brightness / 4095)) | ||
| self._attr_hs_color = color_util.color_RGB_to_hs(*rgb_color) | ||
|
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. This is the same concern as the earlier RGB thread. I am keeping the production code unchanged here because The failed pre-connect fallback path is now covered by test, so we verify that brightness and color are both still applied from the returned cached values. Adding a guard that skips only color would allow mixed-freshness state, which this PR is trying to avoid. |
||
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.
avea.Bulb.get_rgb()returns a 3-tuple of integer RGB values by contract. I do not plan to add a guard here unless you want explicit validation despite that contract.The reason is that applying a fresh brightness value while skipping a failed color refresh would publish mixed-freshness state, which is the inconsistency this bugfix is trying to avoid. If the RGB read/conversion unexpectedly fails, failing the whole refresh is preferable to updating only part of the light state.