From 7d42eaf92fda11e035d2fda799d75c457713650e Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sun, 8 Dec 2024 12:49:37 +0100 Subject: [PATCH] Fix too many sync client log messages. --- pymodbus/client/base.py | 1 - pymodbus/client/tls.py | 2 +- pymodbus/transaction/transaction.py | 6 ++---- test/client/test_client_sync.py | 2 +- test/transaction/test_transaction.py | 3 +++ 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 41c574b4b..1f930d5e3 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -149,7 +149,6 @@ def __init__( self.state = ModbusTransactionState.IDLE self.last_frame_end: float | None = 0 self.silent_interval: float = 0 - self.transport = None # ----------------------------------------------------------------------- # # Client external interface diff --git a/pymodbus/client/tls.py b/pymodbus/client/tls.py index 1dd67139c..ea7dc199b 100644 --- a/pymodbus/client/tls.py +++ b/pymodbus/client/tls.py @@ -222,7 +222,7 @@ def generate_ssl( @property def connected(self) -> bool: """Connect internal.""" - return self.transport is not None + return self.socket is not None def connect(self): """Connect to the modbus tls server.""" diff --git a/pymodbus/transaction/transaction.py b/pymodbus/transaction/transaction.py index 4da945025..6bea652b5 100644 --- a/pymodbus/transaction/transaction.py +++ b/pymodbus/transaction/transaction.py @@ -96,10 +96,8 @@ def sync_execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbus REMARK: this method is identical to execute, apart from the lock and sync_receive. any changes in either method MUST be mirrored !!! """ - if not self.transport: - Log.warning("Not connected, trying to connect!") - if not self.sync_client.connect(): - raise ConnectionException("Client cannot connect (automatic retry continuing) !!") + if not self.sync_client.connect(): + raise ConnectionException("Client cannot connect (automatic retry continuing) !!") with self._sync_lock: request.transaction_id = self.getNextTID() count_retries = 0 diff --git a/test/client/test_client_sync.py b/test/client/test_client_sync.py index 69b1da9f5..dafda7438 100755 --- a/test/client/test_client_sync.py +++ b/test/client/test_client_sync.py @@ -213,7 +213,7 @@ def test_basic_syn_tls_client(self, mock_select): assert client.recv(1) == b"\x45" # connect/disconnect - assert not client.connected + assert client.connected assert client.connect() client.close() diff --git a/test/transaction/test_transaction.py b/test/transaction/test_transaction.py index 0876d0e0e..deca90016 100755 --- a/test/transaction/test_transaction.py +++ b/test/transaction/test_transaction.py @@ -333,6 +333,7 @@ def test_sync_transaction_receiver(self, use_clc): None, sync_client=client, ) + transact.sync_client.connect = mock.Mock(return_value=True) transact.sync_client.send = mock.Mock() request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False]) @@ -366,6 +367,7 @@ def test_sync_client_protocol_execute_outside(self, use_clc, no_resp): None, sync_client=client, ) + transact.sync_client.connect = mock.Mock(return_value=True) request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False]) transact.retries = 0 @@ -400,6 +402,7 @@ def test_sync_client_protocol_execute_no_pdu(self, use_clc): None, sync_client=client, ) + transact.sync_client.connect = mock.Mock(return_value=True) request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False]) transact.retries = 0