🐛 fix: harden stream parsing (native booleans, malformed frames) #196

Merged
mat merged 1 commit from fix/stream-parsing-hardening into main 2026-10-27 14:36:26 +00:00
Owner

Summary

Two parsing-hardening fixes in the stream generator:

_try_bool(value)
└── isinstance(value, bool) → return it   (native JSON booleans no longer yield value_bool=None)
_try_float(value)
└── isinstance(value, bool) → None        (a boolean is not a float sample)
Measurement.value: str → str | bool

frame loop
├── measures frame missing "gatewayUid" → skip frame (was: bare KeyError)
└── measure entry missing keys / not a dict → skip measure, keep the loop alive

Evidence

  • Before: _try_bool (_streaming.py:65-70) matched only the strings "true"/"false"; measure["value"] / payload["gatewayUid"] raised a bare KeyError that killed the reconnect loop (#178, #179).
    After: TDD — 3 failing tests written first (native bool, missing gatewayUid frame, malformed measure among valid ones), then the fix. pytest -q → 246 passed (+4), mypy → clean.

Merge Danger

Door: two-way

Blast Radius: low — malformed/boolean measures previously crashed the stream (or silently lost the flag); well-formed string frames behave identically (regression test included).

Closes #178. Closes #179.

## Summary Two parsing-hardening fixes in the stream generator: ```text _try_bool(value) └── isinstance(value, bool) → return it (native JSON booleans no longer yield value_bool=None) _try_float(value) └── isinstance(value, bool) → None (a boolean is not a float sample) Measurement.value: str → str | bool frame loop ├── measures frame missing "gatewayUid" → skip frame (was: bare KeyError) └── measure entry missing keys / not a dict → skip measure, keep the loop alive ``` ## Evidence - **Before:** `_try_bool` (`_streaming.py:65-70`) matched only the strings `"true"`/`"false"`; `measure["value"]` / `payload["gatewayUid"]` raised a bare `KeyError` that killed the reconnect loop (#178, #179). **After:** TDD — 3 failing tests written first (native bool, missing gatewayUid frame, malformed measure among valid ones), then the fix. `pytest -q` → 246 passed (+4), `mypy` → clean. ## Merge Danger **Door:** two-way **Blast Radius:** low — malformed/boolean measures previously crashed the stream (or silently lost the flag); well-formed string frames behave identically (regression test included). Closes #178. Closes #179.
🐛 fix: harden stream parsing (native booleans, malformed frames)
All checks were successful
Tests / forgejo-pytest (push) Successful in 44s
Tests / forgejo-pytest (pull_request) Successful in 45s
989b466634
mat changed title from WIP: 🐛 fix: harden stream parsing (native booleans, malformed frames) to 🐛 fix: harden stream parsing (native booleans, malformed frames) 2026-10-27 14:36:25 +00:00
mat merged commit 5aaf2a29a2 into main 2026-10-27 14:36:26 +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!196
No description provided.