Skip to content

Commit f5621bc

Browse files
committed
remove kwargs client.
1 parent 978ad88 commit f5621bc

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

pymodbus/client/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ def __init__( # pylint: disable=too-many-arguments
6262
no_resend_on_retry: bool = False,
6363
comm_type: CommType | None = None,
6464
source_address: tuple[str, int] | None = None,
65+
comm_params: CommParams | None = None,
6566
**kwargs: Any,
6667
) -> None:
6768
"""Initialize a client instance."""
6869
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
70+
if comm_params:
71+
self.comm_params = comm_params
6972
self.ctx = ModbusClientProtocol(
7073
framer,
7174
CommParams(
@@ -276,10 +279,13 @@ def __init__( # pylint: disable=too-many-arguments
276279
no_resend_on_retry: bool = False,
277280
comm_type: CommType | None = None,
278281
source_address: tuple[str, int] | None = None,
282+
comm_params: CommParams | None = None,
279283
**kwargs: Any,
280284
) -> None:
281285
"""Initialize a client instance."""
282286
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
287+
if comm_params:
288+
self.comm_params = comm_params
283289
self.comm_params = CommParams(
284290
comm_type=comm_type,
285291
comm_name="comm",

pymodbus/client/serial.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pymodbus.exceptions import ConnectionException
1010
from pymodbus.framer import FramerType
1111
from pymodbus.logging import Log
12-
from pymodbus.transport import CommType
12+
from pymodbus.transport import CommParams, CommType
1313
from pymodbus.utilities import ModbusTransactionState
1414

1515

@@ -90,6 +90,7 @@ def __init__(
9090
bytesize=bytesize,
9191
parity=parity,
9292
stopbits=stopbits,
93+
comm_params = CommParams(),
9394
**kwargs,
9495
)
9596

@@ -167,6 +168,7 @@ def __init__(
167168
bytesize=bytesize,
168169
parity=parity,
169170
stopbits=stopbits,
171+
comm_params = CommParams(),
170172
**kwargs,
171173
)
172174
self.socket: serial.Serial | None = None

pymodbus/client/tcp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pymodbus.exceptions import ConnectionException
1111
from pymodbus.framer import FramerType
1212
from pymodbus.logging import Log
13-
from pymodbus.transport import CommType
13+
from pymodbus.transport import CommParams, CommType
1414

1515

1616
class AsyncModbusTcpClient(ModbusBaseClient):
@@ -72,6 +72,7 @@ def __init__(
7272
framer,
7373
host=host,
7474
port=port,
75+
comm_params = CommParams(),
7576
**kwargs,
7677
)
7778

@@ -138,6 +139,7 @@ def __init__(
138139
framer,
139140
host=host,
140141
port=port,
142+
comm_params = CommParams(),
141143
**kwargs,
142144
)
143145
self.params.source_address = source_address

pymodbus/client/udp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pymodbus.exceptions import ConnectionException
99
from pymodbus.framer import FramerType
1010
from pymodbus.logging import Log
11-
from pymodbus.transport import CommType
11+
from pymodbus.transport import CommParams, CommType
1212

1313

1414
DGRAM_TYPE = socket.SOCK_DGRAM
@@ -68,6 +68,7 @@ def __init__(
6868
comm_type=CommType.UDP,
6969
host=host,
7070
port=port,
71+
comm_params = CommParams(),
7172
**kwargs,
7273
)
7374
self.source_address = source_address
@@ -135,6 +136,7 @@ def __init__(
135136
port=port,
136137
host=host,
137138
comm_type=CommType.UDP,
139+
comm_params = CommParams(),
138140
**kwargs,
139141
)
140142
self.params.source_address = source_address

test/framers/test_old_framers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ModbusTlsFramer,
1515
)
1616
from pymodbus.pdu.bit_read_message import ReadCoilsRequest
17-
from pymodbus.transport import CommType
17+
from pymodbus.transport import CommParams, CommType
1818
from pymodbus.utilities import ModbusTransactionState
1919

2020

@@ -330,6 +330,7 @@ async def test_send_packet(self, rtu_framer):
330330
host="localhost",
331331
port=BASE_PORT + 1,
332332
CommType=CommType.TCP,
333+
comm_params=CommParams(),
333334
)
334335
client.state = ModbusTransactionState.TRANSACTION_COMPLETE
335336
client.silent_interval = 1

test/sub_client/test_client.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pymodbus.datastore.store import ModbusSequentialDataBlock
2323
from pymodbus.exceptions import ConnectionException, ModbusException, ModbusIOException
2424
from pymodbus.pdu import ModbusRequest
25-
from pymodbus.transport import CommType
25+
from pymodbus.transport import CommParams, CommType
2626

2727

2828
BASE_PORT = 6500
@@ -281,6 +281,7 @@ async def test_client_modbusbaseclient():
281281
host="localhost",
282282
port=BASE_PORT + 1,
283283
CommType=CommType.TCP,
284+
comm_params=CommParams(),
284285
)
285286
client.register(pdu_bit_read.ReadCoilsResponse)
286287
assert str(client)
@@ -316,6 +317,7 @@ async def test_client_base_async():
316317
host="localhost",
317318
port=BASE_PORT + 2,
318319
CommType=CommType.TCP,
320+
comm_params=CommParams(),
319321
) as client:
320322
str(client)
321323
p_connect.return_value = asyncio.Future()
@@ -327,7 +329,8 @@ async def test_client_base_async():
327329
@pytest.mark.skip()
328330
async def test_client_protocol_receiver():
329331
"""Test the client protocol data received."""
330-
base = ModbusBaseClient(FramerType.SOCKET)
332+
base = ModbusBaseClient(FramerType.SOCKET, comm_params=CommParams(),
333+
)
331334
transport = mock.MagicMock()
332335
base.ctx.connection_made(transport)
333336
assert base.transport == transport
@@ -349,7 +352,8 @@ async def test_client_protocol_receiver():
349352
@pytest.mark.skip()
350353
async def test_client_protocol_response():
351354
"""Test the udp client protocol builds responses."""
352-
base = ModbusBaseClient(FramerType.SOCKET)
355+
base = ModbusBaseClient(FramerType.SOCKET, comm_params=CommParams(),
356+
)
353357
response = base.build_response(0x00) # pylint: disable=protected-access
354358
excp = response.exception()
355359
assert isinstance(excp, ConnectionException)
@@ -363,7 +367,8 @@ async def test_client_protocol_response():
363367
async def test_client_protocol_handler():
364368
"""Test the client protocol handles responses."""
365369
base = ModbusBaseClient(
366-
FramerType.ASCII, host="localhost", port=+3, CommType=CommType.TCP
370+
FramerType.ASCII, host="localhost", port=+3, CommType=CommType.TCP, comm_params=CommParams(),
371+
367372
)
368373
transport = mock.MagicMock()
369374
base.ctx.connection_made(transport=transport)
@@ -411,7 +416,8 @@ def close(self):
411416

412417
async def test_client_protocol_execute():
413418
"""Test the client protocol execute method."""
414-
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1")
419+
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1", comm_params=CommParams(),
420+
)
415421
request = pdu_bit_read.ReadCoilsRequest(1, 1)
416422
transport = MockTransport(base, request)
417423
base.ctx.connection_made(transport=transport)
@@ -422,7 +428,8 @@ async def test_client_protocol_execute():
422428

423429
async def test_client_execute_broadcast():
424430
"""Test the client protocol execute method."""
425-
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1")
431+
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1", comm_params=CommParams(),
432+
)
426433
base.broadcast_enable = True
427434
request = pdu_bit_read.ReadCoilsRequest(1, 1)
428435
transport = MockTransport(base, request)
@@ -432,7 +439,8 @@ async def test_client_execute_broadcast():
432439

433440
async def test_client_protocol_retry():
434441
"""Test the client protocol execute method with retries."""
435-
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1", timeout=0.1)
442+
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1", timeout=0.1, comm_params=CommParams(),
443+
)
436444
request = pdu_bit_read.ReadCoilsRequest(1, 1)
437445
transport = MockTransport(base, request, retries=2)
438446
base.ctx.connection_made(transport=transport)
@@ -445,7 +453,8 @@ async def test_client_protocol_retry():
445453

446454
async def test_client_protocol_timeout():
447455
"""Test the client protocol execute method with timeout."""
448-
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1", timeout=0.1, retries=2)
456+
base = ModbusBaseClient(FramerType.SOCKET, host="127.0.0.1", timeout=0.1, retries=2, comm_params=CommParams(),
457+
)
449458
# Avoid creating do_reconnect() task
450459
base.ctx.connection_lost = mock.MagicMock()
451460
request = pdu_bit_read.ReadCoilsRequest(1, 1)
@@ -645,7 +654,8 @@ def test_client_mixin_convert_fail():
645654

646655
async def test_client_build_response():
647656
"""Test fail of build_response."""
648-
client = ModbusBaseClient(FramerType.RTU)
657+
client = ModbusBaseClient(FramerType.RTU, comm_params=CommParams(),
658+
)
649659
with pytest.raises(ConnectionException):
650660
await client.build_response(ModbusRequest(0, 0, 0, False))
651661

0 commit comments

Comments
 (0)