diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index 09f67fe..ac8fa15 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -650,3 +650,11 @@ def test_fuzz_fromStr(valstr): assert isinstance(result, int) except ValueError: assert isinstance(result, str) + +def test_shorthex(): + result = fromStr('0x0') + assert result == b'\x00' + result = fromStr('0x5') + assert result == b'\x05' + result = fromStr('0xffff') + assert result == b'\xff\xff' \ No newline at end of file diff --git a/meshtastic/util.py b/meshtastic/util.py index 8cb177c..3f864a2 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -82,7 +82,7 @@ def fromStr(valstr): val = bytes() elif valstr.startswith("0x"): # if needed convert to string with asBytes.decode('utf-8') - val = bytes.fromhex(valstr[2:]) + val = bytes.fromhex(valstr[2:].zfill(2)) elif valstr.startswith("base64:"): val = base64.b64decode(valstr[7:]) elif valstr.lower() in {"t", "true", "yes"}: