Skip to content

Fix KeyError 'token_expires_at' in initial config flow - #10

Open
pengelbrecht wants to merge 2 commits into
furth3st:mainfrom
pengelbrecht:fix/config-flow-missing-token-expires-at
Open

Fix KeyError 'token_expires_at' in initial config flow#10
pengelbrecht wants to merge 2 commits into
furth3st:mainfrom
pengelbrecht:fix/config-flow-missing-token-expires-at

Conversation

@pengelbrecht

Copy link
Copy Markdown

Problem

Setting up the integration with valid credentials (2FA disabled) fails with "Unknown error occurred" in the UI. The log shows:

File "/config/custom_components/danalock_cloud/config_flow.py", line 90, in async_step_user
    TOKEN_EXPIRES_AT: auth_result[TOKEN_EXPIRES_AT],
                      ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
KeyError: 'token_expires_at'

The auth result reaching async_step_user contains access_token/refresh_token but not always token_expires_at, so entry creation crashes after a successful login.

Fix

Derive the expiry from the standard OAuth expires_in field when token_expires_at is absent — the same way DanalockApiClient already 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

pengelbrecht and others added 2 commits August 11, 2026 20:54
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant