[client] _request: accept any 2xx as success (201/204 currently raise) #180

Closed
opened 2026-10-27 11:31:55 +00:00 by mat · 0 comments
Owner

_request (_core.py:96-97) treats only HTTP 200 as success:

if response.status_code == 200:
    return response

Every other status goes to the error path, so a 201/204 from a write endpoint raises ComwattAPIError despite success. This matters now that the write surface exists (set_device_mode, set_alert_config, create_/update_typical_day, update_planning, set_thermal_control), and set_thermal_control's own docstring admits its success path is unverified (_thermal_control.py:60-61) — a 204 answer would currently be reported as an error.

Fix:

  • accept 200 <= status < 300 in _request (keep the 401 re-auth retry path unchanged);
  • audit write-path callers that .json() the response (e.g. switch_capacity, _capacities.py:25): a 204 has an empty body, so they must tolerate it (e.g. return {}) rather than trading a bogus ComwattAPIError for a JSONDecodeError;
  • while implementing, live-pin the actual success codes per write endpoint, per this repo's field-verification habit.

Done when: mocked 201/204 responses return instead of raising, write callers handle empty bodies, tests cover both.

`_request` (`_core.py:96-97`) treats only HTTP 200 as success: ```python if response.status_code == 200: return response ``` Every other status goes to the error path, so a 201/204 from a write endpoint raises `ComwattAPIError` despite success. This matters now that the write surface exists (`set_device_mode`, `set_alert_config`, `create_/update_typical_day`, `update_planning`, `set_thermal_control`), and `set_thermal_control`'s own docstring admits its success path is unverified (`_thermal_control.py:60-61`) — a 204 answer would currently be reported as an error. **Fix:** - accept `200 <= status < 300` in `_request` (keep the 401 re-auth retry path unchanged); - audit write-path callers that `.json()` the response (e.g. `switch_capacity`, `_capacities.py:25`): a 204 has an empty body, so they must tolerate it (e.g. return `{}`) rather than trading a bogus `ComwattAPIError` for a `JSONDecodeError`; - while implementing, live-pin the actual success codes per write endpoint, per this repo's field-verification habit. **Done when:** mocked 201/204 responses return instead of raising, write callers handle empty bodies, tests cover both.
mat closed this issue 2026-10-27 14:38:29 +00:00
Sign in to join this conversation.
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#180
No description provided.