Skip to content

Commit 4c97866

Browse files
authored
Merge pull request #511 from flavoromission/506-show-all-module-settings
feat:506 show all module settings
2 parents 8bb0cdf + 27be73c commit 4c97866

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

meshtastic/mesh_interface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
our_exit,
3636
remove_keys_from_dict,
3737
stripnl,
38+
message_to_json,
3839
)
3940

4041

@@ -108,10 +109,10 @@ def showInfo(self, file=sys.stdout): # pylint: disable=W0613
108109
owner = f"Owner: {self.getLongName()} ({self.getShortName()})"
109110
myinfo = ""
110111
if self.myInfo:
111-
myinfo = f"\nMy info: {stripnl(MessageToJson(self.myInfo))}"
112+
myinfo = f"\nMy info: {message_to_json(self.myInfo)}"
112113
metadata = ""
113114
if self.metadata:
114-
metadata = f"\nMetadata: {stripnl(MessageToJson(self.metadata))}"
115+
metadata = f"\nMetadata: {message_to_json(self.metadata)}"
115116
mesh = "\n\nNodes in mesh: "
116117
nodes = {}
117118
if self.nodes:

meshtastic/node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
our_exit,
1616
pskToString,
1717
stripnl,
18+
message_to_json,
1819
)
1920

2021

@@ -47,8 +48,7 @@ def showChannels(self):
4748
if self.channels:
4849
logging.debug(f"self.channels:{self.channels}")
4950
for c in self.channels:
50-
# print('c.settings.psk:', c.settings.psk)
51-
cStr = stripnl(MessageToJson(c.settings))
51+
cStr = message_to_json(c.settings)
5252
# don't show disabled channels
5353
if channel_pb2.Channel.Role.Name(c.role) != "DISABLED":
5454
print(
@@ -64,11 +64,11 @@ def showInfo(self):
6464
"""Show human readable description of our node"""
6565
prefs = ""
6666
if self.localConfig:
67-
prefs = stripnl(MessageToJson(self.localConfig))
67+
prefs = message_to_json(self.localConfig)
6868
print(f"Preferences: {prefs}\n")
6969
prefs = ""
7070
if self.moduleConfig:
71-
prefs = stripnl(MessageToJson(self.moduleConfig))
71+
prefs = message_to_json(self.moduleConfig)
7272
print(f"Module preferences: {prefs}\n")
7373
self.showChannels()
7474

meshtastic/tests/test_util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Meshtastic unit tests for util.py"""
22

3+
import json
34
import logging
45
import re
56
from unittest.mock import patch
67

78
import pytest
89

910
from meshtastic.supported_device import SupportedDevice
11+
from meshtastic.mesh_pb2 import MyNodeInfo
1012
from meshtastic.util import (
1113
Timeout,
1214
active_ports_on_supported_devices,
@@ -30,6 +32,7 @@
3032
snake_to_camel,
3133
stripnl,
3234
support_info,
35+
message_to_json,
3336
)
3437

3538

@@ -545,3 +548,9 @@ def test_active_ports_on_supported_devices_mac_duplicates_check(mock_platform, m
545548
}
546549
mock_platform.assert_called()
547550
mock_sp.assert_called()
551+
552+
@pytest.mark.unit
553+
def test_message_to_json_shows_all():
554+
actual = json.loads(message_to_json(MyNodeInfo()))
555+
expected = { "myNodeNum": 0, "rebootCount": 0, "minAppVersion": 0 }
556+
assert actual == expected

meshtastic/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212
import traceback
1313
from queue import Queue
14+
from google.protobuf.json_format import MessageToJson
1415

1516
import packaging.version as pkg_version
1617
import requests
@@ -23,7 +24,6 @@
2324
"""Some devices such as a seger jlink we never want to accidentally open"""
2425
blacklistVids = dict.fromkeys([0x1366])
2526

26-
2727
def quoteBooleans(a_string):
2828
"""Quote booleans
2929
given a string that contains ": true", replace with ": 'true'" (or false)
@@ -612,3 +612,7 @@ def check_if_newer_version():
612612
return None
613613

614614
return pypi_version
615+
616+
def message_to_json(message):
617+
return stripnl(MessageToJson(message, always_print_fields_with_no_presence=True))
618+

0 commit comments

Comments
 (0)