diff --git a/meshtastic/ble_interface.py b/meshtastic/ble_interface.py index c4b542f..28d55cd 100644 --- a/meshtastic/ble_interface.py +++ b/meshtastic/ble_interface.py @@ -7,6 +7,8 @@ import asyncio from threading import Thread, Event from bleak import BleakScanner, BleakClient +from typing import Optional + from meshtastic.mesh_interface import MeshInterface from meshtastic.util import our_exit @@ -30,7 +32,7 @@ class BLEInterface(MeshInterface): MESH = False - def __init__(self, address, noProto = False, debugOut = None): + def __init__(self, address: Optional[str], noProto: bool = False, debugOut = None): self.state = BLEInterface.BLEState() if not address: diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index 0ae68aa..e3c3a48 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -6,6 +6,8 @@ import time import serial # type: ignore[import-untyped] +from typing import Optional + import meshtastic.util from meshtastic.stream_interface import StreamInterface @@ -16,7 +18,7 @@ if platform.system() != "Windows": class SerialInterface(StreamInterface): """Interface class for meshtastic devices over a serial link""" - def __init__(self, devPath=None, debugOut=None, noProto=False, connectNow=True): + def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto=False, connectNow=True): """Constructor, opens a connection to a specified serial port, or if unspecified try to find one Meshtastic device by probing @@ -26,7 +28,7 @@ class SerialInterface(StreamInterface): """ self.noProto = noProto - self.devPath = devPath + self.devPath: Optional[str] = devPath if self.devPath is None: ports = meshtastic.util.findPorts(True) diff --git a/meshtastic/util.py b/meshtastic/util.py index f9e1b1e..bc24e33 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -11,7 +11,7 @@ import threading import time import traceback from queue import Queue -from typing import Union +from typing import List, NoReturn, Union from google.protobuf.json_format import MessageToJson @@ -122,7 +122,7 @@ def catchAndIgnore(reason, closure): logging.error(f"Exception thrown in {reason}: {ex}") -def findPorts(eliminate_duplicates=False): +def findPorts(eliminate_duplicates: bool=False) -> List[str]: """Find all ports that might have meshtastic devices eliminate_duplicates will run the eliminate_duplicate_port() on the collection @@ -263,7 +263,7 @@ class DeferredExecution: print(traceback.format_exc()) -def our_exit(message, return_value=1): +def our_exit(message, return_value=1) -> NoReturn: """Print the message and return a value. return_value defaults to 1 (non-successful) """