From 193c3faca5a0064ce638a8163c30ab58a875b7e3 Mon Sep 17 00:00:00 2001 From: Manuel Verch Date: Sat, 25 Mar 2023 21:37:10 +0100 Subject: [PATCH] Fix remote_hardware configuration --- meshtastic/mesh_interface.py | 2 ++ meshtastic/node.py | 17 +++++++++++++---- meshtastic/tests/test_remote_hardware.py | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 8568fb0..a0baee8 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -615,6 +615,8 @@ class MeshInterface: self.localNode.moduleConfig.telemetry.CopyFrom(fromRadio.moduleConfig.telemetry) elif fromRadio.moduleConfig.HasField("canned_message"): self.localNode.moduleConfig.canned_message.CopyFrom(fromRadio.moduleConfig.canned_message) + elif fromRadio.moduleConfig.HasField("remote_hardware"): + self.localNode.moduleConfig.remote_hardware.CopyFrom(fromRadio.moduleConfig.remote_hardware) else: logging.debug("Unexpected FromRadio payload") diff --git a/meshtastic/node.py b/meshtastic/node.py index d6b2b0f..7ede26b 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -83,19 +83,19 @@ class Node: if "getConfigResponse" in adminMessage: resp = adminMessage["getConfigResponse"] field = list(resp.keys())[0] - config_type = self.localConfig.DESCRIPTOR.fields_by_name.get(field) + config_type = self.localConfig.DESCRIPTOR.fields_by_name.get(camel_to_snake(field)) config_values = getattr(self.localConfig, config_type.name) elif "getModuleConfigResponse" in adminMessage: resp = adminMessage["getModuleConfigResponse"] field = list(resp.keys())[0] - config_type = self.moduleConfig.DESCRIPTOR.fields_by_name.get(field) + config_type = self.moduleConfig.DESCRIPTOR.fields_by_name.get(camel_to_snake(field)) config_values = getattr(self.moduleConfig, config_type.name) else: print("Did not receive a valid response. Make sure to have a shared channel named 'admin'.") return for key, value in resp[field].items(): setattr(config_values, camel_to_snake(key), value) - print(f"{str(field)}:\n{str(config_values)}") + print(f"{str(camel_to_snake(field))}:\n{str(config_values)}") def requestConfig(self, configType): if self == self.iface.localNode: @@ -233,7 +233,14 @@ class Node: p = admin_pb2.AdminMessage() p.set_module_config.audio.CopyFrom(self.moduleConfig.audio) self._sendAdmin(p) - logging.debug("Wrote module: audo") + logging.debug("Wrote module: audio") + time.sleep(0.3) + + if self.moduleConfig.remote_hardware: + p = admin_pb2.AdminMessage() + p.set_module_config.remote_hardware.CopyFrom(self.moduleConfig.remote_hardware) + self._sendAdmin(p) + logging.debug("Wrote module: remote_hardware") time.sleep(0.3) def writeConfig(self, config_name): @@ -273,6 +280,8 @@ class Node: p.set_module_config.canned_message.CopyFrom(self.moduleConfig.canned_message) elif config_name == 'audio': p.set_module_config.audio.CopyFrom(self.moduleConfig.audio) + elif config_name == 'remote_hardware': + p.set_module_config.remote_hardware.CopyFrom(self.moduleConfig.remote_hardware) else: our_exit(f"Error: No valid config with name {config_name}") diff --git a/meshtastic/tests/test_remote_hardware.py b/meshtastic/tests/test_remote_hardware.py index 1bff9ef..1521037 100644 --- a/meshtastic/tests/test_remote_hardware.py +++ b/meshtastic/tests/test_remote_hardware.py @@ -23,7 +23,7 @@ def test_RemoteHardwareClient(): def test_onGPIOreceive(capsys): """Test onGPIOreceive""" iface = MagicMock(autospec=SerialInterface) - packet = {'decoded': {'remotehw': {'typ': 'foo', 'gpioValue': '4096' }}} + packet = {'decoded': {'remotehw': {'type': 'foo', 'gpioValue': '4096' }}} onGPIOreceive(packet, iface) out, err = capsys.readouterr() assert re.search(r'Received RemoteHardware', out)