Fix KeyError 'token_expires_at' in initial config flow - #10
Open
pengelbrecht wants to merge 2 commits into
Open
Conversation
The login response does not always include token_expires_at, so async_step_user crashed with KeyError and the UI showed 'Unknown error occurred' even with valid credentials. Derive the expiry from the standard OAuth expires_in field when token_expires_at is absent, the same way DanalockApiClient computes it (time() + expires_in). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0118KiXSBUG3V16rsWoNbiEd
OptionsFlow.config_entry is a framework-provided read-only property in
current Home Assistant; assigning it in __init__ raises AttributeError
('property has no setter'), so opening the integration's options dialog
returned a 500. Stop passing/storing the entry manually.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0118KiXSBUG3V16rsWoNbiEd
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
Setting up the integration with valid credentials (2FA disabled) fails with "Unknown error occurred" in the UI. The log shows:
The auth result reaching
async_step_usercontainsaccess_token/refresh_tokenbut not alwaystoken_expires_at, so entry creation crashes after a successful login.Fix
Derive the expiry from the standard OAuth
expires_infield whentoken_expires_atis absent — the same wayDanalockApiClientalready computes it (time() + expires_in), with a 3600s fallback.Tested on Home Assistant 2026.8.1 (Container) with a Danalock V3 + Danabridge V3: config flow now completes and both locks + battery sensors work.
🤖 Generated with Claude Code
https://claude.ai/code/session_0118KiXSBUG3V16rsWoNbiEd