Skip to content

Fix Avea color state refresh#171003

Merged
joostlek merged 4 commits into
home-assistant:devfrom
pattyland:avea-bugfix-color-update
May 18, 2026
Merged

Fix Avea color state refresh#171003
joostlek merged 4 commits into
home-assistant:devfrom
pattyland:avea-bugfix-color-update

Conversation

@pattyland
Copy link
Copy Markdown
Contributor

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

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

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_color on 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)
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.

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.

Comment thread tests/components/avea/test_light.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread homeassistant/components/avea/light.py Outdated
Copilot AI review requested due to automatic review settings May 17, 2026 21:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

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

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.

Comment thread tests/components/avea/test_light.py Outdated
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@joostlek joostlek merged commit ad04aec into home-assistant:dev May 18, 2026
33 checks passed
@pattyland pattyland deleted the avea-bugfix-color-update branch May 18, 2026 12:21
jnimmo pushed a commit to jnimmo/core that referenced this pull request May 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants