Skip to content

Conversation

@Diegorro98
Copy link
Contributor

Proposed change

Use a coordinator per appliance in the Home Connect integration.

This will allow to improve a little bit the user experience (i.e. using the refresh service will not longer refresh all the appliances, instead it will refresh only the target appliance)

Also, some test have been improved and one test has been added while another test was deleted because wasn't testing anything different from what it was already tested

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @DavidMStraub, @MartinHjelmare, mind taking a look at this pull request as it has been labeled with an integration (home_connect) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of home_connect can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign home_connect Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
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

This PR refactors the Home Connect integration to use a coordinator per appliance instead of a single global coordinator. This architectural change improves user experience by enabling appliance-specific refresh operations rather than refreshing all appliances at once.

Key changes:

  • Introduces HomeConnectApplianceCoordinator for per-appliance data management
  • Refactors entity creation to use appliance-specific coordinators
  • Updates test framework to remove client_with_exception fixture and improve exception handling

Reviewed Changes

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

Show a summary per file
File Description
coordinator.py Introduces HomeConnectApplianceCoordinator and refactors main coordinator for per-appliance management
entity.py Updates base entity to work with appliance-specific coordinators
common.py Updates entity setup functions to use new coordinator structure
Platform files (switch.py, sensor.py, etc.) Updates all platform implementations to use appliance coordinators
Test files Removes client_with_exception fixture and improves exception handling in tests
init.py Updates setup logic to work with new coordinator architecture

Comment on lines +141 to 143
appliance_coordinator = self.appliance_coordinators.pop(
event_message.ha_id
)
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

When handling DEPAIRED events, the coordinator is removed from the dictionary but not properly cleaned up. The coordinator should have its resources cleaned up (e.g., stopping background tasks, removing listeners) before being removed.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Please comment on this. Don't we need to do anything more here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think cleaning listeners maybe. Should we clean also entities? I'm not sure how to do it.
Do you have any suggestion?

Copy link
Member

Choose a reason for hiding this comment

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

What do we want the lifecycle to be with the entities on the paired and depaired events? What should happen? Should they become unavailable, or should they be removed, on depaired event? What should happen on paired event?

Copy link
Contributor Author

@Diegorro98 Diegorro98 Feb 1, 2026

Choose a reason for hiding this comment

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

On paired event it should add new entities and on depaired event they should be removed.
But the entities are not there anymore after a depairing event; see test_paired_depaired_devices_flow test at each platform tests.
So, I'm not sure if we should do anything else. AFAIK, there's not much else to do, as there are not background tasks in the appliance coordinator and the entities are no longer present after depairing event.

Copy link
Member

@MartinHjelmare MartinHjelmare Feb 3, 2026

Choose a reason for hiding this comment

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

Ok. I've looked over the update coordinator base code. I'm worried that we're introducing a memory leak due to this registration:

if self.config_entry:
self.config_entry.async_on_unload(self.async_shutdown)

I think the config entry will hold a reference to the coordinator instance, and will not allow it to be garbage collected after we pop it here.

What would be good to shutdown is to cancel the debouncer job. There could be one if a user requested a refresh with the entity update service action. The rest we don't use since we don't refresh on a schedule.

async def async_shutdown(self) -> None:
"""Cancel any scheduled call, and ignore new runs."""
self._shutdown_requested = True
self._async_unsub_refresh()
self._async_unsub_shutdown()
self._debounced_refresh.async_shutdown()

The config_entry attribute is only useful for us to make sure that a reauth flow is created on ConfigEntryAuthFailed.

except ConfigEntryAuthFailed as err:
auth_failed = True
self.last_exception = err
if self.last_update_success:
if log_failures:
self.logger.error(
"Authentication failed while fetching %s data: %s",
self.name,
err,
)
self.last_update_success = False
if raise_on_auth_failed:
raise
if self.config_entry:
self.config_entry.async_start_reauth(self.hass)

On the other hand, on dev branch, we don't raise that exception after config entry setup, so maybe we don't actually need to connect the config entry to the application coordinators?

Copy link
Member

Choose a reason for hiding this comment

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

So in summary, I'd look into not passing the config_entry parameter to these coordinators, calling async_register_shutdown when setting up the coordinator, and calling async_shutdown here before popping the coordinator. Probably also shutdown the coordinator when unloading the config entry but we'd need to be able to remove any such listener here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, made these changes, seems to work well.
But I think I'm going to keep ConfigEntryAuthFailed, as it seems to work without config entry associated and shows a log which maybe is enough information for not very used feature in this integration, as it has the server sent events.

@home-assistant home-assistant bot marked this pull request as draft October 10, 2025 11:30
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@Diegorro98 Diegorro98 marked this pull request as ready for review October 10, 2025 14:54
@home-assistant home-assistant bot requested a review from joostlek October 10, 2025 14:54
@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Jan 13, 2026
@Diegorro98
Copy link
Contributor Author

Waiting for review and merge

@github-actions github-actions bot removed the stale label Jan 13, 2026
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

There are many changes to the tests that don't seem related to the PR topic. Eg why do we change from client_with_exception to client here? Can't that be another PR before or after this one?

Preferably there should be no changes at all to the tests in this PR.

@home-assistant home-assistant bot marked this pull request as draft January 29, 2026 20:50
to remove unneded changes on ffixtures and snapshots
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

There is a merge conflict.

@Diegorro98 Diegorro98 marked this pull request as ready for review February 1, 2026 18:24
@MartinHjelmare MartinHjelmare marked this pull request as draft February 3, 2026 14:23
@Diegorro98 Diegorro98 force-pushed the home_connect/appliance_coordinator branch from bedbcf5 to 12b88dc Compare February 3, 2026 23:45
@Diegorro98 Diegorro98 marked this pull request as ready for review February 3, 2026 23:52
@MartinHjelmare MartinHjelmare marked this pull request as draft February 4, 2026 12:29
@Diegorro98 Diegorro98 marked this pull request as ready for review February 4, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants