Skip to content

Commit 384063d

Browse files
committed
Fix some remaining mypy complaints
1 parent 20d75d9 commit 384063d

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

meshtastic/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _printSetting(config_type, uni_name, pref_value, repeated):
130130
return False
131131

132132
# Check if we need to request the config
133-
if len(config.ListFields()) != 0:
133+
if len(config.ListFields()) != 0 and not isinstance(pref, str): # if str, it's still the empty string, I think
134134
# read the value
135135
config_values = getattr(config, config_type.name)
136136
if not wholeField:

meshtastic/ble_interface.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ def _receiveFromRadioImpl(self) -> None:
174174
self.should_read = False
175175
retries: int = 0
176176
while self._want_receive:
177+
if self.client is None:
178+
logging.debug(f"BLE client is None, shutting down")
179+
self._want_receive = False
180+
continue
177181
try:
178182
b = bytes(self.client.read_gatt_char(FROMRADIO_UUID))
179183
except BleakDBusError as e:

meshtastic/mt_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
1414
"""
1515

16+
from typing import Any, Optional
17+
1618
def reset():
1719
"""
1820
Restore the namespace to pristine condition.
@@ -33,5 +35,5 @@ def reset():
3335
parser = None
3436
channel_index = None
3537
logfile = None
36-
tunnelInstance = None
38+
tunnelInstance: Optional[Any] = None
3739
camel_case = False

meshtastic/stream_interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, debugOut: Optional[io.TextIOWrapper]=None, noProto: bool=Fals
3838
raise Exception( # pylint: disable=W0719
3939
"StreamInterface is now abstract (to update existing code create SerialInterface instead)"
4040
)
41+
self.stream: Optional[serial.Serial] # only serial uses this, TCPInterface overrides the relevant methods instead
4142
self._rxBuf = bytes() # empty
4243
self._wantExit = False
4344

@@ -115,7 +116,7 @@ def _sendToRadioImpl(self, toRadio) -> None:
115116
bufLen: int = len(b)
116117
# We convert into a string, because the TCP code doesn't work with byte arrays
117118
header: bytes = bytes([START1, START2, (bufLen >> 8) & 0xFF, bufLen & 0xFF])
118-
logging.debug(f"sending header:{header} b:{b}")
119+
logging.debug(f"sending header:{header!r} b:{b!r}")
119120
self._writeBytes(header + b)
120121

121122
def close(self) -> None:

meshtastic/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,12 @@ def readnet_u16(p, offset: int) -> int:
369369
return p[offset] * 256 + p[offset + 1]
370370

371371

372-
def convert_mac_addr(val: bytes) -> Union[str, bytes]:
372+
def convert_mac_addr(val: str) -> Union[str, bytes]:
373373
"""Convert the base 64 encoded value to a mac address
374374
val - base64 encoded value (ex: '/c0gFyhb'))
375375
returns: a string formatted like a mac address (ex: 'fd:cd:20:17:28:5b')
376376
"""
377-
if not re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", val): #FIXME - does the regex have to be bytes too to
378-
#match val since val is bytes?
377+
if not re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", val):
379378
val_as_bytes: bytes = base64.b64decode(val)
380379
return hexstr(val_as_bytes)
381380
return val
@@ -656,6 +655,8 @@ def check_if_newer_version() -> Optional[str]:
656655
pass
657656
act_version = get_active_version()
658657

658+
if pypi_version is None:
659+
return None
659660
try:
660661
parsed_act_version = pkg_version.parse(act_version)
661662
parsed_pypi_version = pkg_version.parse(pypi_version)

0 commit comments

Comments
 (0)