Skip to content

Commit 14f5339

Browse files
committed
Merge commit 'refs/pull/857/head' of github.com:meshtastic/python into tmp/merge-918-857
2 parents 4d8091a + 1214d50 commit 14f5339

4 files changed

Lines changed: 17 additions & 20 deletions

File tree

meshtastic/serial_interface.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ def __init__(
3535
debugOut {stream} -- If a stream is provided, any debug serial output from the device will be emitted to that stream. (default: {None})
3636
timeout -- How long to wait for replies (default: 300 seconds)
3737
"""
38-
self.noProto = noProto
39-
4038
self.devPath: Optional[str] = devPath
4139

4240
if self.devPath is None:
@@ -52,6 +50,11 @@ def __init__(
5250
else:
5351
self.devPath = ports[0]
5452

53+
StreamInterface.__init__(
54+
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout
55+
)
56+
57+
def connect(self) -> None:
5558
logger.debug(f"Connecting to {self.devPath}")
5659

5760
if sys.platform != "win32":
@@ -65,9 +68,7 @@ def __init__(
6568
self.stream.flush() # type: ignore[attr-defined]
6669
time.sleep(0.1)
6770

68-
StreamInterface.__init__(
69-
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout
70-
)
71+
super().connect()
7172

7273
def _set_hupcl_with_termios(self, f: TextIOWrapper):
7374
"""first we need to set the HUPCL so the device will not reboot based on RTS and/or DTR

meshtastic/stream_interface.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ def __init__( # pylint: disable=R0917
4040
timeout -- How long to wait for replies (default: 300 seconds)
4141
4242
Raises:
43-
Exception: [description]
44-
Exception: [description]
43+
RuntimeError: Raised if StreamInterface is instantiated when noProto is false.
4544
"""
4645

47-
if not hasattr(self, "stream") and not noProto:
48-
raise Exception( # pylint: disable=W0719
46+
if not noProto and type(self) == StreamInterface: # pylint: disable=C0123
47+
raise RuntimeError(
4948
"StreamInterface is now abstract (to update existing code create SerialInterface instead)"
5049
)
51-
self.stream: Optional[serial.Serial] # only serial uses this, TCPInterface overrides the relevant methods instead
50+
self.stream: Optional[serial.Serial] = None # only serial uses this, TCPInterface overrides the relevant methods instead
5251
self._rxBuf = bytes() # empty
5352
self._wantExit = False
5453

meshtastic/tcp_interface.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,11 @@ def __init__(
3131
hostname {string} -- Hostname/IP address of the device to connect to
3232
timeout -- How long to wait for replies (default: 300 seconds)
3333
"""
34-
35-
self.stream = None
36-
3734
self.hostname: str = hostname
3835
self.portNumber: int = portNumber
3936

4037
self.socket: Optional[socket.socket] = None
4138

42-
if connectNow:
43-
self.myConnect()
44-
else:
45-
self.socket = None
46-
4739
super().__init__(debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes, timeout=timeout)
4840

4941
def __repr__(self):
@@ -68,8 +60,13 @@ def _socket_shutdown(self) -> None:
6860
if self.socket is not None:
6961
self.socket.shutdown(socket.SHUT_RDWR)
7062

63+
def connect(self) -> None:
64+
"""Connect the interface"""
65+
self.myConnect()
66+
super().connect()
67+
7168
def myConnect(self) -> None:
72-
"""Connect to socket"""
69+
"""Connect to socket (without attempting to start the interface's receive thread"""
7370
logger.debug(f"Connecting to {self.hostname}") # type: ignore[str-bytes-safe]
7471
server_address = (self.hostname, self.portNumber)
7572
self.socket = socket.create_connection(server_address)

meshtastic/tests/test_stream_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_StreamInterface():
1515
"""Test that we cannot instantiate a StreamInterface based on noProto"""
1616
with pytest.raises(Exception) as pytest_wrapped_e:
1717
StreamInterface()
18-
assert pytest_wrapped_e.type == Exception
18+
assert pytest_wrapped_e.type == RuntimeError
1919

2020

2121
@pytest.mark.unit

0 commit comments

Comments
 (0)