"""SUB 0x15's serial is a C string in an 8-byte field: cut at the first NUL. BE9441 (bench, 2026-10-25) answers `BE9441\\x00?` -- six characters, the terminator, then a leftover byte. Stripping only trailing NULs kept the `?`, so the serial read as "BE9441\\x00?" and every serial-named request was refused as the wrong unit. Seven-character serials (BE11529, BE18189) fill the field up to the terminator, which is why this never showed before. """ from __future__ import annotations from minimateplus.client import _decode_serial_number _HEADER = bytes(11) # data[0:11]: the section header def _reply(field8: bytes, trail: int = 0x00, fw_minor: int = 0x11) -> bytes: return _HEADER + field8 + bytes([trail, fw_minor]) def test_a_six_character_serial_stops_at_its_terminator(): assert _decode_serial_number(_reply(b"BE9441\x00?")).serial == "BE9441" def test_a_seven_character_serial_is_unchanged(): info = _decode_serial_number(_reply(b"BE18189\x00", trail=0x2A, fw_minor=0x11)) assert (info.serial, info.firmware_minor) == ("BE18189", 0x11) def test_a_short_payload_also_stops_at_the_terminator(): assert _decode_serial_number(_HEADER + b"BE9441\x00?").serial == "BE9441"