Skip to content

Commit 8afab5c

Browse files
authored
Remove loop from return of Modbus<something>Client (#1000)
When creating an object, normally only the object pointer is returned, returning loop,client is causing problems and not needed.
1 parent 0635fb0 commit 8afab5c

File tree

15 files changed

+36
-40
lines changed

15 files changed

+36
-40
lines changed

TODO_pylint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ try-except-raise
6262
unexpected-keyword-arg
6363
unnecessary-comprehension
6464
unnecessary-lambda
65-
unpacking-non-sequence
6665
unspecified-encoding
6766
unused-argument
6867
unused-import

examples/client_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def setup_async_client(loop):
4848
_logger.info("### Create client object")
4949

5050
if args.comm == "tcp":
51-
loop, client = AsyncModbusTCPClient( # pylint: disable=unpacking-non-sequence
51+
client = AsyncModbusTCPClient(
5252
host="127.0.0.1", # define tcp address where to connect to.
5353
port=args.port, # on which port
5454
framer=ModbusSocketFramer, # how to interpret the messages
@@ -60,7 +60,7 @@ def setup_async_client(loop):
6060
loop=loop,
6161
)
6262
elif args.comm == "udp":
63-
loop, client = AsyncModbusUDPClient( # pylint: disable=unpacking-non-sequence
63+
client = AsyncModbusUDPClient(
6464
host="localhost", # define tcp address where to connect to.
6565
port=args.port, # on which port
6666
framer=args.framer, # how to interpret the messages
@@ -72,7 +72,7 @@ def setup_async_client(loop):
7272
loop=loop,
7373
)
7474
elif args.comm == "serial":
75-
loop, client = AsyncModbusSerialClient( # pylint: disable=unpacking-non-sequence
75+
client = AsyncModbusSerialClient(
7676
port=args.port, # serial port
7777
framer=args.framer, # how to interpret the messages
7878
stopbits=1, # The number of stop bits to use
@@ -85,7 +85,7 @@ def setup_async_client(loop):
8585
loop=loop,
8686
)
8787
elif args.comm == "tls":
88-
loop, client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
88+
client = AsyncModbusTLSClient(
8989
host="localhost", # define tcp address where to connect to.
9090
port=args.port, # on which port
9191
sslctx=None, # ssl control

examples/contrib/asynchronous_asyncio_modbus_tls_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# import necessary libraries
1010
# -------------------------------------------------------------------------- #
1111
import ssl
12+
import asyncio
1213

1314
from pymodbus.client.asynchronous.tls import AsyncModbusTLSClient
1415

@@ -37,10 +38,11 @@ async def start_async_test(client):
3738
# ----------------------------------------------------------------------- #
3839
# pass SSLContext which is the context here to ModbusTcpClient()
3940
# ----------------------------------------------------------------------- #
40-
loop, new_client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
41+
new_client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
4142
"test.host.com",
4243
8020,
4344
sslctx=sslctx,
4445
)
46+
loop = asyncio.get_running_loop()
4547
loop.run_until_complete(start_async_test(new_client.protocol))
4648
loop.close()

pymodbus/client/asynchronous/async_io/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ModbusTlsFramer,
1919
)
2020

21+
2122
_logger = logging.getLogger(__name__)
2223

2324
DGRAM_TYPE = socket.SOCK_DGRAM
@@ -236,7 +237,7 @@ def __init__(self, protocol_class=None, framer=None, **kwargs):
236237
237238
:param protocol_class: Protocol used to talk to modbus device.
238239
"""
239-
# If there are no loop running a runtime error will be raised
240+
# get current loop, if there are no loop a RuntimeError will be raised
240241
self.loop = asyncio.get_running_loop()
241242
#: Protocol used to talk to modbus device.
242243
self.protocol_class = protocol_class or ModbusClientProtocol
@@ -347,17 +348,15 @@ def __init__(self, host=None, port=502, protocol_class=None, framer=None, **kwar
347348
:param port: Port to connect
348349
:param protocol_class: Protocol used to talk to modbus device.
349350
"""
350-
# If there are no loop running a runtime error will be raised
351+
# get current loop, if there are no loop a RuntimeError will be raised
351352
self.loop = asyncio.get_running_loop()
352353
#: Protocol used to talk to modbus device.
353354
self.protocol_class = protocol_class or ModbusClientProtocol
354355
#: Current protocol instance.
355356
self.protocol = None
356357
self.framer = framer if framer else ModbusSocketFramer
357-
358358
self.host = host
359359
self.port = port
360-
361360
self.connected = False
362361
self._proto_args = kwargs
363362

@@ -422,7 +421,7 @@ def __init__(self, protocol_class=None, framer=None, **kwargs):
422421
423422
:param protocol_class: Protocol used to talk to modbus device.
424423
"""
425-
# If there are no loop running a runtime error will be raised
424+
# get current loop, if there are no loop a RuntimeError will be raised
426425
self.loop = asyncio.get_running_loop()
427426
self.framer = framer if framer else ModbusTlsFramer
428427
self.server_hostname = None
@@ -493,7 +492,7 @@ def __init__(self, protocol_class=None, framer=None, **kwargs):
493492
494493
:param protocol_class: Protocol used to talk to modbus device.
495494
"""
496-
# If there are no loop running a runtime error will be raised
495+
# get current loop, if there are no loop a RuntimeError will be raised
497496
self.loop = asyncio.get_running_loop()
498497
#: Protocol used to talk to modbus device.
499498
self.protocol_class = protocol_class or ModbusUdpClientProtocol
@@ -612,7 +611,7 @@ def __init__(self, host=None, port=502, protocol_class=None, framer=None, **kwar
612611
:param port: Port to connect
613612
:param protocol_class: Protocol used to talk to modbus device.
614613
"""
615-
# If there are no loop running a runtime error will be raised
614+
# get current loop, if there are no loop a RuntimeError will be raised
616615
self.loop = asyncio.get_running_loop()
617616
#: Protocol used to talk to modbus device.
618617
self.protocol_class = protocol_class or ModbusUdpClientProtocol
@@ -711,7 +710,7 @@ def __init__(
711710
:param protocol_class: Protocol used to talk to modbus device.
712711
:param framer: Framer to use
713712
"""
714-
# If there are no loop running a runtime error will be raised
713+
# get current loop, if there are no loop a RuntimeError will be raised
715714
self.loop = asyncio.get_running_loop()
716715
#: Protocol used to talk to modbus device.
717716
self.protocol_class = protocol_class or ModbusRtuFramer

pymodbus/client/asynchronous/factory/serial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ def async_io_factory(port=None, framer=None, **kwargs):
3434
future = asyncio.run_coroutine_threadsafe(coro(), loop=loop)
3535
future.result()
3636

37-
return loop, client
37+
return client

pymodbus/client/asynchronous/factory/tcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):
3737
future = asyncio.run_coroutine_threadsafe(cor, loop=loop)
3838
client = future.result()
3939

40-
return loop, client
40+
return client

pymodbus/client/asynchronous/factory/tls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def async_io_factory(
4040
)
4141
client = loop.run_until_complete(asyncio.gather(cor))[0]
4242
elif loop is asyncio.get_event_loop():
43-
return loop, init_tls_client(
43+
return init_tls_client(
4444
proto_cls, host, port, sslctx, server_hostname, framer, **kwargs
4545
)
4646
else:
@@ -50,4 +50,4 @@ def async_io_factory(
5050
future = asyncio.run_coroutine_threadsafe(cor, loop=loop)
5151
client = future.result()
5252

53-
return loop, client
53+
return client

pymodbus/client/asynchronous/factory/udp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):
2828
cor = init_udp_client(proto_cls, host, port)
2929
client = loop.run_until_complete(asyncio.gather(cor))[0]
3030
elif loop is asyncio.get_event_loop():
31-
return loop, init_udp_client(proto_cls, host, port)
31+
return init_udp_client(proto_cls, host, port)
3232

3333
cor = init_udp_client(proto_cls, host, port)
3434
client = asyncio.run_coroutine_threadsafe(cor, loop=loop)
3535
client = client.result()
3636

37-
return loop, client
37+
return client

pymodbus/client/asynchronous/serial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""SERIAL communication."""
22
import logging
33

4+
from pymodbus.client.asynchronous.async_io import AsyncioModbusSerialClient as serialClient
45
from pymodbus.client.asynchronous.factory.serial import async_io_factory
56
from pymodbus.factory import ClientDecoder
67

78
_logger = logging.getLogger(__name__)
89

910

10-
class AsyncModbusSerialClient: # pylint: disable=too-few-public-methods
11+
class AsyncModbusSerialClient(serialClient):
1112
"""Actual Async Serial Client to be used.
1213
1314
To use do::

pymodbus/client/asynchronous/tcp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""TCP communication."""
22
import logging
33

4+
from pymodbus.client.asynchronous.async_io import ReconnectingAsyncioModbusTcpClient as tcpClient
45
from pymodbus.client.asynchronous.factory.tcp import async_io_factory
56
from pymodbus.constants import Defaults
67

78
_logger = logging.getLogger(__name__)
89

910

10-
class AsyncModbusTCPClient: # pylint: disable=too-few-public-methods
11+
class AsyncModbusTCPClient(tcpClient):
1112
"""Actual Async Serial Client to be used.
1213
1314
To use do::

0 commit comments

Comments
 (0)