Skip to content

Fix swallowed exceptions in deconz actions - #175646

Merged
justanotherariel merged 23 commits into
home-assistant:devfrom
mattreim:Fix-swallowed-exceptions-in-deconz-actions
Jul 6, 2026
Merged

Fix swallowed exceptions in deconz actions#175646
justanotherariel merged 23 commits into
home-assistant:devfrom
mattreim:Fix-swallowed-exceptions-in-deconz-actions

Conversation

@mattreim

@mattreim mattreim commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Breaking change

Proposed change

This PR is the starting point for fixing issue #170606, as I haven't tested it yet.

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:

Copilot AI review requested due to automatic review settings July 4, 2026 23:28
@mattreim
mattreim requested a review from Kane610 as a code owner July 4, 2026 23:28
@home-assistant

home-assistant Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of deconz 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 deconz 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses issue #170606 by fixing swallowed exceptions in the deCONZ integration's action handlers. Previously, several except blocks in services.py only logged errors and returned, so failed actions gave the user no UI feedback and automations continued as if the action succeeded. The change re-raises HomeAssistantError with translated messages instead, and removes the associated pylint: disable-next=home-assistant-action-swallowed-exception suppressions.

Changes:

  • Replaced log-and-return error handling in async_call_deconz_service, async_configure_service, and async_refresh_devices_service with raised HomeAssistantErrors using new translation keys.
  • Added an exceptions block to strings.json with five translation keys (gateway_not_found, no_master_gateway, entity_not_found, configure_failed, device_refresh_failed).
  • Updated existing service tests to assert that HomeAssistantError is now raised (using blocking=True and pytest.raises).

Reviewed changes

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

File Description
homeassistant/components/deconz/services.py Re-raises HomeAssistantError instead of logging-and-returning; refactors bridge lookup and wraps API calls in try/except; drops unused LOGGER import.
homeassistant/components/deconz/strings.json Adds exceptions translation keys referenced by the new error handling.
tests/components/deconz/test_services.py Updates failure-path tests to expect HomeAssistantError with blocking=True.

Notes for the author: the two except Exception catches are broader than the integration's established convention (hub/api.py:35, config_flow.py:161 catch (TimeoutError, errors.RequestError, errors.ResponseError)) and will mask unexpected errors; moving load_ignored_devices() into finally changes behavior on refresh failures; and the new configure_failed/device_refresh_failed branches are not yet covered by tests (consistent with the PR description noting it is untested).

Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py
Comment thread homeassistant/components/deconz/services.py Outdated
Copilot AI review requested due to automatic review settings July 4, 2026 23:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py
Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py
Copilot AI review requested due to automatic review settings July 5, 2026 00:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread homeassistant/components/deconz/services.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 5, 2026 00:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread tests/components/deconz/test_services.py Outdated
Comment thread homeassistant/components/deconz/services.py
Comment thread homeassistant/components/deconz/services.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 5, 2026 00:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/deconz/services.py
Comment thread homeassistant/components/deconz/services.py
Copilot AI review requested due to automatic review settings July 5, 2026 10:30
Copilot AI review requested due to automatic review settings July 5, 2026 23:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread tests/components/deconz/conftest.py Outdated
Comment thread tests/components/deconz/conftest.py Outdated
Comment thread tests/components/deconz/test_services.py Outdated
Comment thread tests/components/deconz/test_services.py Outdated
Copilot AI review requested due to automatic review settings July 5, 2026 23:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread tests/components/deconz/test_services.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 July 6, 2026 00:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated no new comments.

@mattreim

mattreim commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@Kane610 Copilot is satisfied for now, and the tests are running successfully, so we can move on to the next step. What do you think?

Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py Outdated
Comment thread homeassistant/components/deconz/services.py Outdated
Comment on lines 114 to 200
@@ -122,9 +125,15 @@ async def test_configure_service_with_faulty_bridgeid(
SERVICE_DATA: {"on": True},
}

await hass.services.async_call(DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data)
await hass.async_block_till_done()
with pytest.raises(HomeAssistantError) as err:
await hass.services.async_call(
DOMAIN,
SERVICE_CONFIGURE_DEVICE,
service_data=data,
blocking=True,
)

assert err.value.translation_key == "gateway_not_found"
assert len(aioclient_mock.mock_calls) == 0


@@ -141,26 +150,35 @@ async def test_configure_service_with_faulty_field(hass: HomeAssistant) -> None:

@pytest.mark.usefixtures("config_entry_setup")
async def test_configure_service_with_faulty_entity(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test that service on a non existing entity."""
"""Test that service fails on a non-existing entity."""
aioclient_mock.clear_requests()

data = {
SERVICE_ENTITY: "light.nonexisting",
SERVICE_DATA: {},
}

await hass.services.async_call(DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data)
await hass.async_block_till_done()
with pytest.raises(HomeAssistantError) as err:
await hass.services.async_call(
DOMAIN,
SERVICE_CONFIGURE_DEVICE,
service_data=data,
blocking=True,
)

assert err.value.translation_key == "entity_not_found"
assert err.value.translation_placeholders == {"entity_id": "light.nonexisting"}
assert len(aioclient_mock.mock_calls) == 0


@pytest.mark.parametrize("config_entry_options", [{CONF_MASTER_GATEWAY: False}])
@pytest.mark.usefixtures("config_entry_setup")
async def test_calling_service_with_no_master_gateway_fails(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test that service call fails when no master gateway exist."""
aioclient_mock.clear_requests()
@@ -170,9 +188,15 @@ async def test_calling_service_with_no_master_gateway_fails(
SERVICE_DATA: {"on": True},
}

await hass.services.async_call(DOMAIN, SERVICE_CONFIGURE_DEVICE, service_data=data)
await hass.async_block_till_done()
with pytest.raises(HomeAssistantError) as err:
await hass.services.async_call(
DOMAIN,
SERVICE_CONFIGURE_DEVICE,
service_data=data,
blocking=True,
)

assert err.value.translation_key == "no_master_gateway"
assert len(aioclient_mock.mock_calls) == 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These could be merged/parameterized

@home-assistant
home-assistant Bot marked this pull request as draft July 6, 2026 08:37
@home-assistant

home-assistant Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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.

@mattreim

mattreim commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@justanotherariel Thank you very much for your help, and I hope it's okay now.

@mattreim
mattreim marked this pull request as ready for review July 6, 2026 10:36
Copilot AI review requested due to automatic review settings July 6, 2026 10:36
@home-assistant
home-assistant Bot requested a review from justanotherariel July 6, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/deconz/services.py
Comment thread homeassistant/components/deconz/services.py

@Kane610 Kane610 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@justanotherariel justanotherariel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You did a bit more than I asked for regarding the error types - not everything should be a ServiceValidationError. Fixed it for you. Looks good now.

@justanotherariel
justanotherariel merged commit 7678cf9 into home-assistant:dev Jul 6, 2026
29 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 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.

4 participants