🐛 fix: normalize time-series numeric samples to float #56

Merged
mat merged 1 commit from fix-string-series-values into main 2026-09-04 21:15:59 +00:00
Owner

Fixes the root cause of MateoGreil/homeassistant-comwatt#56 (v0.8.x fails to set up with TypeError: '<' not supported between instances of 'str' and 'int').

Why

Some Comwatt accounts get their time-series samples serialized as JSON strings ("12.34") instead of JSON numbers. The first numeric consumer downstream is the HA integration's site-energy folding (value < 0), which crashes the whole setup on those accounts.

What

normalize_time_series() (new _series.py) coerces every top-level list except timestamps to uniform float | None samples:

  • JSON numbers → float
  • numeric strings ("12.34") → float
  • None stays None
  • booleans, empty/unparseable strings → None (usable as a number gap)

Applied on site-time-series, time-series and the deprecated site-networks-ts-time-ago endpoints. Non-list fields and unknown structures are returned unchanged, so extra API metadata is never altered.

Tests

4 new tests in test_aggregations.py: string-sample coercion per endpoint, and non-series fields left untouched.

Release plan

Bump __version__ to 0.4.2 → tag → PyPI, then the integration bumps its manifest.json requirement to comwatt-client==0.4.2 for v0.8.2 (companion PR: mat/homeassistant-comwatt#113 hardens the persisted-state loader against the follow-up crash reported in the same issue).

Fixes the root cause of MateoGreil/homeassistant-comwatt#56 (v0.8.x fails to set up with `TypeError: '<' not supported between instances of 'str' and 'int'`). ## Why Some Comwatt accounts get their time-series samples serialized as JSON strings (`"12.34"`) instead of JSON numbers. The first numeric consumer downstream is the HA integration's site-energy folding (`value < 0`), which crashes the whole setup on those accounts. ## What `normalize_time_series()` (new `_series.py`) coerces every top-level list except `timestamps` to uniform `float | None` samples: - JSON numbers → `float` - numeric strings (`"12.34"`) → `float` - `None` stays `None` - booleans, empty/unparseable strings → `None` (usable as a number gap) Applied on `site-time-series`, `time-series` and the deprecated `site-networks-ts-time-ago` endpoints. Non-list fields and unknown structures are returned unchanged, so extra API metadata is never altered. ## Tests 4 new tests in `test_aggregations.py`: string-sample coercion per endpoint, and non-series fields left untouched. ## Release plan Bump `__version__` to 0.4.2 → tag → PyPI, then the integration bumps its `manifest.json` requirement to `comwatt-client==0.4.2` for v0.8.2 (companion PR: mat/homeassistant-comwatt#113 hardens the persisted-state loader against the follow-up crash reported in the same issue).
🐛 fix: normalize time-series numeric samples to float
All checks were successful
Tests / forgejo-pytest (push) Successful in 43s
Tests / forgejo-pytest (pull_request) Successful in 43s
1a3bb168c2
Some accounts get their time-series samples serialized as JSON strings
("12.34") instead of numbers, which crashes numeric consumers with
TypeError: '<' not supported between instances of 'str' and 'int'.

normalize_time_series() coerces every list except timestamps to
float/None samples on site-time-series, time-series and the deprecated
site-networks-ts-time-ago endpoints.
mat force-pushed fix-string-series-values from 1a3bb168c2
All checks were successful
Tests / forgejo-pytest (push) Successful in 43s
Tests / forgejo-pytest (pull_request) Successful in 43s
to 8b96072db5
All checks were successful
Tests / forgejo-pytest (push) Successful in 42s
Tests / forgejo-pytest (pull_request) Successful in 42s
2026-09-04 21:15:40 +00:00
Compare
mat merged commit ea52b0178c into main 2026-09-04 21:15:59 +00:00
mat deleted branch fix-string-series-values 2026-09-04 21:15:59 +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!56
No description provided.