Use Oauth2 exceptions in miele - #175256
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the Miele integration's async_setup_entry to use Home Assistant's new OAuth2 token request exceptions instead of manually inspecting ClientResponseError.status to split 4xx/5xx handling. It resolves issue #175248 and aligns Miele with the migration pattern already adopted by integrations like google_assistant_sdk, yoto, and nest.
The new handling relies on the OAuth helper (config_entry_oauth2_flow._token_request) mapping token endpoint responses to typed exceptions: 4xx → OAuth2TokenRequestReauthError (→ ConfigEntryAuthFailed), and 429/5xx (OAuth2TokenRequestTransientError, a subclass of OAuth2TokenRequestError) plus other ClientErrors → ConfigEntryNotReady. The except-clause ordering is correct because OAuth2TokenRequestReauthError is a subclass of OAuth2TokenRequestError and is caught first. The now-unused ClientResponseError import is removed from this file (other Miele modules retain their own imports), and existing tests (401 → SETUP_ERROR, 500 → SETUP_RETRY, connection error → SETUP_RETRY) continue to cover the changed path.
Changes:
- Replace manual
ClientResponseErrorstatus-splitting with typed OAuth2 exceptions in setup. - Update imports to pull in
OAuth2TokenRequestError/OAuth2TokenRequestReauthErrorand drop the unusedClientResponseError.
Proposed change
Use new Oauth2 exceptions in miele setup
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: