diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 170ffc8..37eb09f 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -18,7 +18,7 @@ from google.protobuf.json_format import MessageToJson import meshtastic.node from . import portnums_pb2, mesh_pb2 -from .util import stripnl, Timeout, our_exit +from .util import stripnl, Timeout, our_exit, remove_keys_from_dict from .__init__ import LOCAL_ADDR, BROADCAST_NUM, BROADCAST_ADDR, ResponseHandler, publishingThread, OUR_APP_VERSION, protocols class MeshInterface: @@ -84,7 +84,10 @@ class MeshInterface: nodes = "" if self.nodes: for n in self.nodes.values(): - nodes = nodes + f" {stripnl(n)}" + # when the TBeam is first booted, it sometimes shows the 'raw' data + # so, we will just remove any raw keys + n2 = remove_keys_from_dict('raw', n) + nodes = nodes + f" {stripnl(n2)}" infos = owner + myinfo + mesh + nodes print(infos) return infos diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index 6b9e94b..b7a2aa6 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -7,7 +7,8 @@ import pytest from meshtastic.util import (fixme, stripnl, pskToString, our_exit, support_info, genPSK256, fromStr, fromPSK, - quoteBooleans, catchAndIgnore) + quoteBooleans, catchAndIgnore, + remove_keys_from_dict) @pytest.mark.unit @@ -149,3 +150,27 @@ def test_catchAndIgnore(caplog): with caplog.at_level(logging.DEBUG): catchAndIgnore("something", some_closure) assert re.search(r'Exception thrown in something', caplog.text, re.MULTILINE) + + +@pytest.mark.unit +def test_remove_keys_from_dict_empty_keys_empty_dict(): + """Test when keys and dict both are empty""" + assert not remove_keys_from_dict((), {}) + + +@pytest.mark.unit +def test_remove_keys_from_dict_empty_dict(): + """Test when dict is empty""" + assert not remove_keys_from_dict(('a'), {}) + + +@pytest.mark.unit +def test_remove_keys_from_dict_empty_keys(): + """Test when keys is empty""" + assert remove_keys_from_dict((), {'a':1}) == {'a':1} + + +@pytest.mark.unit +def test_remove_keys_from_dict(): + """Test remove_keys_from_dict()""" + assert remove_keys_from_dict(('b'), {'a':1, 'b':2}) == {'a':1} diff --git a/meshtastic/util.py b/meshtastic/util.py index 9f9cba8..ac1eada 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -201,3 +201,12 @@ def support_info(): platform.python_implementation(), platform.python_compiler())) print('') print('Please add the output from the command: meshtastic --info') + + +def remove_keys_from_dict(keys, adict): + """Return a dictionary without some keys in it.""" + newdict = adict + for key in keys: + if key in adict: + del newdict[key] + return newdict