You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(config_flow): defer credential storage until OAuth succeeds
Replaces the eager-replace approach from the prior PR. The form submit
no longer mutates the application_credentials store; instead it stages
the new credentials on self._pending_credential, builds an in-memory
LocalOAuth2Implementation, sets self.flow_impl, and jumps to
async_step_auth. The actual store mutation runs in async_oauth_create_entry
on the OAuth-success path.
Two bugs this fixes:
1. Reconfigure with bad creds left the entry broken. The old flow deleted
the original cred before OAuth ran; if OAuth failed at Xthings (bad
secret, user rejection, etc.), the existing entry's stored token was
no longer refreshable against any valid client and the integration
looped on "failed to unload". With deferred storage, OAuth failure
leaves the original cred intact and the entry keeps working.
2. First-time install showed two consecutive credential prompts. HA's
stock "missing_credentials" flow added the cred via its own UI, then
restarted the flow; our async_step_user routing then rendered our
form on top, asking for the same cred a second time. async_step_user
now always renders our form directly, bypassing HA's stock prompt.
The unused scope step (whose value was never actually applied to
extra_authorize_data) is dropped.
Trade-offs noted:
- Drops the never-applied API scope field (DEFAULT_API_SCOPE is
hard-coded into extra_authorize_data, matching the prior runtime
behavior).
- Drops the credential_import_failed error path from the form, since
imports now happen during async_oauth_create_entry; if the import
fails there, HA aborts the flow with the standard oauth_error reason.
Test coverage: 15 tests in test_config_flow_reconfigure.py (form
rendering, user-step routing, submit-does-not-touch-store, pending-
credential staging, validation, reconfigure routing, commit-on-success,
delete-then-import for matching client_id, no-pending no-op, source-
based entry update for reconfigure and reauth).
Copy file name to clipboardExpand all lines: custom_components/u_tec/strings.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@
9
9
"description": "The Uhome integration needs to re-authenticate your account"
10
10
},
11
11
"replace_credentials": {
12
-
"title": "Update U-Tec credentials",
13
-
"description": "Enter your Client ID and Client Secret from the Xthings app (My Account → OpenAPI). Submitting will replace any previously stored credentials and start a new authorization. The Client Secret is not displayed for security; please re-enter it.",
12
+
"title": "U-Tec credentials",
13
+
"description": "Enter your Client ID and Client Secret from the Xthings app (My Account → OpenAPI). Submitting will start the U-Tec authorization. The Client Secret is not displayed; if you've used this integration before, please re-enter it.",
0 commit comments