meshcore_py/tests/unit
Matthew Wolter 2bf3f1b9dd fix: BATTERY handler drops frames shorter than 3 bytes (level field guard)
A BATTERY frame with len(data) < 3 caused dbuf.read(2) to return short
bytes; int.from_bytes(b"", ...) silently yielded 0, propagating a bogus
level=0 to HA sensors.  Same silent-zero class as N07 (storage fields).

Option B: early-return with debug log, matching the NEW-C pattern for
STATUS_RESPONSE.  No BATTERY event is dispatched for malformed frames.

Not in the original forensics report — discovered during G1 N07 work and
logged in issues_log.md.  Resolved here because no later branch touches
this handler.

Files changed:
- src/meshcore/reader.py: add `if len(data) < 3: return` guard before
  the level read in the BATTERY branch
- tests/unit/test_reader.py: add test_g1_battery_too_short_for_level —
  sends a 1-byte frame (type only), asserts no BATTERY event dispatched
  and debug log emitted
2026-04-11 19:24:26 -07:00
..
test_commands.py Fix 16 failing unit tests to match current source behavior 2026-04-05 18:38:16 -07:00
test_events.py feat: Refactor binary commands and apply BLE fixes 2025-08-05 15:31:54 -04:00
test_lpp_parsing.py Fix 16 failing unit tests to match current source behavior 2026-04-05 18:38:16 -07:00
test_path_discovery_response.py Fix three byte path packets 2026-03-18 17:31:17 -07:00
test_private_key_export.py Fix 16 failing unit tests to match current source behavior 2026-04-05 18:38:16 -07:00
test_reader.py fix: BATTERY handler drops frames shorter than 3 bytes (level field guard) 2026-04-11 19:24:26 -07:00
test_serial_connection.py Use the frame start once we've found it 2026-03-21 21:08:04 -07:00