Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions meshtastic/serial_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -52,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":
Expand All @@ -65,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
Expand Down
9 changes: 4 additions & 5 deletions meshtastic/stream_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ 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: # pylint: disable=C0123
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

Expand Down
15 changes: 6 additions & 9 deletions meshtastic/tcp_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,11 @@ 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

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):
Expand All @@ -68,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)
Expand Down
2 changes: 1 addition & 1 deletion meshtastic/tests/test_stream_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down