From 79334e83e6dc94c472a990849701fc372ca609cf Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Tue, 11 Nov 2025 18:57:52 +1030 Subject: [PATCH 1/7] Adjusting old deprecation test and exception for non-abstract use of StreamInterface --- meshtastic/stream_interface.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/meshtastic/stream_interface.py b/meshtastic/stream_interface.py index 06ee28a3..1cd4db1e 100644 --- a/meshtastic/stream_interface.py +++ b/meshtastic/stream_interface.py @@ -39,12 +39,11 @@ def __init__( # pylint: disable=R0917 timeout -- How long to wait for replies (default: 300 seconds) Raises: - Exception: [description] - Exception: [description] + RuntimeError: Raised if StreamInterface is instantiated when noProto is false. """ - if not hasattr(self, "stream") and not noProto: - raise Exception( # pylint: disable=W0719 + if not noProto and type(self) == StreamInterface: + raise RuntimeError( "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 From f3f17a7d50b7b8f368de488f19b09b054d60916b Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Tue, 11 Nov 2025 19:02:54 +1030 Subject: [PATCH 2/7] Removing superfluous setting of noProto in init() --- meshtastic/serial_interface.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index 8d1397c6..96e1bcce 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -35,8 +35,6 @@ def __init__( debugOut {stream} -- If a stream is provided, any debug serial output from the device will be emitted to that stream. (default: {None}) timeout -- How long to wait for replies (default: 300 seconds) """ - self.noProto = noProto - self.devPath: Optional[str] = devPath if self.devPath is None: From 040f332078085fc04710c63d67388fc0c7f07293 Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Tue, 11 Nov 2025 19:14:42 +1030 Subject: [PATCH 3/7] Updating test for change of deprecation exception --- meshtastic/tests/test_stream_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshtastic/tests/test_stream_interface.py b/meshtastic/tests/test_stream_interface.py index 3411ffb8..1e1d5e3c 100644 --- a/meshtastic/tests/test_stream_interface.py +++ b/meshtastic/tests/test_stream_interface.py @@ -15,7 +15,7 @@ def test_StreamInterface(): """Test that we cannot instantiate a StreamInterface based on noProto""" with pytest.raises(Exception) as pytest_wrapped_e: StreamInterface() - assert pytest_wrapped_e.type == Exception + assert pytest_wrapped_e.type == RuntimeError # Note: This takes a bit, so moving from unit to slow From 2245ac8d970bf827b32b85eadce6d74ad5f03d2f Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Tue, 11 Nov 2025 19:18:00 +1030 Subject: [PATCH 4/7] Shifting serial interface connection parts from __init__() into connect() method --- meshtastic/serial_interface.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index 96e1bcce..e80bc2d6 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -50,6 +50,11 @@ def __init__( else: self.devPath = ports[0] + StreamInterface.__init__( + self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout + ) + + def connect(self) -> None: logger.debug(f"Connecting to {self.devPath}") if sys.platform != "win32": @@ -63,9 +68,7 @@ def __init__( self.stream.flush() # type: ignore[attr-defined] time.sleep(0.1) - StreamInterface.__init__( - self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout - ) + super().connect() def _set_hupcl_with_termios(self, f: TextIOWrapper): """first we need to set the HUPCL so the device will not reboot based on RTS and/or DTR From 3be73b42e219ab4c5235c77e417c7ee018357008 Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Tue, 11 Nov 2025 19:19:44 +1030 Subject: [PATCH 5/7] Removing unnecessary initialization of self.stream in TCPInterface --- meshtastic/stream_interface.py | 2 +- meshtastic/tcp_interface.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/meshtastic/stream_interface.py b/meshtastic/stream_interface.py index 1cd4db1e..fc7e9bc3 100644 --- a/meshtastic/stream_interface.py +++ b/meshtastic/stream_interface.py @@ -46,7 +46,7 @@ def __init__( # pylint: disable=R0917 raise RuntimeError( "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.stream: Optional[serial.Serial] = None # only serial uses this, TCPInterface overrides the relevant methods instead self._rxBuf = bytes() # empty self._wantExit = False diff --git a/meshtastic/tcp_interface.py b/meshtastic/tcp_interface.py index 732f37ef..c9bdc520 100644 --- a/meshtastic/tcp_interface.py +++ b/meshtastic/tcp_interface.py @@ -31,9 +31,6 @@ def __init__( hostname {string} -- Hostname/IP address of the device to connect to timeout -- How long to wait for replies (default: 300 seconds) """ - - self.stream = None - self.hostname: str = hostname self.portNumber: int = portNumber From 76418b8e574a3a216a572d6e720c5aa060a35512 Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Tue, 11 Nov 2025 19:25:51 +1030 Subject: [PATCH 6/7] Reorganising connect method calls for when connectNow is false --- meshtastic/tcp_interface.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/meshtastic/tcp_interface.py b/meshtastic/tcp_interface.py index c9bdc520..9fbd7fec 100644 --- a/meshtastic/tcp_interface.py +++ b/meshtastic/tcp_interface.py @@ -36,11 +36,6 @@ def __init__( self.socket: Optional[socket.socket] = None - if connectNow: - self.myConnect() - else: - self.socket = None - super().__init__(debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout) def __repr__(self): @@ -65,8 +60,13 @@ def _socket_shutdown(self) -> None: if self.socket is not None: self.socket.shutdown(socket.SHUT_RDWR) + def connect(self) -> None: + """Connect the interface""" + self.myConnect() + super().connect() + def myConnect(self) -> None: - """Connect to socket""" + """Connect to socket (without attempting to start the interface's receive thread""" logger.debug(f"Connecting to {self.hostname}") # type: ignore[str-bytes-safe] server_address = (self.hostname, self.portNumber) self.socket = socket.create_connection(server_address) From 1214d5010bcfa8986b6e2797ed5e1a8fc7f20b20 Mon Sep 17 00:00:00 2001 From: Travis-L-R <> Date: Thu, 13 Nov 2025 07:38:25 +1030 Subject: [PATCH 7/7] Linting adjustment for change to StreamInterface non-abstract use check --- meshtastic/stream_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshtastic/stream_interface.py b/meshtastic/stream_interface.py index fc7e9bc3..a13404d2 100644 --- a/meshtastic/stream_interface.py +++ b/meshtastic/stream_interface.py @@ -42,7 +42,7 @@ def __init__( # pylint: disable=R0917 RuntimeError: Raised if StreamInterface is instantiated when noProto is false. """ - if not noProto and type(self) == StreamInterface: + if not noProto and type(self) == StreamInterface: # pylint: disable=C0123 raise RuntimeError( "StreamInterface is now abstract (to update existing code create SerialInterface instead)" )