From e8b3e11d3c0b9f88f94862eebe16939554fb2160 Mon Sep 17 00:00:00 2001 From: Alex <52292902+alexrudd2@users.noreply.github.com> Date: Sat, 10 Feb 2024 13:19:38 -0600 Subject: [PATCH] Improve client types (#1997) --- pymodbus/client/base.py | 8 ++++---- test/sub_client/test_client.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 7d5abe9de..119999a88 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -150,7 +150,7 @@ def execute(self, request: ModbusRequest | None = None): # ----------------------------------------------------------------------- # # Merged client methods # ----------------------------------------------------------------------- # - async def async_execute(self, request=None) -> ModbusResponse: + async def async_execute(self, request) -> ModbusResponse: """Execute requests asynchronously.""" request.transaction_id = self.transaction.getNextTID() packet = self.framer.buildPacket(request) @@ -186,7 +186,7 @@ def callback_data(self, data: bytes, addr: tuple | None = None) -> int: self.framer.processIncomingPacket(data, self._handle_response, slave=0) return len(data) - async def connect(self): + async def connect(self) -> bool: # type: ignore[empty-body] """Connect to the modbus remote host.""" def raise_future(self, my_future, exc): @@ -241,7 +241,7 @@ async def __aenter__(self): return self async def __aexit__(self, klass, value, traceback): - """Implement the client with exit block.""" + """Implement the client with aexit block.""" self.close() def __str__(self): @@ -414,7 +414,7 @@ def get_address_family(cls, address): return socket.AF_INET return socket.AF_INET6 - def connect(self): + def connect(self) -> bool: # type: ignore[empty-body] """Connect to other end, overwritten.""" def close(self): diff --git a/test/sub_client/test_client.py b/test/sub_client/test_client.py index d668c4c9d..0af821878 100755 --- a/test/sub_client/test_client.py +++ b/test/sub_client/test_client.py @@ -599,6 +599,7 @@ async def test_client_build_response(): with pytest.raises(ConnectionException): await client.build_response(0) + async def test_client_mixin_execute(): """Test dummy execute for both sync and async.""" client = ModbusClientMixin()