Merge branch 'pr-bletweak' into pr-powermon

# Conflicts:
#	.vscode/launch.json
This commit is contained in:
Kevin Hester
2024-06-30 13:03:33 -07:00
9 changed files with 329 additions and 212 deletions

View File

@@ -1212,7 +1212,10 @@ def initParser():
group.add_argument(
"--seriallog",
help="Log device serial output to either 'stdout', 'none' or a filename to append to.",
help="Log device serial output to either 'none' or a filename to append to. Defaults to 'stdout' if no filename specified.",
nargs='?',
const="stdout",
default=None
)
group.add_argument(

View File

@@ -6,7 +6,7 @@ import logging
import struct
import time
from threading import Thread
from typing import Optional
from typing import List, Optional
from bleak import BleakClient, BleakScanner, BLEDevice
from bleak.exc import BleakDBusError, BleakError
@@ -84,7 +84,7 @@ class BLEInterface(MeshInterface):
self._handleLogLine(log_radio)
@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)...")
@@ -195,7 +195,7 @@ class BLEInterface(MeshInterface):
if self._want_receive:
self.want_receive = False # Tell the thread we want it to stop
self._receiveThread.join()
self._receiveThread.join(timeout=2) # If bleak is hung, don't wait for the thread to exit (it is critical we disconnect)
self._receiveThread = None
if self.client:

View File

@@ -523,11 +523,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
@@ -1055,7 +1055,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:
@@ -1068,7 +1068,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