diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 2870556..9aeef2e 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -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: diff --git a/meshtastic/ble_interface.py b/meshtastic/ble_interface.py index f020979..76e5dc3 100644 --- a/meshtastic/ble_interface.py +++ b/meshtastic/ble_interface.py @@ -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: diff --git a/meshtastic/mt_config.py b/meshtastic/mt_config.py index 662a10d..3b40294 100644 --- a/meshtastic/mt_config.py +++ b/meshtastic/mt_config.py @@ -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 diff --git a/meshtastic/stream_interface.py b/meshtastic/stream_interface.py index abaef4a..c1fecab 100644 --- a/meshtastic/stream_interface.py +++ b/meshtastic/stream_interface.py @@ -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: diff --git a/meshtastic/util.py b/meshtastic/util.py index 2490660..2e0a989 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -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)