✨ Auto re-authenticate and retry once on 401 #15
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/auto-reauth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Slice 2 of 2 — point #8 (session-expiry handling)
Stacked on #14 (base branch
refactor/central-request-helper). Review/merge #14 first; this diff shows only the re-auth changes.Transparent auto re-authentication: on a 401 the client silently re-logs-in once
(reusing credentials captured at
authenticate()time) and retries the request once.This is exactly what the Home Assistant integration needs to stop falling into
ConfigEntryAuthFailedevery time thecwt_sessioncookie expires.Design (agreed with maintainer):
ComwattClient(auto_reauth=True)— new flag, on by default;auto_reauth=Falsedisables.username+ the sha256 hash, never the raw password._requesthelper; one retry, no loop.ComwattAPIError.authenticate()andis_authenticated()never auto-retry (the auth probe still returnsTrue/False).Tests: +6 (
tests/test_reauth.py) covering happy path,auto_reauth=False, no-stored-creds,re-auth-then-still-401 (single retry),
is_authenticatedunaffected, and no-raw-password-retained.Full suite green (38 passed).
Draft (WIP) — remove the WIP prefix to mark ready for review.
WIP: ✨ Auto re-authenticate and retry once on 401to ✨ Auto re-authenticate and retry once on 4011b0de0febac826981f6f