Skip to content

Improve exception handling for frontier_silicon#168635

Draft
wlcrs wants to merge 4 commits intohome-assistant:devfrom
wlcrs:afsapi_exception_handling
Draft

Improve exception handling for frontier_silicon#168635
wlcrs wants to merge 4 commits intohome-assistant:devfrom
wlcrs:afsapi_exception_handling

Conversation

@wlcrs
Copy link
Copy Markdown
Contributor

@wlcrs wlcrs commented Apr 20, 2026

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

  • 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:

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

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.py to catch FSConnectionError / FSApiError and raise translated HomeAssistantErrors.
  • Add new exception translation strings (api_error, connection_error) for the integration.
  • Add unit tests verifying exception-to-HomeAssistantError mapping 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.

Comment thread tests/components/frontier_silicon/test_media_player.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 April 20, 2026 15:39
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

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 / FSApiError into translated HomeAssistantErrors.
  • 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:
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 two tests can be grouped together via parametrization. :)

@home-assistant home-assistant bot marked this pull request as draft April 20, 2026 17:10
@home-assistant
Copy link
Copy Markdown

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.

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