meshcore_py/src/meshcore
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
..
commands Use firmware suggested_timeout for login and path discovery sync methods 2026-04-08 21:42:21 -07:00
__init__.py Export binary req type 2025-09-07 12:28:26 -07:00
ble_cx.py Add optional bleak package import handling 2026-02-10 10:30:51 +01:00
connection_manager.py Revert "Refactor command system to be queue based" 2025-09-04 15:08:08 -07:00
events.py add code_string to error event 2026-03-07 21:05:00 -04:00
lpp_json_encoder.py fix lpp values for voltage and current as signed 2026-02-17 08:52:56 -04:00
meshcore.py if possible, add path and rssi to channel messages 2026-03-05 11:50:41 -04:00
meshcore_parser.py G1: R02 — fix txt_type empty-slice (uncrypted[4:4] -> [4:5]) 2026-04-11 18:30:54 -07:00
packets.py implement advert_path 2026-03-07 17:42:41 -04:00
parsing.py Revert "Refactor command system to be queue based" 2025-09-04 15:08:08 -07:00
reader.py fix: BATTERY handler drops frames shorter than 3 bytes (level field guard) 2026-04-11 19:24:26 -07:00
serial_cx.py Use the frame start once we've found it 2026-03-21 21:08:04 -07:00
tcp_cx.py apply frame header fix to tcp as well 2026-03-22 12:51:01 -04:00