mirror of
https://github.com/meshtastic/python.git
synced 2026-01-17 12:17:55 -05:00
Merge pull request #621 from ianmcorvidae/str-concat-trace
Properly handle missing nodes in traceroute response
This commit is contained in:
@@ -6,7 +6,7 @@ import logging
|
||||
import struct
|
||||
import time
|
||||
from threading import Thread
|
||||
from typing import Optional
|
||||
from typing import List, Optional
|
||||
|
||||
import print_color # type: ignore[import-untyped]
|
||||
from bleak import BleakClient, BleakScanner, BLEDevice
|
||||
@@ -94,7 +94,7 @@ class BLEInterface(MeshInterface):
|
||||
print_color.print(log_radio, end=None)
|
||||
|
||||
@staticmethod
|
||||
def scan() -> list[BLEDevice]:
|
||||
def scan() -> List[BLEDevice]:
|
||||
"""Scan for available BLE devices."""
|
||||
with BLEClient() as client:
|
||||
logging.info("Scanning for BLE devices (takes 10 seconds)...")
|
||||
|
||||
@@ -490,11 +490,11 @@ class MeshInterface: # pylint: disable=R0902
|
||||
asDict = google.protobuf.json_format.MessageToDict(routeDiscovery)
|
||||
|
||||
print("Route traced:")
|
||||
routeStr = self._nodeNumToId(p["to"])
|
||||
routeStr = self._nodeNumToId(p["to"]) or f"{p['to']:08x}"
|
||||
if "route" in asDict:
|
||||
for nodeNum in asDict["route"]:
|
||||
routeStr += " --> " + self._nodeNumToId(nodeNum)
|
||||
routeStr += " --> " + self._nodeNumToId(p["from"])
|
||||
routeStr += " --> " + (self._nodeNumToId(nodeNum) or f"{nodeNum:08x}")
|
||||
routeStr += " --> " + (self._nodeNumToId(p["from"]) or f"{p['from']:08x}")
|
||||
print(routeStr)
|
||||
|
||||
self._acknowledgment.receivedTraceRoute = True
|
||||
@@ -1021,7 +1021,7 @@ class MeshInterface: # pylint: disable=R0902
|
||||
position["longitude"] = float(position["longitudeI"] * Decimal("1e-7"))
|
||||
return position
|
||||
|
||||
def _nodeNumToId(self, num):
|
||||
def _nodeNumToId(self, num: int) -> Optional[str]:
|
||||
"""Map a node node number to a node ID
|
||||
|
||||
Arguments:
|
||||
@@ -1034,7 +1034,7 @@ class MeshInterface: # pylint: disable=R0902
|
||||
return BROADCAST_ADDR
|
||||
|
||||
try:
|
||||
return self.nodesByNum[num]["user"]["id"]
|
||||
return self.nodesByNum[num]["user"]["id"] #type: ignore[index]
|
||||
except:
|
||||
logging.debug(f"Node {num} not found for fromId")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user