🐛 fix: accept any 2xx in _request, tolerate empty bodies on writes #197

Merged
mat merged 1 commit from fix/accept-2xx into main 2026-10-27 14:38:29 +00:00
Owner

Summary

_request stops treating 200 as the only success; write paths stop assuming a parseable body:

_request:   status == 200            ──►  200 <= status < 300   (401 re-auth retry path unchanged)
new helper:  _json_or_empty(response) ──►  {} on blank body (204), else response.json()

11 write call-sites switched to _json_or_empty:
  switch_capacity · set_pilot_wire · set_thermal_mode · set_thermostat_set_point
  put_device · set_device_mode · set_alert_config · update_planning
  create_typical_day · update_typical_day · set_thermal_control

Evidence

  • Before: a 201/204 answer from any write endpoint raised ComwattAPIError despite success (_core.py:96-97); even with 2xx accepted, .json() on a 204 body would have traded it for a decode error.
    After: TDD — 6 failing tests first (201 on read, 201 with body, 204 empty body ×4 endpoints), then the fix. pytest -q → 248 passed (+6), mypy → clean.

Merge Danger

Door: two-way

Blast Radius: low — strictly widens the success set; error paths (non-2xx, 401 re-auth) untouched. Actual per-endpoint success codes remain to be live-pinned (follow-up field-notes issue).

Closes #180.

## Summary `_request` stops treating 200 as the only success; write paths stop assuming a parseable body: ```text _request: status == 200 ──► 200 <= status < 300 (401 re-auth retry path unchanged) new helper: _json_or_empty(response) ──► {} on blank body (204), else response.json() 11 write call-sites switched to _json_or_empty: switch_capacity · set_pilot_wire · set_thermal_mode · set_thermostat_set_point put_device · set_device_mode · set_alert_config · update_planning create_typical_day · update_typical_day · set_thermal_control ``` ## Evidence - **Before:** a 201/204 answer from any write endpoint raised `ComwattAPIError` despite success (`_core.py:96-97`); even with 2xx accepted, `.json()` on a 204 body would have traded it for a decode error. **After:** TDD — 6 failing tests first (201 on read, 201 with body, 204 empty body ×4 endpoints), then the fix. `pytest -q` → 248 passed (+6), `mypy` → clean. ## Merge Danger **Door:** two-way **Blast Radius:** low — strictly widens the success set; error paths (non-2xx, 401 re-auth) untouched. Actual per-endpoint success codes remain to be live-pinned (follow-up field-notes issue). Closes #180.
🐛 fix: accept any 2xx in _request, tolerate empty bodies on writes
All checks were successful
Tests / forgejo-pytest (push) Successful in 44s
Tests / forgejo-pytest (pull_request) Successful in 44s
aef08b5c86
mat force-pushed fix/accept-2xx from aef08b5c86
All checks were successful
Tests / forgejo-pytest (push) Successful in 44s
Tests / forgejo-pytest (pull_request) Successful in 44s
to 1c264775d0
All checks were successful
Tests / forgejo-pytest (push) Successful in 45s
Tests / forgejo-pytest (pull_request) Successful in 45s
2026-10-27 14:38:20 +00:00
Compare
mat changed title from WIP: 🐛 fix: accept any 2xx in _request, tolerate empty bodies on writes to 🐛 fix: accept any 2xx in _request, tolerate empty bodies on writes 2026-10-27 14:38:27 +00:00
mat merged commit 0bf52f6946 into main 2026-10-27 14:38:29 +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!197
No description provided.