From e331bea4ea8a94db943ec828844f119b99c3af41 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sun, 30 Jun 2024 09:58:32 -0700 Subject: [PATCH 1/2] make typing a little more 3.8-approved --- meshtastic/ble_interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meshtastic/ble_interface.py b/meshtastic/ble_interface.py index 69cb9a3..bb6e8ec 100644 --- a/meshtastic/ble_interface.py +++ b/meshtastic/ble_interface.py @@ -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)...") From 93fbc78492783f6ced2eed18de5801ec3297ce83 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sun, 30 Jun 2024 10:04:54 -0700 Subject: [PATCH 2/2] Properly handle missing nodes in traceroute response (fixes #612) --- meshtastic/mesh_interface.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 49e87fd..bf7d715 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -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