♻️ Route HTTP calls through a central _request() helper #14

Merged
mat merged 1 commit from refactor/central-request-helper into main 2026-07-04 09:08:04 +00:00
Owner

Slice 1 of 2 — point #8 (session-expiry handling)

Behavior-preserving refactor that extracts the repeated
request → check 200 → return .json() / raise _api_error pattern into a single
private _request(self, method, path, **kwargs) helper. The 9 data-fetching
methods now delegate to it (−61/+21 lines).

authenticate() and is_authenticated() intentionally keep their bespoke logic
and do not route through _request (login must never auto-retry; the
auth-probe maps 401/403 → False).

Why: this unlocks the next slice (transparent auto re-auth on 401), which
wraps this single helper instead of touching all 12 methods.

Merge-safe: no behavior change, produced request URLs are byte-identical,
all 32 existing tests pass unchanged.

Draft (WIP) — remove the WIP prefix to mark ready for review.

## Slice 1 of 2 — point #8 (session-expiry handling) Behavior-preserving refactor that extracts the repeated `request → check 200 → return .json() / raise _api_error` pattern into a single private `_request(self, method, path, **kwargs)` helper. The 9 data-fetching methods now delegate to it (−61/+21 lines). `authenticate()` and `is_authenticated()` intentionally keep their bespoke logic and do **not** route through `_request` (login must never auto-retry; the auth-probe maps 401/403 → `False`). **Why:** this unlocks the next slice (transparent auto re-auth on 401), which wraps this single helper instead of touching all 12 methods. **Merge-safe:** no behavior change, produced request URLs are byte-identical, all 32 existing tests pass unchanged. _Draft (WIP) — remove the WIP prefix to mark ready for review._
♻️ Route HTTP calls through a central _request() helper
All checks were successful
Tests / forgejo-pytest (push) Successful in 36s
Tests / forgejo-pytest (pull_request) Successful in 37s
84e1796cd1
Extract the repeated "call session verb → check 200 → return json /
raise _api_error" pattern into a single private ComwattClient._request
helper. Route get_authenticated_user, get_sites,
get_site_networks_ts_time_ago, get_site_consumption_breakdown_time_ago,
get_devices, get_device, put_device, get_device_ts_time_ago and
switch_capacity through it.

authenticate and is_authenticated keep their bespoke status-code
handling and are left untouched. Produced URLs and return values are
unchanged; all 32 existing tests pass with no modifications.
mat changed title from WIP: ♻️ Route HTTP calls through a central _request() helper to ♻️ Route HTTP calls through a central _request() helper 2026-07-04 09:07:56 +00:00
mat merged commit e47b6ef77d into main 2026-07-04 09:08:04 +00:00
mat deleted branch refactor/central-request-helper 2026-07-04 09:08:04 +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!14
No description provided.