-
-
Notifications
You must be signed in to change notification settings - Fork 36.7k
Use a coordinator per appliance in Home Connect #152518
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
base: dev
Are you sure you want to change the base?
Use a coordinator per appliance in Home Connect #152518
Conversation
|
Hey there @DavidMStraub, @MartinHjelmare, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
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.
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
HomeConnectApplianceCoordinatorfor per-appliance data management - Refactors entity creation to use appliance-specific coordinators
- Updates test framework to remove
client_with_exceptionfixture 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 |
| appliance_coordinator = self.appliance_coordinators.pop( | ||
| event_message.ha_id | ||
| ) |
Copilot
AI
Sep 17, 2025
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.
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.
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.
Please comment on this. Don't we need to do anything more here?
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.
I think cleaning listeners maybe. Should we clean also entities? I'm not sure how to do it.
Do you have any suggestion?
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.
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?
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.
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.
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.
Ok. I've looked over the update coordinator base code. I'm worried that we're introducing a memory leak due to this registration:
core/homeassistant/helpers/update_coordinator.py
Lines 148 to 149 in 89f536e
| 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.
core/homeassistant/helpers/update_coordinator.py
Lines 202 to 207 in 89f536e
| 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.
core/homeassistant/helpers/update_coordinator.py
Lines 474 to 489 in 89f536e
| 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?
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.
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.
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.
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.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
…aising ConfigEntryNotReady at entry setup.
|
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. |
|
Waiting for review and merge |
MartinHjelmare
left a comment
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.
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.
to remove unneded changes on ffixtures and snapshots
…'s connected status Instead of any HomeConnectError while fetching all the data of the appliance
… not connected Instead of logging and return
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.
There is a merge conflict.
bedbcf5 to
12b88dc
Compare
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
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: