Skip to content

Commit ea5d70d

Browse files
authored
Simplify code flow for broadcast requests (#2720)
1 parent b9731ec commit ea5d70d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pymodbus/server/requesthandler.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,18 @@ def handle_later(self):
8686

8787
async def handle_request(self):
8888
"""Handle request."""
89-
broadcast = False
9089
if not self.last_pdu:
9190
return
9291
try:
9392
if self.server.broadcast_enable and not self.last_pdu.dev_id:
94-
broadcast = True
9593
# if broadcasting then execute on all device contexts,
9694
# note response will be ignored
9795
for dev_id in self.server.context.device_id():
98-
response = await self.last_pdu.update_datastore(self.server.context[dev_id])
99-
else:
100-
context = self.server.context[self.last_pdu.dev_id]
101-
response = await self.last_pdu.update_datastore(context)
96+
await self.last_pdu.update_datastore(self.server.context[dev_id])
97+
return
98+
99+
context = self.server.context[self.last_pdu.dev_id]
100+
response = await self.last_pdu.update_datastore(context)
102101

103102
except NoSuchIdException:
104103
Log.error("requested device id does not exist: {}", self.last_pdu.dev_id)
@@ -112,11 +111,9 @@ async def handle_request(self):
112111
traceback.format_exc(),
113112
)
114113
response = ExceptionResponse(self.last_pdu.function_code, ExceptionResponse.DEVICE_FAILURE)
115-
# no response when broadcasting
116-
if not broadcast:
117-
response.transaction_id = self.last_pdu.transaction_id
118-
response.dev_id = self.last_pdu.dev_id
119-
self.server_send(response, self.last_addr)
114+
response.transaction_id = self.last_pdu.transaction_id
115+
response.dev_id = self.last_pdu.dev_id
116+
self.server_send(response, self.last_addr)
120117

121118
def server_send(self, pdu, addr):
122119
"""Send message."""

0 commit comments

Comments
 (0)