Skip to content

Commit 459913b

Browse files
committed
Request/Response: change execute to be async method
contains only async/await edits, no functional changes otherwise
1 parent 24c200c commit 459913b

18 files changed

+110
-110
lines changed

pymodbus/bit_read_message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(self, address=None, count=None, slave=0, **kwargs):
155155
"""
156156
ReadBitsRequestBase.__init__(self, address, count, slave, **kwargs)
157157

158-
def execute(self, context):
158+
async def execute(self, context):
159159
"""Run a read coils request against a datastore.
160160
161161
Before running the request, we make sure that the request is in
@@ -223,7 +223,7 @@ def __init__(self, address=None, count=None, slave=0, **kwargs):
223223
"""
224224
ReadBitsRequestBase.__init__(self, address, count, slave, **kwargs)
225225

226-
def execute(self, context):
226+
async def execute(self, context):
227227
"""Run a read discrete input request against a datastore.
228228
229229
Before running the request, we make sure that the request is in

pymodbus/bit_write_message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def decode(self, data):
7979
self.address, value = struct.unpack(">HH", data)
8080
self.value = value == ModbusStatus.ON
8181

82-
def execute(self, context):
82+
async def execute(self, context):
8383
"""Run a write coil request against a datastore.
8484
8585
:param context: The datastore to request from
@@ -212,7 +212,7 @@ def decode(self, data):
212212
values = unpack_bitstring(data[5:])
213213
self.values = values[:count]
214214

215-
def execute(self, context):
215+
async def execute(self, context):
216216
"""Run a write coils request against a datastore.
217217
218218
:param context: The datastore to request from

pymodbus/diag_message.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def __init__(self, data=0x0000, **kwargs):
199199
DiagnosticStatusRequest.__init__(self, **kwargs)
200200
self.message = data
201201

202-
def execute(self, *args):
202+
async def execute(self, *args):
203203
"""Raise if not implemented."""
204204
raise NotImplementedException("Diagnostic Message Has No Execute Method")
205205

@@ -245,7 +245,7 @@ def __init__(self, message=b"\x00\x00", slave=None, **kwargs):
245245
raise ModbusException(f"message({type(message)}) must be bytes")
246246
self.message = message
247247

248-
def execute(self, *_args):
248+
async def execute(self, *_args):
249249
"""Execute the loopback request (builds the response).
250250
251251
:returns: The populated loopback response message
@@ -301,7 +301,7 @@ def __init__(self, toggle=False, slave=None, **kwargs):
301301
else:
302302
self.message = [ModbusStatus.OFF]
303303

304-
def execute(self, *_args):
304+
async def execute(self, *_args):
305305
"""Clear event log and restart.
306306
307307
:returns: The initialized response message
@@ -343,7 +343,7 @@ class ReturnDiagnosticRegisterRequest(DiagnosticStatusSimpleRequest):
343343

344344
sub_function_code = 0x0002
345345

346-
def execute(self, *args):
346+
async def execute(self, *args):
347347
"""Execute the diagnostic request on the given device.
348348
349349
:returns: The initialized response message
@@ -377,7 +377,7 @@ class ChangeAsciiInputDelimiterRequest(DiagnosticStatusSimpleRequest):
377377

378378
sub_function_code = 0x0003
379379

380-
def execute(self, *args):
380+
async def execute(self, *args):
381381
"""Execute the diagnostic request on the given device.
382382
383383
:returns: The initialized response message
@@ -412,7 +412,7 @@ class ForceListenOnlyModeRequest(DiagnosticStatusSimpleRequest):
412412

413413
sub_function_code = 0x0004
414414

415-
def execute(self, *args):
415+
async def execute(self, *args):
416416
"""Execute the diagnostic request on the given device.
417417
418418
:returns: The initialized response message
@@ -451,7 +451,7 @@ class ClearCountersRequest(DiagnosticStatusSimpleRequest):
451451

452452
sub_function_code = 0x000A
453453

454-
def execute(self, *args):
454+
async def execute(self, *args):
455455
"""Execute the diagnostic request on the given device.
456456
457457
:returns: The initialized response message
@@ -482,7 +482,7 @@ class ReturnBusMessageCountRequest(DiagnosticStatusSimpleRequest):
482482

483483
sub_function_code = 0x000B
484484

485-
def execute(self, *args):
485+
async def execute(self, *args):
486486
"""Execute the diagnostic request on the given device.
487487
488488
:returns: The initialized response message
@@ -515,7 +515,7 @@ class ReturnBusCommunicationErrorCountRequest(DiagnosticStatusSimpleRequest):
515515

516516
sub_function_code = 0x000C
517517

518-
def execute(self, *args):
518+
async def execute(self, *args):
519519
"""Execute the diagnostic request on the given device.
520520
521521
:returns: The initialized response message
@@ -548,7 +548,7 @@ class ReturnBusExceptionErrorCountRequest(DiagnosticStatusSimpleRequest):
548548

549549
sub_function_code = 0x000D
550550

551-
def execute(self, *args):
551+
async def execute(self, *args):
552552
"""Execute the diagnostic request on the given device.
553553
554554
:returns: The initialized response message
@@ -581,7 +581,7 @@ class ReturnSlaveMessageCountRequest(DiagnosticStatusSimpleRequest):
581581

582582
sub_function_code = 0x000E
583583

584-
def execute(self, *args):
584+
async def execute(self, *args):
585585
"""Execute the diagnostic request on the given device.
586586
587587
:returns: The initialized response message
@@ -614,7 +614,7 @@ class ReturnSlaveNoResponseCountRequest(DiagnosticStatusSimpleRequest):
614614

615615
sub_function_code = 0x000F
616616

617-
def execute(self, *args):
617+
async def execute(self, *args):
618618
"""Execute the diagnostic request on the given device.
619619
620620
:returns: The initialized response message
@@ -648,7 +648,7 @@ class ReturnSlaveNAKCountRequest(DiagnosticStatusSimpleRequest):
648648

649649
sub_function_code = 0x0010
650650

651-
def execute(self, *args):
651+
async def execute(self, *args):
652652
"""Execute the diagnostic request on the given device.
653653
654654
:returns: The initialized response message
@@ -682,7 +682,7 @@ class ReturnSlaveBusyCountRequest(DiagnosticStatusSimpleRequest):
682682

683683
sub_function_code = 0x0011
684684

685-
def execute(self, *args):
685+
async def execute(self, *args):
686686
"""Execute the diagnostic request on the given device.
687687
688688
:returns: The initialized response message
@@ -717,7 +717,7 @@ class ReturnSlaveBusCharacterOverrunCountRequest(DiagnosticStatusSimpleRequest):
717717

718718
sub_function_code = 0x0012
719719

720-
def execute(self, *args):
720+
async def execute(self, *args):
721721
"""Execute the diagnostic request on the given device.
722722
723723
:returns: The initialized response message
@@ -750,7 +750,7 @@ class ReturnIopOverrunCountRequest(DiagnosticStatusSimpleRequest):
750750

751751
sub_function_code = 0x0013
752752

753-
def execute(self, *args):
753+
async def execute(self, *args):
754754
"""Execute the diagnostic request on the given device.
755755
756756
:returns: The initialized response message
@@ -783,7 +783,7 @@ class ClearOverrunCountRequest(DiagnosticStatusSimpleRequest):
783783

784784
sub_function_code = 0x0014
785785

786-
def execute(self, *args):
786+
async def execute(self, *args):
787787
"""Execute the diagnostic request on the given device.
788788
789789
:returns: The initialized response message
@@ -834,7 +834,7 @@ def get_response_pdu_size(self):
834834
data = 0
835835
return 1 + 2 + 2 + 2 + data
836836

837-
def execute(self, *args):
837+
async def execute(self, *args):
838838
"""Execute the diagnostic request on the given device.
839839
840840
:returns: The initialized response message

pymodbus/mei_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def decode(self, data):
8484
params = struct.unpack(">BBB", data)
8585
self.sub_function_code, self.read_code, self.object_id = params
8686

87-
def execute(self, _context):
87+
async def execute(self, _context):
8888
"""Run a read exception status request against the store.
8989
9090
:returns: The populated response

pymodbus/other_message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def decode(self, data):
5454
:param data: The incoming data
5555
"""
5656

57-
def execute(self, _context=None):
57+
async def execute(self, _context=None):
5858
"""Run a read exception status request against the store.
5959
6060
:returns: The populated response
@@ -159,7 +159,7 @@ def decode(self, data):
159159
:param data: The incoming data
160160
"""
161161

162-
def execute(self, _context=None):
162+
async def execute(self, _context=None):
163163
"""Run a read exception status request against the store.
164164
165165
:returns: The populated response
@@ -270,7 +270,7 @@ def decode(self, data):
270270
:param data: The incoming data
271271
"""
272272

273-
def execute(self, _context=None):
273+
async def execute(self, _context=None):
274274
"""Run a read exception status request against the store.
275275
276276
:returns: The populated response
@@ -395,7 +395,7 @@ def decode(self, data):
395395
:param data: The incoming data
396396
"""
397397

398-
def execute(self, context=None):
398+
async def execute(self, context=None):
399399
"""Run a report slave id request against the store.
400400
401401
:returns: The populated response

pymodbus/pdu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def decode(self, _data):
252252
def encode(self):
253253
"""Decode so this failure will run correctly."""
254254

255-
def execute(self, _context):
255+
async def execute(self, _context):
256256
"""Build an illegal function request error response.
257257
258258
:returns: The error response packet

pymodbus/register_read_message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(self, address=None, count=None, slave=0, **kwargs):
139139
"""
140140
super().__init__(address, count, slave, **kwargs)
141141

142-
def execute(self, context):
142+
async def execute(self, context):
143143
"""Run a read holding request against a datastore.
144144
145145
:param context: The datastore to request from
@@ -200,7 +200,7 @@ def __init__(self, address=None, count=None, slave=0, **kwargs):
200200
"""
201201
super().__init__(address, count, slave, **kwargs)
202202

203-
def execute(self, context):
203+
async def execute(self, context):
204204
"""Run a read input request against a datastore.
205205
206206
:param context: The datastore to request from
@@ -310,7 +310,7 @@ def decode(self, data):
310310
register = struct.unpack(">H", data[i : i + 2])[0]
311311
self.write_registers.append(register)
312312

313-
def execute(self, context):
313+
async def execute(self, context):
314314
"""Run a write single register request against a datastore.
315315
316316
:param context: The datastore to request from

pymodbus/register_write_message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def decode(self, data):
5757
"""
5858
self.address, self.value = struct.unpack(">HH", data)
5959

60-
def execute(self, context):
60+
async def execute(self, context):
6161
"""Run a write single register request against a datastore.
6262
6363
:param context: The datastore to request from
@@ -200,7 +200,7 @@ def decode(self, data):
200200
for idx in range(5, (self.count * 2) + 5, 2):
201201
self.values.append(struct.unpack(">H", data[idx : idx + 2])[0])
202202

203-
def execute(self, context):
203+
async def execute(self, context):
204204
"""Run a write single register request against a datastore.
205205
206206
:param context: The datastore to request from
@@ -321,7 +321,7 @@ def decode(self, data):
321321
"""
322322
self.address, self.and_mask, self.or_mask = struct.unpack(">HHH", data)
323323

324-
def execute(self, context):
324+
async def execute(self, context):
325325
"""Run a mask write register request against the store.
326326
327327
:param context: The datastore to request from

test/sub_client/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def __init__(self, base, req, retries=0):
392392
async def delayed_resp(self):
393393
"""Send a response to a received packet."""
394394
await asyncio.sleep(0.05)
395-
resp = self.req.execute(self.ctx)
395+
resp = await self.req.execute(self.ctx)
396396
pkt = self.base.ctx.framer.buildPacket(resp)
397397
self.base.ctx.data_received(pkt)
398398

test/sub_function_codes/test_bit_read_messages.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,29 @@ def test_bit_read_base_requests(self):
8585
for request, expected in iter(messages.items()):
8686
assert request.encode() == expected
8787

88-
def test_bit_read_message_execute_value_errors(self):
88+
async def test_bit_read_message_execute_value_errors(self):
8989
"""Test bit read request encoding."""
9090
context = MockContext()
9191
requests = [
9292
ReadCoilsRequest(1, 0x800),
9393
ReadDiscreteInputsRequest(1, 0x800),
9494
]
9595
for request in requests:
96-
result = request.execute(context)
96+
result = await request.execute(context)
9797
assert ModbusExceptions.IllegalValue == result.exception_code
9898

99-
def test_bit_read_message_execute_address_errors(self):
99+
async def test_bit_read_message_execute_address_errors(self):
100100
"""Test bit read request encoding."""
101101
context = MockContext()
102102
requests = [
103103
ReadCoilsRequest(1, 5),
104104
ReadDiscreteInputsRequest(1, 5),
105105
]
106106
for request in requests:
107-
result = request.execute(context)
107+
result = await request.execute(context)
108108
assert ModbusExceptions.IllegalAddress == result.exception_code
109109

110-
def test_bit_read_message_execute_success(self):
110+
async def test_bit_read_message_execute_success(self):
111111
"""Test bit read request encoding."""
112112
context = MockContext()
113113
context.validate = lambda a, b, c: True
@@ -116,7 +116,7 @@ def test_bit_read_message_execute_success(self):
116116
ReadDiscreteInputsRequest(1, 5),
117117
]
118118
for request in requests:
119-
result = request.execute(context)
119+
result = await request.execute(context)
120120
assert result.bits == [True] * 5
121121

122122
def test_bit_read_message_get_response_pdu(self):

0 commit comments

Comments
 (0)