Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
our_exit,
remove_keys_from_dict,
stripnl,
message_to_json,
)


Expand Down Expand Up @@ -102,10 +103,10 @@ def showInfo(self, file=sys.stdout): # pylint: disable=W0613
owner = f"Owner: {self.getLongName()} ({self.getShortName()})"
myinfo = ""
if self.myInfo:
myinfo = f"\nMy info: {stripnl(MessageToJson(self.myInfo))}"
myinfo = f"\nMy info: {message_to_json(self.myInfo)}"
metadata = ""
if self.metadata:
metadata = f"\nMetadata: {stripnl(MessageToJson(self.metadata))}"
metadata = f"\nMetadata: {message_to_json(self.metadata)}"
mesh = "\n\nNodes in mesh: "
nodes = {}
if self.nodes:
Expand Down
8 changes: 4 additions & 4 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
our_exit,
pskToString,
stripnl,
message_to_json,
)


Expand Down Expand Up @@ -47,8 +48,7 @@ def showChannels(self):
if self.channels:
logging.debug(f"self.channels:{self.channels}")
for c in self.channels:
# print('c.settings.psk:', c.settings.psk)
cStr = stripnl(MessageToJson(c.settings))
cStr = message_to_json(c.settings)
# don't show disabled channels
if channel_pb2.Channel.Role.Name(c.role) != "DISABLED":
print(
Expand All @@ -64,11 +64,11 @@ def showInfo(self):
"""Show human readable description of our node"""
prefs = ""
if self.localConfig:
prefs = stripnl(MessageToJson(self.localConfig))
prefs = message_to_json(self.localConfig)
print(f"Preferences: {prefs}\n")
prefs = ""
if self.moduleConfig:
prefs = stripnl(MessageToJson(self.moduleConfig))
prefs = message_to_json(self.moduleConfig)
print(f"Module preferences: {prefs}\n")
self.showChannels()

Expand Down
9 changes: 9 additions & 0 deletions meshtastic/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Meshtastic unit tests for util.py"""

import json
import logging
import re
from unittest.mock import patch

import pytest

from meshtastic.supported_device import SupportedDevice
from meshtastic.mesh_pb2 import MyNodeInfo
from meshtastic.util import (
Timeout,
active_ports_on_supported_devices,
Expand All @@ -30,6 +32,7 @@
snake_to_camel,
stripnl,
support_info,
message_to_json,
)


Expand Down Expand Up @@ -545,3 +548,9 @@ def test_active_ports_on_supported_devices_mac_duplicates_check(mock_platform, m
}
mock_platform.assert_called()
mock_sp.assert_called()

@pytest.mark.unit
def test_message_to_json_shows_all():
actual = json.loads(message_to_json(MyNodeInfo()))
expected = { "myNodeNum": 0, "rebootCount": 0, "minAppVersion": 0 }
assert actual == expected
6 changes: 5 additions & 1 deletion meshtastic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
import traceback
from queue import Queue
from google.protobuf.json_format import MessageToJson

import pkg_resources
import requests
Expand All @@ -22,7 +23,6 @@
"""Some devices such as a seger jlink we never want to accidentally open"""
blacklistVids = dict.fromkeys([0x1366])


def quoteBooleans(a_string):
"""Quote booleans
given a string that contains ": true", replace with ": 'true'" (or false)
Expand Down Expand Up @@ -605,3 +605,7 @@ def check_if_newer_version():
) <= pkg_resources.parse_version(act_version):
return None
return pypi_version

def message_to_json(message):
return stripnl(MessageToJson(message, always_print_fields_with_no_presence=True))