♻️ Split client.py into domain mixin modules #38

Merged
mat merged 2 commits from split-client into main 2026-07-05 08:26:32 +00:00
Owner

Summary

comwatt_client/client.py had grown to ~620 lines holding transport, auth and every endpoint. This splits it into a _BaseClient core plus one private mixin module per API domain — pure refactor, zero behavior change.

Layout

Module Contents
_core.py _BaseClient: session, timeout, _request (auto-reauth), error mapping, close, context manager
_auth.py authenticate, is_authenticated, _hash_password
_aggregations.py 5 time-series methods + _aggregations_query, _format_timestamp
_devices.py get_devices, get_device, put_device, get_device_kinds, switch_capacity
_sites.py get_sites, get_authenticated_user, get_tiles
_connected_objects.py connected objects + get_measure_keys
client.py ComwattClient(AuthMixin, AggregationsMixin, DevicesMixin, SitesMixin, ConnectedObjectsMixin) — 21 lines

Compatibility

  • Public interface unchanged: from comwatt_client import ComwattClient and from comwatt_client.client import ComwattClient both keep working; __init__.py untouched.
  • Method bodies & docstrings moved verbatim (only imports + __enter__ TypeVar annotation adjusted, typing.Self needs 3.11 and floor is 3.10).
  • Rebased on main: get_tiles (#34) and get_device_kinds (#35) placed in their domain mixins.
  • Cleanup: dropped unused import json; updated hash reference in docs/energy.comwatt.com/auth.md.

Tests

  • 81/81 passing, tests unmodified
  • mypy clean (9 source files, disallow_untyped_defs)
## Summary `comwatt_client/client.py` had grown to ~620 lines holding transport, auth and every endpoint. This splits it into a `_BaseClient` core plus one private mixin module per API domain — **pure refactor, zero behavior change**. ## Layout | Module | Contents | |---|---| | `_core.py` | `_BaseClient`: session, timeout, `_request` (auto-reauth), error mapping, `close`, context manager | | `_auth.py` | `authenticate`, `is_authenticated`, `_hash_password` | | `_aggregations.py` | 5 time-series methods + `_aggregations_query`, `_format_timestamp` | | `_devices.py` | `get_devices`, `get_device`, `put_device`, `get_device_kinds`, `switch_capacity` | | `_sites.py` | `get_sites`, `get_authenticated_user`, `get_tiles` | | `_connected_objects.py` | connected objects + `get_measure_keys` | | `client.py` | `ComwattClient(AuthMixin, AggregationsMixin, DevicesMixin, SitesMixin, ConnectedObjectsMixin)` — 21 lines | ## Compatibility - Public interface unchanged: `from comwatt_client import ComwattClient` and `from comwatt_client.client import ComwattClient` both keep working; `__init__.py` untouched. - Method bodies & docstrings moved verbatim (only imports + `__enter__` TypeVar annotation adjusted, `typing.Self` needs 3.11 and floor is 3.10). - Rebased on main: `get_tiles` (#34) and `get_device_kinds` (#35) placed in their domain mixins. - Cleanup: dropped unused `import json`; updated hash reference in `docs/energy.comwatt.com/auth.md`. ## Tests - 81/81 passing, tests unmodified - mypy clean (9 source files, `disallow_untyped_defs`)
♻️ Restore verbatim _api_error return type
Some checks are pending
Tests / forgejo-pytest (push) Waiting to run
Tests / forgejo-pytest (pull_request) Waiting to run
b56907b8b9
mat force-pushed split-client from b56907b8b9
Some checks are pending
Tests / forgejo-pytest (push) Waiting to run
Tests / forgejo-pytest (pull_request) Waiting to run
to 641c651212
All checks were successful
Tests / forgejo-pytest (push) Successful in 43s
Tests / forgejo-pytest (pull_request) Successful in 42s
2026-07-05 08:24:59 +00:00
Compare
Author
Owner

Rebased on main (now includes #36 and #37).

New module in the layout: _grid.pyGridMixin with the external grid-signal/tariff endpoints:

  • get_electricity_price(site_id) (EDF Tempo, #37)
  • get_ecowatt() (RTE EcoWatt, #36)

ComwattClient is now (AuthMixin, AggregationsMixin, DevicesMixin, GridMixin, SitesMixin, ConnectedObjectsMixin).

Verified after rebase: 85/85 tests passing (tests unmodified), mypy clean (10 source files).

Rebased on main (now includes #36 and #37). New module in the layout: `_grid.py` → `GridMixin` with the external grid-signal/tariff endpoints: - `get_electricity_price(site_id)` (EDF Tempo, #37) - `get_ecowatt()` (RTE EcoWatt, #36) `ComwattClient` is now `(AuthMixin, AggregationsMixin, DevicesMixin, GridMixin, SitesMixin, ConnectedObjectsMixin)`. Verified after rebase: 85/85 tests passing (tests unmodified), mypy clean (10 source files).
mat merged commit 506820f324 into main 2026-07-05 08:26:32 +00:00
mat deleted branch split-client 2026-07-05 08:26:33 +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!38
No description provided.