|
8 | 8 | from threading import Thread |
9 | 9 | from typing import List, Optional |
10 | 10 |
|
| 11 | +import google.protobuf |
11 | 12 | from bleak import BleakClient, BleakScanner, BLEDevice |
12 | 13 | from bleak.exc import BleakDBusError, BleakError |
13 | 14 |
|
14 | | -import google.protobuf |
15 | | - |
16 | 15 | from meshtastic.mesh_interface import MeshInterface |
17 | 16 |
|
18 | | -from .protobuf import ( |
19 | | - mesh_pb2, |
20 | | -) |
| 17 | +from .protobuf import mesh_pb2 |
| 18 | + |
21 | 19 | SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd" |
22 | 20 | TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7" |
23 | 21 | FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002" |
@@ -63,7 +61,9 @@ def __init__( |
63 | 61 | raise e |
64 | 62 |
|
65 | 63 | if self.client.has_characteristic(LEGACY_LOGRADIO_UUID): |
66 | | - self.client.start_notify(LEGACY_LOGRADIO_UUID, self.legacy_log_radio_handler) |
| 64 | + self.client.start_notify( |
| 65 | + LEGACY_LOGRADIO_UUID, self.legacy_log_radio_handler |
| 66 | + ) |
67 | 67 |
|
68 | 68 | if self.client.has_characteristic(LOGRADIO_UUID): |
69 | 69 | self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler) |
@@ -94,11 +94,15 @@ async def log_radio_handler(self, _, b): # pylint: disable=C0116 |
94 | 94 | log_record = mesh_pb2.LogRecord() |
95 | 95 | try: |
96 | 96 | log_record.ParseFromString(bytes(b)) |
97 | | - except google.protobuf.message.DecodeError: |
98 | | - return |
99 | 97 |
|
100 | | - message = f'[{log_record.source}] {log_record.message}' if log_record.source else log_record.message |
101 | | - self._handleLogLine(message) |
| 98 | + message = ( |
| 99 | + f"[{log_record.source}] {log_record.message}" |
| 100 | + if log_record.source |
| 101 | + else log_record.message |
| 102 | + ) |
| 103 | + self._handleLogLine(message) |
| 104 | + except google.protobuf.message.DecodeError: |
| 105 | + logging.warning("Malformed LogRecord received. Skipping.") |
102 | 106 |
|
103 | 107 | async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116 |
104 | 108 | log_radio = b.decode("utf-8").replace("\n", "") |
@@ -215,7 +219,9 @@ def close(self): |
215 | 219 |
|
216 | 220 | if self._want_receive: |
217 | 221 | self.want_receive = False # Tell the thread we want it to stop |
218 | | - self._receiveThread.join(timeout=2) # If bleak is hung, don't wait for the thread to exit (it is critical we disconnect) |
| 222 | + self._receiveThread.join( |
| 223 | + timeout=2 |
| 224 | + ) # If bleak is hung, don't wait for the thread to exit (it is critical we disconnect) |
219 | 225 | self._receiveThread = None |
220 | 226 |
|
221 | 227 | if self.client: |
|
0 commit comments