From 76cfded371a598872c4fbdcb9d7c34ef15ad724f Mon Sep 17 00:00:00 2001 From: eunwoo song Date: Sun, 6 Sep 2026 23:47:27 +0900 Subject: [PATCH 1/2] fix: align GPIO read output with write format --- meshtastic/remote_hardware.py | 9 +++++--- meshtastic/tests/test_remote_hardware.py | 26 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/meshtastic/remote_hardware.py b/meshtastic/remote_hardware.py index 41534a02a..8e9c66cb9 100644 --- a/meshtastic/remote_hardware.py +++ b/meshtastic/remote_hardware.py @@ -23,10 +23,13 @@ def onGPIOreceive(packet, interface) -> None: # so, we set it here gpioValue = 0 - # print(f'mask:{interface.mask}') - value = int(gpioValue) & int(interface.mask) + # Keep read replies consistent with the hexadecimal mask/value notation used + # when the CLI writes GPIOs. + mask = int(interface.mask) + value = int(gpioValue) & mask print( - f'Received RemoteHardware type={hw["type"]}, gpio_value={gpioValue} value={value}' + f'Received Remote_Hardware type={hw["type"]}, ' + f"mask=0x{mask:x} value=0x{value:x}" ) interface.gotResponse = True diff --git a/meshtastic/tests/test_remote_hardware.py b/meshtastic/tests/test_remote_hardware.py index 7d4cf6f1a..85952d2f0 100644 --- a/meshtastic/tests/test_remote_hardware.py +++ b/meshtastic/tests/test_remote_hardware.py @@ -20,14 +20,32 @@ def test_RemoteHardwareClient(): @pytest.mark.unit -def test_onGPIOreceive(capsys): - """Test onGPIOreceive""" +@pytest.mark.parametrize( + ("gpio_value", "mask", "expected_value"), + [ + ("8192", 0x2000, "0x2000"), + ("12288", 0x2000, "0x2000"), + (None, 0x10, "0x0"), + ], +) +def test_onGPIOreceive_formats_masked_values_as_hex( + capsys, gpio_value, mask, expected_value +): + """GPIO replies use the same hexadecimal notation as write requests.""" iface = MagicMock(autospec=SerialInterface) - packet = {"decoded": {"remotehw": {"type": "foo", "gpioValue": "4096"}}} + iface.mask = mask + remotehw = {"type": "READ_GPIOS_REPLY"} + if gpio_value is not None: + remotehw["gpioValue"] = gpio_value + packet = {"decoded": {"remotehw": remotehw}} onGPIOreceive(packet, iface) out, err = capsys.readouterr() - assert re.search(r"Received RemoteHardware", out) + assert out == ( + "Received Remote_Hardware type=READ_GPIOS_REPLY, " + f"mask=0x{mask:x} value={expected_value}\n" + ) assert err == "" + assert iface.gotResponse is True @pytest.mark.unit From 1c77507d0a78f352155b0e44d84d77233310bbce Mon Sep 17 00:00:00 2001 From: eunwoo song Date: Mon, 7 Sep 2026 10:56:40 +0900 Subject: [PATCH 2/2] test: type GPIO response parameters --- meshtastic/tests/test_remote_hardware.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/meshtastic/tests/test_remote_hardware.py b/meshtastic/tests/test_remote_hardware.py index 85952d2f0..9fd43bfe4 100644 --- a/meshtastic/tests/test_remote_hardware.py +++ b/meshtastic/tests/test_remote_hardware.py @@ -29,8 +29,11 @@ def test_RemoteHardwareClient(): ], ) def test_onGPIOreceive_formats_masked_values_as_hex( - capsys, gpio_value, mask, expected_value -): + capsys: pytest.CaptureFixture[str], + gpio_value: str | None, + mask: int, + expected_value: str, +) -> None: """GPIO replies use the same hexadecimal notation as write requests.""" iface = MagicMock(autospec=SerialInterface) iface.mask = mask