Skip to content
Merged
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
1 change: 0 additions & 1 deletion TODO_pylint
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ try-except-raise
unexpected-keyword-arg
unnecessary-comprehension
unnecessary-lambda
unpacking-non-sequence
unspecified-encoding
unused-argument
unused-import
Expand Down
8 changes: 4 additions & 4 deletions examples/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setup_async_client(loop):
_logger.info("### Create client object")

if args.comm == "tcp":
loop, client = AsyncModbusTCPClient( # pylint: disable=unpacking-non-sequence
client = AsyncModbusTCPClient(
host="127.0.0.1", # define tcp address where to connect to.
port=args.port, # on which port
framer=ModbusSocketFramer, # how to interpret the messages
Expand All @@ -60,7 +60,7 @@ def setup_async_client(loop):
loop=loop,
)
elif args.comm == "udp":
loop, client = AsyncModbusUDPClient( # pylint: disable=unpacking-non-sequence
client = AsyncModbusUDPClient(
host="localhost", # define tcp address where to connect to.
port=args.port, # on which port
framer=args.framer, # how to interpret the messages
Expand All @@ -72,7 +72,7 @@ def setup_async_client(loop):
loop=loop,
)
elif args.comm == "serial":
loop, client = AsyncModbusSerialClient( # pylint: disable=unpacking-non-sequence
client = AsyncModbusSerialClient(
port=args.port, # serial port
framer=args.framer, # how to interpret the messages
stopbits=1, # The number of stop bits to use
Expand All @@ -85,7 +85,7 @@ def setup_async_client(loop):
loop=loop,
)
elif args.comm == "tls":
loop, client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
client = AsyncModbusTLSClient(
host="localhost", # define tcp address where to connect to.
port=args.port, # on which port
sslctx=None, # ssl control
Expand Down
4 changes: 3 additions & 1 deletion examples/contrib/asynchronous_asyncio_modbus_tls_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# import necessary libraries
# -------------------------------------------------------------------------- #
import ssl
import asyncio

from pymodbus.client.asynchronous.tls import AsyncModbusTLSClient

Expand Down Expand Up @@ -37,10 +38,11 @@ async def start_async_test(client):
# ----------------------------------------------------------------------- #
# pass SSLContext which is the context here to ModbusTcpClient()
# ----------------------------------------------------------------------- #
loop, new_client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
new_client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
"test.host.com",
8020,
sslctx=sslctx,
)
loop = asyncio.get_running_loop()
loop.run_until_complete(start_async_test(new_client.protocol))
loop.close()
15 changes: 7 additions & 8 deletions pymodbus/client/asynchronous/async_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ModbusTlsFramer,
)


_logger = logging.getLogger(__name__)

DGRAM_TYPE = socket.SOCK_DGRAM
Expand Down Expand Up @@ -236,7 +237,7 @@ def __init__(self, protocol_class=None, framer=None, **kwargs):

:param protocol_class: Protocol used to talk to modbus device.
"""
# If there are no loop running a runtime error will be raised
# get current loop, if there are no loop a RuntimeError will be raised
self.loop = asyncio.get_running_loop()
#: Protocol used to talk to modbus device.
self.protocol_class = protocol_class or ModbusClientProtocol
Expand Down Expand Up @@ -347,17 +348,15 @@ def __init__(self, host=None, port=502, protocol_class=None, framer=None, **kwar
:param port: Port to connect
:param protocol_class: Protocol used to talk to modbus device.
"""
# If there are no loop running a runtime error will be raised
# get current loop, if there are no loop a RuntimeError will be raised
self.loop = asyncio.get_running_loop()
#: Protocol used to talk to modbus device.
self.protocol_class = protocol_class or ModbusClientProtocol
#: Current protocol instance.
self.protocol = None
self.framer = framer if framer else ModbusSocketFramer

self.host = host
self.port = port

self.connected = False
self._proto_args = kwargs

Expand Down Expand Up @@ -422,7 +421,7 @@ def __init__(self, protocol_class=None, framer=None, **kwargs):

:param protocol_class: Protocol used to talk to modbus device.
"""
# If there are no loop running a runtime error will be raised
# get current loop, if there are no loop a RuntimeError will be raised
self.loop = asyncio.get_running_loop()
self.framer = framer if framer else ModbusTlsFramer
self.server_hostname = None
Expand Down Expand Up @@ -493,7 +492,7 @@ def __init__(self, protocol_class=None, framer=None, **kwargs):

:param protocol_class: Protocol used to talk to modbus device.
"""
# If there are no loop running a runtime error will be raised
# get current loop, if there are no loop a RuntimeError will be raised
self.loop = asyncio.get_running_loop()
#: Protocol used to talk to modbus device.
self.protocol_class = protocol_class or ModbusUdpClientProtocol
Expand Down Expand Up @@ -612,7 +611,7 @@ def __init__(self, host=None, port=502, protocol_class=None, framer=None, **kwar
:param port: Port to connect
:param protocol_class: Protocol used to talk to modbus device.
"""
# If there are no loop running a runtime error will be raised
# get current loop, if there are no loop a RuntimeError will be raised
self.loop = asyncio.get_running_loop()
#: Protocol used to talk to modbus device.
self.protocol_class = protocol_class or ModbusUdpClientProtocol
Expand Down Expand Up @@ -711,7 +710,7 @@ def __init__(
:param protocol_class: Protocol used to talk to modbus device.
:param framer: Framer to use
"""
# If there are no loop running a runtime error will be raised
# get current loop, if there are no loop a RuntimeError will be raised
self.loop = asyncio.get_running_loop()
#: Protocol used to talk to modbus device.
self.protocol_class = protocol_class or ModbusRtuFramer
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/asynchronous/factory/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def async_io_factory(port=None, framer=None, **kwargs):
future = asyncio.run_coroutine_threadsafe(coro(), loop=loop)
future.result()

return loop, client
return client
2 changes: 1 addition & 1 deletion pymodbus/client/asynchronous/factory/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):
future = asyncio.run_coroutine_threadsafe(cor, loop=loop)
client = future.result()

return loop, client
return client
4 changes: 2 additions & 2 deletions pymodbus/client/asynchronous/factory/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def async_io_factory(
)
client = loop.run_until_complete(asyncio.gather(cor))[0]
elif loop is asyncio.get_event_loop():
return loop, init_tls_client(
return init_tls_client(
proto_cls, host, port, sslctx, server_hostname, framer, **kwargs
)
else:
Expand All @@ -50,4 +50,4 @@ def async_io_factory(
future = asyncio.run_coroutine_threadsafe(cor, loop=loop)
client = future.result()

return loop, client
return client
4 changes: 2 additions & 2 deletions pymodbus/client/asynchronous/factory/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):
cor = init_udp_client(proto_cls, host, port)
client = loop.run_until_complete(asyncio.gather(cor))[0]
elif loop is asyncio.get_event_loop():
return loop, init_udp_client(proto_cls, host, port)
return init_udp_client(proto_cls, host, port)

cor = init_udp_client(proto_cls, host, port)
client = asyncio.run_coroutine_threadsafe(cor, loop=loop)
client = client.result()

return loop, client
return client
3 changes: 2 additions & 1 deletion pymodbus/client/asynchronous/serial.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""SERIAL communication."""
import logging

from pymodbus.client.asynchronous.async_io import AsyncioModbusSerialClient as serialClient
from pymodbus.client.asynchronous.factory.serial import async_io_factory
from pymodbus.factory import ClientDecoder

_logger = logging.getLogger(__name__)


class AsyncModbusSerialClient: # pylint: disable=too-few-public-methods
class AsyncModbusSerialClient(serialClient):
"""Actual Async Serial Client to be used.

To use do::
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/client/asynchronous/tcp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""TCP communication."""
import logging

from pymodbus.client.asynchronous.async_io import ReconnectingAsyncioModbusTcpClient as tcpClient
from pymodbus.client.asynchronous.factory.tcp import async_io_factory
from pymodbus.constants import Defaults

_logger = logging.getLogger(__name__)


class AsyncModbusTCPClient: # pylint: disable=too-few-public-methods
class AsyncModbusTCPClient(tcpClient):
"""Actual Async Serial Client to be used.
To use do::
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/client/asynchronous/tls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""TLS communication."""
import logging

from pymodbus.client.asynchronous.async_io import ReconnectingAsyncioModbusTlsClient as TlsClient
from pymodbus.client.asynchronous.factory.tls import async_io_factory
from pymodbus.constants import Defaults
from pymodbus.factory import ClientDecoder
Expand All @@ -9,7 +10,7 @@
_logger = logging.getLogger(__name__)


class AsyncModbusTLSClient: # pylint: disable=too-few-public-methods
class AsyncModbusTLSClient(TlsClient):
"""Actual Async TLS Client to be used.

To use do::
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/client/asynchronous/udp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""UDP communication."""
import logging

from pymodbus.client.asynchronous.async_io import ReconnectingAsyncioModbusUdpClient as udpClient
from pymodbus.client.asynchronous.factory.udp import async_io_factory
from pymodbus.constants import Defaults

_logger = logging.getLogger(__name__)


class AsyncModbusUDPClient: # pylint: disable=too-few-public-methods
class AsyncModbusUDPClient(udpClient):
"""Actual Async UDP Client to be used.

To use do::
Expand Down
7 changes: 2 additions & 5 deletions test/test_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_tcp_asyncio_client(

def test_tls_asyncio_client(self):
"""Test the TLS AsyncIO client."""
_, client = AsyncModbusTLSClient() # pylint: disable=unpacking-non-sequence
client = AsyncModbusTLSClient()
assert isinstance(client, ReconnectingAsyncioModbusTlsClient) # nosec
assert isinstance(client.framer, ModbusTlsFramer) # nosec
assert isinstance(client.sslctx, ssl.SSLContext) # nosec
Expand Down Expand Up @@ -107,10 +107,7 @@ async def test_serial_asyncio_client(
"""Test that AsyncModbusSerialClient instantiates AsyncioModbusSerialClient for asyncio scheduler."""
loop = asyncio.get_event_loop()
loop.is_running.side_effect = lambda: False
( # pylint: disable=unpacking-non-sequence
loop,
client,
) = AsyncModbusSerialClient(
client = AsyncModbusSerialClient(
framer=framer,
port=pytest.SERIAL_PORT,
loop=loop,
Expand Down
7 changes: 2 additions & 5 deletions test/test_client_async2.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestAsynchronousClient:
# -----------------------------------------------------------------------#
def test_tls_asyncio_client(self):
"""Test the TLS AsyncIO client."""
_, client = AsyncModbusTLSClient() # pylint: disable=unpacking-non-sequence
client = AsyncModbusTLSClient()
assert isinstance(client, ReconnectingAsyncioModbusTlsClient) # nosec
assert isinstance(client.framer, ModbusTlsFramer) # nosec
assert isinstance(client.sslctx, ssl.SSLContext) # nosec
Expand Down Expand Up @@ -94,10 +94,7 @@ async def test_serial_asyncio_client(
"""Test that AsyncModbusSerialClient instantiates AsyncioModbusSerialClient for asyncio scheduler."""
loop = asyncio.get_event_loop()
loop.is_running.side_effect = lambda: False
( # pylint: disable=unpacking-non-sequence
loop,
client,
) = AsyncModbusSerialClient(
client = AsyncModbusSerialClient(
framer=framer,
port=pytest.SERIAL_PORT,
loop=loop,
Expand Down
10 changes: 4 additions & 6 deletions test/test_client_async_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ async def test_factory_initialization_state(self):

async def test_initialization_tcp_in_loop(self):
"""Test initialization tcp in loop."""
_, client = AsyncModbusTCPClient( # pylint: disable=unpacking-non-sequence
port=5020,
)
client = AsyncModbusTCPClient(port=5020)
client = await client

assert not client.connected # nosec
Expand All @@ -104,7 +102,7 @@ async def test_initialization_tcp_in_loop(self):

async def test_initialization_udp_in_loop(self):
"""Test initialization udp in loop."""
_, client = AsyncModbusUDPClient() # pylint: disable=unpacking-non-sequence
client = AsyncModbusUDPClient()
client = await client

assert client.connected # nosec
Expand All @@ -113,7 +111,7 @@ async def test_initialization_udp_in_loop(self):

async def test_initialization_tls_in_loop(self):
"""Test initialization tls in loop."""
_, client = AsyncModbusTLSClient() # pylint: disable=unpacking-non-sequence
client = AsyncModbusTLSClient()
client = await client

assert not client.connected # nosec
Expand All @@ -123,7 +121,7 @@ async def test_initialization_tls_in_loop(self):
@pytest.mark.skip("To fix")
def test_initialization_serial_in_loop(self):
"""Test initialization serial in loop."""
_, client = AsyncModbusSerialClient( # pylint: disable=unpacking-non-sequence
client = AsyncModbusSerialClient(
port="/tmp/ptyp0", baudrate=9600, framer=ModbusRtuFramer # nosec
)
assert client.port == "/tmp/ptyp0" # nosec
Expand Down