Fix Avea color state refresh#171003
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Avea light entity to explicitly connect/disconnect during state refresh and adds color state validation in tests.
Changes:
- Add connect/disconnect lifecycle around
update()state fetches. - Read RGB from the device and expose
hs_coloron the entity. - Extend tests to mock RGB/connection behavior and assert call ordering + HS color.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/components/avea/test_light.py | Updates mocks and assertions to cover connection + RGB/HS color behavior during update. |
| homeassistant/components/avea/light.py | Connects before reading brightness/RGB, disconnects after, and sets HS color based on RGB. |
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b3e6bb8a4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 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) |
There was a problem hiding this comment.
This is the same concern as the earlier RGB thread. I am keeping the production code unchanged here because avea.Bulb.get_rgb() returns an RGB 3-tuple by contract, including when it falls back to cached values after a failed connection attempt.
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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Proposed change
Fix Avea light state refresh so color is updated together with brightness during a Home Assistant entity update.
Avea requires separate BLE requests for brightness and color, so this keeps those device-level reads separate. The update now opens one BLE connection, reads brightness and RGB color within the same refresh, then updates the Home Assistant light state with both brightness and
hs_color.Previously, Avea only refreshed brightness in
update(). If the color changed outside Home Assistant, the entity state could report fresh brightness with stale or missing color data.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: