✨ feat: session_expires_at (x-cwt-token capture) #159

Merged
mat merged 1 commit from feat/session-expires-at into main 2026-10-27 10:13:41 +00:00
Owner

Summary

 _post_authent (login / reactive re-auth)
+  x-cwt-token response header → _parse_session_expiry → _session_expires_at
 AuthMixin
+  session_expires_at: property → datetime | None (UTC-aware)
 logout()
+  clears _session_expires_at

Despite its name, x-cwt-token is not a token: it carries the session expiry instant (login + exactly 2 h, observed live; docs/energy.comwatt.com/auth.md — format re-confirmed live today, 2026-10-27T12:03:42.627Z). Captured on every successful _post_authent — initial login and reactive re-auth alike — and exposed as client.session_expires_at. Absent/unparseable header is tolerated as None (authentication itself still succeeded). logout() resets it.

Evidence

  • Before: AttributeError: no attribute 'session_expires_at'; the header was ignored entirely.
  • After: 7 new tests (parse Z/offset forms, absent + malformed header → None, refresh on reactive re-auth, cleared on logout, None before login); pytest = 192 passed; mypy clean.

Merge Danger

Door: two-way — additive attribute + property; revert restores previous behavior exactly.

Blast Radius: minimal — no existing method signature or request flow changed; _post_authent only records extra state.

Closes half of #99 (capture + expose); the opt-in proactive re-auth follows as a stacked PR.

## Summary ```diff _post_authent (login / reactive re-auth) + x-cwt-token response header → _parse_session_expiry → _session_expires_at AuthMixin + session_expires_at: property → datetime | None (UTC-aware) logout() + clears _session_expires_at ``` Despite its name, `x-cwt-token` is not a token: it carries the session expiry instant (login + exactly 2 h, observed live; `docs/energy.comwatt.com/auth.md` — format re-confirmed live today, `2026-10-27T12:03:42.627Z`). Captured on every successful `_post_authent` — initial login and reactive re-auth alike — and exposed as `client.session_expires_at`. Absent/unparseable header is tolerated as `None` (authentication itself still succeeded). `logout()` resets it. ## Evidence - **Before:** `AttributeError: no attribute 'session_expires_at'`; the header was ignored entirely. - **After:** 7 new tests (parse Z/offset forms, absent + malformed header → None, refresh on reactive re-auth, cleared on logout, None before login); `pytest` = **192 passed**; `mypy` clean. ## Merge Danger **Door:** two-way — additive attribute + property; revert restores previous behavior exactly. **Blast Radius:** minimal — no existing method signature or request flow changed; `_post_authent` only records extra state. Closes half of #99 (capture + expose); the opt-in proactive re-auth follows as a stacked PR.
✨ feat: session_expires_at (x-cwt-token capture) (#99)
All checks were successful
Tests / forgejo-pytest (pull_request) Successful in 44s
Tests / forgejo-pytest (push) Successful in 43s
8a8e9f67dd
mat changed title from WIP: ✨ feat: session_expires_at (x-cwt-token capture) to ✨ feat: session_expires_at (x-cwt-token capture) 2026-10-27 10:13:34 +00:00
mat merged commit 7ff8e87f5f into main 2026-10-27 10:13:41 +00:00
mat deleted branch feat/session-expires-at 2026-10-27 10:13:41 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mat/python-comwatt-client!159
No description provided.