mirror of
https://github.com/meshtastic/python.git
synced 2026-01-01 04:17:59 -05:00
Fix some remaining mypy complaints
This commit is contained in:
@@ -130,7 +130,7 @@ def getPref(node, comp_name) -> bool:
|
||||
return False
|
||||
|
||||
# Check if we need to request the config
|
||||
if len(config.ListFields()) != 0:
|
||||
if len(config.ListFields()) != 0 and not isinstance(pref, str): # if str, it's still the empty string, I think
|
||||
# read the value
|
||||
config_values = getattr(config, config_type.name)
|
||||
if not wholeField:
|
||||
|
||||
@@ -174,6 +174,10 @@ class BLEInterface(MeshInterface):
|
||||
self.should_read = False
|
||||
retries: int = 0
|
||||
while self._want_receive:
|
||||
if self.client is None:
|
||||
logging.debug(f"BLE client is None, shutting down")
|
||||
self._want_receive = False
|
||||
continue
|
||||
try:
|
||||
b = bytes(self.client.read_gatt_char(FROMRADIO_UUID))
|
||||
except BleakDBusError as e:
|
||||
|
||||
@@ -13,6 +13,8 @@ with rather more easily once the code is simplified by this change.
|
||||
|
||||
"""
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
def reset():
|
||||
"""
|
||||
Restore the namespace to pristine condition.
|
||||
@@ -33,5 +35,5 @@ args = None
|
||||
parser = None
|
||||
channel_index = None
|
||||
logfile = None
|
||||
tunnelInstance = None
|
||||
tunnelInstance: Optional[Any] = None
|
||||
camel_case = False
|
||||
|
||||
@@ -38,6 +38,7 @@ class StreamInterface(MeshInterface):
|
||||
raise Exception( # pylint: disable=W0719
|
||||
"StreamInterface is now abstract (to update existing code create SerialInterface instead)"
|
||||
)
|
||||
self.stream: Optional[serial.Serial] # only serial uses this, TCPInterface overrides the relevant methods instead
|
||||
self._rxBuf = bytes() # empty
|
||||
self._wantExit = False
|
||||
|
||||
@@ -115,7 +116,7 @@ class StreamInterface(MeshInterface):
|
||||
bufLen: int = len(b)
|
||||
# We convert into a string, because the TCP code doesn't work with byte arrays
|
||||
header: bytes = bytes([START1, START2, (bufLen >> 8) & 0xFF, bufLen & 0xFF])
|
||||
logging.debug(f"sending header:{header} b:{b}")
|
||||
logging.debug(f"sending header:{header!r} b:{b!r}")
|
||||
self._writeBytes(header + b)
|
||||
|
||||
def close(self) -> None:
|
||||
|
||||
@@ -369,13 +369,12 @@ def readnet_u16(p, offset: int) -> int:
|
||||
return p[offset] * 256 + p[offset + 1]
|
||||
|
||||
|
||||
def convert_mac_addr(val: bytes) -> Union[str, bytes]:
|
||||
def convert_mac_addr(val: str) -> Union[str, bytes]:
|
||||
"""Convert the base 64 encoded value to a mac address
|
||||
val - base64 encoded value (ex: '/c0gFyhb'))
|
||||
returns: a string formatted like a mac address (ex: 'fd:cd:20:17:28:5b')
|
||||
"""
|
||||
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
|
||||
#match val since val is bytes?
|
||||
if not re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", val):
|
||||
val_as_bytes: bytes = base64.b64decode(val)
|
||||
return hexstr(val_as_bytes)
|
||||
return val
|
||||
@@ -656,6 +655,8 @@ def check_if_newer_version() -> Optional[str]:
|
||||
pass
|
||||
act_version = get_active_version()
|
||||
|
||||
if pypi_version is None:
|
||||
return None
|
||||
try:
|
||||
parsed_act_version = pkg_version.parse(act_version)
|
||||
parsed_pypi_version = pkg_version.parse(pypi_version)
|
||||
|
||||
Reference in New Issue
Block a user