Skip to content

Code improvements for Home Connect#172024

Open
Diegorro98 wants to merge 3 commits into
home-assistant:devfrom
Diegorro98:home_connect/code_improvements
Open

Code improvements for Home Connect#172024
Diegorro98 wants to merge 3 commits into
home-assistant:devfrom
Diegorro98:home_connect/code_improvements

Conversation

@Diegorro98
Copy link
Copy Markdown
Contributor

Proposed change

  • Short service.yaml programs
  • Encapsule HomeAssistantError rising from HomeConnectError
  • Fix the platform fixtures return type at tests
  • Skip re-registering listeners at common.py

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:

@home-assistant
Copy link
Copy Markdown
Contributor

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 mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from 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 update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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.

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 translated HomeAssistantError construction 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/extend services.yaml program 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.

Comment thread homeassistant/components/home_connect/number.py Outdated
Comment thread homeassistant/components/home_connect/switch.py Outdated
Comment thread homeassistant/components/home_connect/utils.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 24, 2026 07:47
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 22 out of 22 changed files in this pull request and generated 3 comments.

Comment thread homeassistant/components/home_connect/utils.py Outdated
Comment thread homeassistant/components/home_connect/utils.py Outdated
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
)
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