Code improvements for Home Connect#172024
Open
Diegorro98 wants to merge 3 commits into
Open
Conversation
Contributor
|
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
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR refactors Home Connect error handling by introducing a shared helper for raising translated HomeAssistantErrors, updates several entities/services to use it, and aligns test platform fixtures with Platform typing.
Changes:
- Add
raise_service_error()helper and replace repeated translatedHomeAssistantErrorconstruction across entities/services. - Prevent duplicate option-entity listeners from being registered per appliance.
- Update Home Connect test fixtures to type platforms as
list[Platform]and reorder/extendservices.yamlprogram options.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/components/home_connect/test_switch.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_sensor.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_select.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_number.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_light.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_fan.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_entity.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_coordinator.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_climate.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_button.py | Adjust platform fixture typing to Platform. |
| tests/components/home_connect/test_binary_sensor.py | Adjust platform fixture typing to Platform. |
| homeassistant/components/home_connect/utils.py | Add raise_service_error() helper for translated errors. |
| homeassistant/components/home_connect/switch.py | Use raise_service_error() instead of inline translated errors. |
| homeassistant/components/home_connect/services.yaml | Reorder/extend supported program translation keys. |
| homeassistant/components/home_connect/services.py | Use raise_service_error() for service exceptions. |
| homeassistant/components/home_connect/select.py | Use raise_service_error() and remove inline error construction boilerplate. |
| homeassistant/components/home_connect/number.py | Use raise_service_error() for setting failures. |
| homeassistant/components/home_connect/light.py | Use raise_service_error() for light command failures. |
| homeassistant/components/home_connect/entity.py | Use raise_service_error() for option-setting failures. |
| homeassistant/components/home_connect/common.py | Avoid registering duplicate listeners per appliance. |
| homeassistant/components/home_connect/climate.py | Use raise_service_error() for climate command failures. |
| homeassistant/components/home_connect/button.py | Use raise_service_error() for button command failures. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+111
to
136
| if not ( | ||
| callbacks_for_appliance := changed_options_listener_remove_callbacks[ | ||
| appliance_ha_id | ||
| ] | ||
| ): | ||
| changed_options_listener_remove_callback = ( | ||
| appliance_coordinator.async_add_listener( | ||
| partial( | ||
| _create_option_entities, | ||
| entity_registry, | ||
| appliance_coordinator, | ||
| known_entity_unique_ids, | ||
| get_option_entities_for_appliance, | ||
| async_add_entities, | ||
| ), | ||
| event_key, | ||
| for event_key in ( | ||
| EventKey.BSH_COMMON_ROOT_ACTIVE_PROGRAM, | ||
| EventKey.BSH_COMMON_ROOT_SELECTED_PROGRAM, | ||
| ): | ||
| changed_options_listener_remove_callback = ( | ||
| appliance_coordinator.async_add_listener( | ||
| partial( | ||
| _create_option_entities, | ||
| entity_registry, | ||
| appliance_coordinator, | ||
| known_entity_unique_ids, | ||
| get_option_entities_for_appliance, | ||
| async_add_entities, | ||
| ), | ||
| event_key, | ||
| ) | ||
| ) | ||
| entry.async_on_unload(changed_options_listener_remove_callback) | ||
| callbacks_for_appliance.append( | ||
| changed_options_listener_remove_callback | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
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: