Skip to content

Commit 9e71e85

Browse files
authored
Merge pull request #621 from ianmcorvidae/str-concat-trace
Properly handle missing nodes in traceroute response
2 parents 7788271 + 93fbc78 commit 9e71e85

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

meshtastic/ble_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import struct
77
import time
88
from threading import Thread
9-
from typing import Optional
9+
from typing import List, Optional
1010

1111
import print_color # type: ignore[import-untyped]
1212
from bleak import BleakClient, BleakScanner, BLEDevice
@@ -94,7 +94,7 @@ async def log_radio_handler(self, _, b): # pylint: disable=C0116
9494
print_color.print(log_radio, end=None)
9595

9696
@staticmethod
97-
def scan() -> list[BLEDevice]:
97+
def scan() -> List[BLEDevice]:
9898
"""Scan for available BLE devices."""
9999
with BLEClient() as client:
100100
logging.info("Scanning for BLE devices (takes 10 seconds)...")

meshtastic/mesh_interface.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ def onResponseTraceRoute(self, p: dict):
490490
asDict = google.protobuf.json_format.MessageToDict(routeDiscovery)
491491

492492
print("Route traced:")
493-
routeStr = self._nodeNumToId(p["to"])
493+
routeStr = self._nodeNumToId(p["to"]) or f"{p['to']:08x}"
494494
if "route" in asDict:
495495
for nodeNum in asDict["route"]:
496-
routeStr += " --> " + self._nodeNumToId(nodeNum)
497-
routeStr += " --> " + self._nodeNumToId(p["from"])
496+
routeStr += " --> " + (self._nodeNumToId(nodeNum) or f"{nodeNum:08x}")
497+
routeStr += " --> " + (self._nodeNumToId(p["from"]) or f"{p['from']:08x}")
498498
print(routeStr)
499499

500500
self._acknowledgment.receivedTraceRoute = True
@@ -1021,7 +1021,7 @@ def _fixupPosition(self, position: Dict) -> Dict:
10211021
position["longitude"] = float(position["longitudeI"] * Decimal("1e-7"))
10221022
return position
10231023

1024-
def _nodeNumToId(self, num):
1024+
def _nodeNumToId(self, num: int) -> Optional[str]:
10251025
"""Map a node node number to a node ID
10261026
10271027
Arguments:
@@ -1034,7 +1034,7 @@ def _nodeNumToId(self, num):
10341034
return BROADCAST_ADDR
10351035

10361036
try:
1037-
return self.nodesByNum[num]["user"]["id"]
1037+
return self.nodesByNum[num]["user"]["id"] #type: ignore[index]
10381038
except:
10391039
logging.debug(f"Node {num} not found for fromId")
10401040
return None

0 commit comments

Comments
 (0)