From 7920180137a2850a72a21ff47b3e222d2ecd6a4c Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Fri, 18 Jul 2025 14:16:56 +0200 Subject: [PATCH] enable error_only logging --- pyproject.toml | 2 +- src/meshcore/meshcore.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index baf7136..9eaa197 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "meshcore" -version = "1.9.16" +version = "1.9.17" authors = [ { name="Florent de Lamotte", email="florent@frizoncorrea.fr" }, { name="Alex Wolden", email="awolden@gmail.com" }, diff --git a/src/meshcore/meshcore.py b/src/meshcore/meshcore.py index a4de96c..0ce7a6c 100644 --- a/src/meshcore/meshcore.py +++ b/src/meshcore/meshcore.py @@ -17,7 +17,7 @@ class MeshCore: """ Interface to a MeshCore device """ - def __init__(self, cx, debug=False, default_timeout=None, auto_reconnect=False, max_reconnect_attempts=3): + def __init__(self, cx, debug=False, only_error=False, default_timeout=None, auto_reconnect=False, max_reconnect_attempts=3): # Wrap connection with ConnectionManager self.dispatcher = EventDispatcher() self.connection_manager = ConnectionManager( @@ -31,6 +31,8 @@ class MeshCore: # Set up logger if debug: logger.setLevel(logging.DEBUG) + elif only_error: + logger.setLevel(logging.ERROR) else: logger.setLevel(logging.INFO) @@ -59,29 +61,29 @@ class MeshCore: cx.set_disconnect_callback(self.connection_manager.handle_disconnect) @classmethod - async def create_tcp(cls, host: str, port: int, debug: bool = False, default_timeout=None, + async def create_tcp(cls, host: str, port: int, debug: bool = False, only_error:bool = False, default_timeout=None, auto_reconnect: bool = False, max_reconnect_attempts: int = 3) -> 'MeshCore': """Create and connect a MeshCore instance using TCP connection""" connection = TCPConnection(host, port) - mc = cls(connection, debug=debug, default_timeout=default_timeout, + mc = cls(connection, debug=debug, only_error=only_error, default_timeout=default_timeout, auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts) await mc.connect() return mc @classmethod - async def create_serial(cls, port: str, baudrate: int = 115200, debug: bool = False, default_timeout=None, + async def create_serial(cls, port: str, baudrate: int = 115200, debug: bool = False, only_error:bool=False, default_timeout=None, auto_reconnect: bool = False, max_reconnect_attempts: int = 3, cx_dly:float = 0.1) -> 'MeshCore': """Create and connect a MeshCore instance using serial connection""" connection = SerialConnection(port, baudrate, cx_dly=cx_dly) - mc = cls(connection, debug=debug, default_timeout=default_timeout, + mc = cls(connection, debug=debug, only_error=only_error, default_timeout=default_timeout, auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts) await mc.connect() return mc @classmethod - async def create_ble(cls, address: Optional[str] = None, debug: bool = False, default_timeout=None, + async def create_ble(cls, address: Optional[str] = None, debug: bool = False, only_error:bool=False, default_timeout=None, auto_reconnect: bool = False, max_reconnect_attempts: int = 3) -> 'MeshCore': """Create and connect a MeshCore instance using BLE connection @@ -90,7 +92,7 @@ class MeshCore: connection = BLEConnection(address) - mc = cls(connection, debug=debug, default_timeout=default_timeout, + mc = cls(connection, debug=debug, only_error=only_error, default_timeout=default_timeout, auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts) await mc.connect() return mc