From 7709620f9ae42ab33759111228cabc6239299298 Mon Sep 17 00:00:00 2001 From: Clive Blackledge Date: Mon, 19 Jan 2026 22:15:00 -0800 Subject: [PATCH 1/2] Add traffic management module to the config. --- meshtastic/mesh_interface.py | 4 ++++ meshtastic/node.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 20e43b9d9..eb0bdaf03 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -1455,6 +1455,10 @@ def _handleFromRadio(self, fromRadioBytes): self.localNode.moduleConfig.paxcounter.CopyFrom( fromRadio.moduleConfig.paxcounter ) + elif fromRadio.moduleConfig.HasField("traffic_management"): + self.localNode.moduleConfig.traffic_management.CopyFrom( + fromRadio.moduleConfig.traffic_management + ) else: logger.debug("Unexpected FromRadio payload") diff --git a/meshtastic/node.py b/meshtastic/node.py index afb5611ac..be27e689a 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -245,6 +245,8 @@ def writeConfig(self, config_name): p.set_module_config.ambient_lighting.CopyFrom(self.moduleConfig.ambient_lighting) elif config_name == "paxcounter": p.set_module_config.paxcounter.CopyFrom(self.moduleConfig.paxcounter) + elif config_name == "traffic_management": + p.set_module_config.traffic_management.CopyFrom(self.moduleConfig.traffic_management) else: our_exit(f"Error: No valid config with name {config_name}") From 29fa66f556ab7ca789a46d44eb6b49abd9c466d3 Mon Sep 17 00:00:00 2001 From: Clive Blackledge Date: Wed, 11 Feb 2026 20:41:26 -0800 Subject: [PATCH 2/2] Add traffic management unit tests --- .../test_mesh_interface_traffic_management.py | 22 +++++++++++++++++ meshtastic/tests/test_node.py | 24 +++++++++++++++++++ protobufs | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 meshtastic/tests/test_mesh_interface_traffic_management.py diff --git a/meshtastic/tests/test_mesh_interface_traffic_management.py b/meshtastic/tests/test_mesh_interface_traffic_management.py new file mode 100644 index 000000000..f1aa4f9bb --- /dev/null +++ b/meshtastic/tests/test_mesh_interface_traffic_management.py @@ -0,0 +1,22 @@ +"""Meshtastic unit tests for traffic management handling in mesh_interface.py.""" + +import pytest + +from ..mesh_interface import MeshInterface +from ..protobuf import mesh_pb2 + + +@pytest.mark.unit +@pytest.mark.usefixtures("reset_mt_config") +def test_handleFromRadio_with_traffic_management_module_config(): + """Test _handleFromRadio with moduleConfig.traffic_management.""" + iface = MeshInterface(noProto=True) + from_radio = mesh_pb2.FromRadio() + from_radio.moduleConfig.traffic_management.enabled = True + from_radio.moduleConfig.traffic_management.rate_limit_enabled = True + + iface._handleFromRadio(from_radio.SerializeToString()) + + assert iface.localNode.moduleConfig.traffic_management.enabled is True + assert iface.localNode.moduleConfig.traffic_management.rate_limit_enabled is True + iface.close() diff --git a/meshtastic/tests/test_node.py b/meshtastic/tests/test_node.py index c5cb6b3fa..7dc09b668 100644 --- a/meshtastic/tests/test_node.py +++ b/meshtastic/tests/test_node.py @@ -794,6 +794,30 @@ def test_writeConfig_with_no_radioConfig(capsys): assert err == "" +@pytest.mark.unit +@pytest.mark.usefixtures("reset_mt_config") +def test_writeConfig_traffic_management(): + """Test writeConfig with traffic_management module config.""" + iface = MagicMock(autospec=SerialInterface) + anode = Node(iface, 123, noProto=True) + anode.moduleConfig.traffic_management.enabled = True + anode.moduleConfig.traffic_management.rate_limit_enabled = True + + sent_admin = [] + + def capture_send(p, *args, **kwargs): + sent_admin.append(p) + + with patch.object(anode, "_sendAdmin", side_effect=capture_send): + anode.writeConfig("traffic_management") + + assert len(sent_admin) == 1 + assert sent_admin[0].HasField("set_module_config") + assert sent_admin[0].set_module_config.HasField("traffic_management") + assert sent_admin[0].set_module_config.traffic_management.enabled is True + assert sent_admin[0].set_module_config.traffic_management.rate_limit_enabled is True + + # TODO # @pytest.mark.unit # def test_writeConfig(caplog): diff --git a/protobufs b/protobufs index 77c8329a5..e1a6b3a86 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 77c8329a59a9c96a61c447b5d5f1a52ca583e4f2 +Subproject commit e1a6b3a868d735da72cd6c94c574d655129d390a