Home Connect refactor OAuth exceptions - #175236
Conversation
|
Hey there @DavidMStraub, @Diegorro98, @MartinHjelmare, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the OAuth token-refresh error handling in the Home Connect integration's async_setup_entry. Instead of catching a raw aiohttp.ClientResponseError and inspecting its HTTP status to decide between ConfigEntryAuthFailed and ConfigEntryNotReady, it now catches the semantic OAuth2 exceptions (OAuth2TokenRequestReauthError, OAuth2TokenRequestError) that the Home Assistant OAuth2 helper already raises. This aligns Home Connect with the newer OAuth error-handling convention (per the referenced devblog and issue #175235) also used by SmartThings, Neato, and Google Assistant SDK.
Changes:
- Import
OAuth2TokenRequestErrorandOAuth2TokenRequestReauthErrorfromhomeassistant.exceptions. - Replace the status-based
aiohttp.ClientResponseErrorbranch with explicit exception handling: reauth error →ConfigEntryAuthFailed, other token request/client errors →ConfigEntryNotReady.
I verified the catch ordering is correct (OAuth2TokenRequestReauthError is caught before its superclass OAuth2TokenRequestError), that the trailing except aiohttp.ClientError is still necessary (raw client errors are not wrapped by the OAuth2 helper), and that the existing tests in test_init.py (400 → SETUP_ERROR, 500 → SETUP_RETRY, aiohttp.ClientError → SETUP_RETRY) continue to reflect the new behavior. No issues were found.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Breaking change
Proposed change
Refactors to use the to use the OAuth exceptions, instead of
ClientResponseError.Solves: #175235
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: