fix(config_flow): reload entry after reauth/reconfigure when initial setup failed - #286
Merged
Merged
Conversation
…setup failed When async_setup_entry raises (e.g. a v1->v2 upgrade whose entry.data has no refresh token / DPoP key), it does so before the update listener is registered. reauth/reconfigure then write fresh credentials via async_update_entry, but with no listener nothing reloads the entry, so the new tokens never take effect until a full HA restart or remove+re-add. Explicitly schedule a reload when the entry is not LOADED, while leaving the listener to handle the already-loaded case to avoid a double-reload race. Fixes binarydev#283 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
|
LGTM thanks so much for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #283 (and matches the reports in that thread from @ASwingler, @plynkus, @cheesedogf150, @mattmeiser).
After the v1→v2 (0.5.2) upgrade, an existing entry's
datahas norefresh_token/dpop_pem, soasync_setup_entryraisesConfigEntryAuthFailed("Missing refresh token or DPoP key"). That raise happens beforeentry.add_update_listener(async_reload_entry)is registered, so no update listener exists.The user then recovers via reauth/reconfigure, which persists valid credentials with
async_update_entryand relies on that (now-missing) listener to reload. With no listener, nothing reloads the entry — so it stays stuck showing "Missing refresh token or DPoP key" and the sensors never come up until a full HA restart or remove + re-add. That exactly matches every report in the issue (a restart or re-add fixes it; the update's own auto-restart does not, because the data was still the old v1 data at that point).Fix
In
_finish_reauth/_finish_reconfigure, explicitlyasync_schedule_reloadwhen the entry is notLOADED(i.e. setup failed, so no listener is registered). When the entry is loaded, the reload is left to the update listener — scheduling a second reload there would race the listener-driven one and surface as "failed to unload".Tests
test_reconfigure_reloads_when_setup_failed— failed setup → reconfigure schedules a reloadtest_reauth_reloads_when_setup_failed— failed setup → reauth schedules a reloadtest_reconfigure_does_not_double_reload_when_loaded— a loaded entry does not double-schedule a reload