From 5ca97fbfd560fb05b4288ebdefb5ce9d4b2fdd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquin=20Cuevas=20Mu=C3=B1oz?= Date: Tue, 24 Nov 2026 00:04:49 -0300 Subject: [PATCH] fix: align GPIO read output format with write (#437) Closes #437 --- meshtastic/remote_hardware.py | 9 ++++----- meshtastic/tests/test_remote_hardware.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/meshtastic/remote_hardware.py b/meshtastic/remote_hardware.py index 41534a02a..c10ad5e92 100644 --- a/meshtastic/remote_hardware.py +++ b/meshtastic/remote_hardware.py @@ -23,11 +23,10 @@ def onGPIOreceive(packet, interface) -> None: # so, we set it here gpioValue = 0 - # print(f'mask:{interface.mask}') - value = int(gpioValue) & int(interface.mask) - print( - f'Received RemoteHardware type={hw["type"]}, gpio_value={gpioValue} value={value}' - ) + mask = int(interface.mask) + value = int(gpioValue) & mask + # Use the same hex notation as the "Writing GPIO mask ..." output + print(f'Received RemoteHardware type={hw["type"]}, 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..1f91ff026 100644 --- a/meshtastic/tests/test_remote_hardware.py +++ b/meshtastic/tests/test_remote_hardware.py @@ -30,6 +30,18 @@ def test_onGPIOreceive(capsys): assert err == "" +@pytest.mark.unit +def test_onGPIOreceive_hex_format(capsys): + """Test onGPIOreceive prints mask and masked value in hex, like the write output""" + iface = MagicMock(autospec=SerialInterface) + iface.mask = 0x1000 + packet = {"decoded": {"remotehw": {"type": "READ_GPIOS_REPLY", "gpioValue": "12288"}}} + onGPIOreceive(packet, iface) + out, err = capsys.readouterr() + assert out == "Received RemoteHardware type=READ_GPIOS_REPLY, mask=0x1000 value=0x1000\n" + assert err == "" + + @pytest.mark.unit def test_RemoteHardwareClient_no_gpio_channel(capsys): """Test that we can instantiate a RemoteHardwareClient instance but there is no channel named channel 'gpio'"""