[client] stream_measurements: parse native JSON booleans in measure values (_try_bool) #178

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

_try_bool (_streaming.py:65-70) only matches the strings "true"/"false":

def _try_bool(value: Any) -> bool | None:
    if value == "true":
        return True
    if value == "false":
        return False
    return None

A native JSON boolean in a measure frame ("value": true) silently yields value_bool=None on the emitted Measurement. The stream is string-typed today, so this is hardening rather than a live bug — but the coercion is cheap and removes a silent-failure mode.

Fix: accept booleans first:

if isinstance(value, bool):
    return value

Done when: Measurement.from_measure maps True/False values to value_bool, plus a unit test feeding a native boolean through from_measure.

`_try_bool` (`_streaming.py:65-70`) only matches the strings `"true"`/`"false"`: ```python def _try_bool(value: Any) -> bool | None: if value == "true": return True if value == "false": return False return None ``` A native JSON boolean in a measure frame (`"value": true`) silently yields `value_bool=None` on the emitted `Measurement`. The stream is string-typed today, so this is hardening rather than a live bug — but the coercion is cheap and removes a silent-failure mode. **Fix:** accept booleans first: ```python if isinstance(value, bool): return value ``` **Done when:** `Measurement.from_measure` maps `True`/`False` values to `value_bool`, plus a unit test feeding a native boolean through `from_measure`.
mat closed this issue 2026-10-27 14:36:26 +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#178
No description provided.