Improve exception handling for frontier_silicon#168635
Improve exception handling for frontier_silicon#168635wlcrs wants to merge 4 commits intohome-assistant:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the frontier_silicon integration’s robustness by translating afsapi command exceptions into user-friendly HomeAssistantErrors with localized messages.
Changes:
- Add a decorator in
media_player.pyto catchFSConnectionError/FSApiErrorand raise translatedHomeAssistantErrors. - Add new exception translation strings (
api_error,connection_error) for the integration. - Add unit tests verifying exception-to-
HomeAssistantErrormapping for a media player command.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/frontier_silicon/media_player.py |
Adds a command wrapper decorator and applies it to media player command methods to map afsapi exceptions into translated HA errors. |
homeassistant/components/frontier_silicon/strings.json |
Adds exceptions translation entries used by HomeAssistantError translation keys. |
tests/components/frontier_silicon/test_media_player.py |
Adds tests validating error mapping behavior for async_media_previous_track. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the Frontier Silicon integration’s user-facing error handling by converting afsapi exceptions raised during media player commands into translated HomeAssistantErrors.
Changes:
- Added a reusable decorator to map
FSConnectionError/FSApiErrorinto translatedHomeAssistantErrors. - Applied the decorator across media player command methods (playback, power, volume, source, etc.).
- Added exception translation strings and new tests validating the exception mapping behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/components/frontier_silicon/media_player.py |
Introduces and applies an exception-mapping decorator for command methods. |
homeassistant/components/frontier_silicon/strings.json |
Adds translated exception messages for the new HomeAssistantError translation keys. |
tests/components/frontier_silicon/test_media_player.py |
Adds tests ensuring afsapi exceptions are converted to the expected translated HA errors. |
| from homeassistant.exceptions import HomeAssistantError | ||
|
|
||
|
|
||
| async def test_async_media_previous_track_maps_connection_error() -> None: |
There was a problem hiding this comment.
These two tests can be grouped together via parametrization. :)
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Breaking change
Proposed change
Currently, exceptions generated by the integration are not caught. This PR adds a wrapper to the functions that can receive an FSApiError to properly handle them.
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: