Fix swallowed exception in knx event_register action#171010
Merged
Merged
Conversation
Contributor
|
Hey there @Julius2342, @marvin-w, 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
This PR updates the KNX event_register service to raise a translated exception when removing non-registered group addresses, so failures aren’t silently logged and swallowed (fixes #170618).
Changes:
- Raise a translated exception when
knx.event_registeris called withremove: truefor unknown group addresses. - Add a new KNX translation key/message for this failure.
- Add a test asserting the exception details (translation domain/key/placeholders).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
homeassistant/components/knx/services.py |
Collects failed removals and raises a translated exception instead of logging a warning. |
homeassistant/components/knx/strings.json |
Adds a new exception translation key/message for failed event_register removals. |
tests/components/knx/test_services.py |
Adds coverage to ensure an error is raised (and translated) when removing an unregistered address. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
119
to
+137
| if call.data.get(SERVICE_KNX_ATTR_REMOVE): | ||
| _error_gas = set() | ||
| for group_address in group_addresses: | ||
| try: | ||
| knx_module.knx_event_callback.group_addresses.remove(group_address) | ||
| # pylint: disable-next=home-assistant-action-swallowed-exception | ||
| except ValueError: | ||
| _LOGGER.warning( | ||
| "Service event_register could not remove event for '%s'", | ||
| str(group_address), | ||
| ) | ||
| _error_gas.add(group_address) | ||
| if group_address in knx_module.group_address_transcoder: | ||
| del knx_module.group_address_transcoder[group_address] | ||
| return | ||
|
|
||
| if not _error_gas: | ||
| return | ||
| raise HomeAssistantError( | ||
| translation_domain=DOMAIN, | ||
| translation_key="service_event_register_ga_not_found", | ||
| translation_placeholders={ | ||
| "group_addresses": ", ".join(map(str, sorted(_error_gas))) | ||
| }, | ||
| ) |
Comment on lines
119
to
+125
| if call.data.get(SERVICE_KNX_ATTR_REMOVE): | ||
| _error_gas = set() | ||
| for group_address in group_addresses: | ||
| try: | ||
| knx_module.knx_event_callback.group_addresses.remove(group_address) | ||
| # pylint: disable-next=home-assistant-action-swallowed-exception | ||
| except ValueError: | ||
| _LOGGER.warning( | ||
| "Service event_register could not remove event for '%s'", | ||
| str(group_address), | ||
| ) | ||
| _error_gas.add(group_address) |
| "message": "KNX integration is not loaded." | ||
| }, | ||
| "service_event_register_ga_not_found": { | ||
| "message": "Could not find registered event for `{group_addresses}` to remove." |
joostlek
approved these changes
May 18, 2026
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
Raise HomeAssistantError instead of logging a warning.
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: