|
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | 4 | import struct |
| 5 | +from collections.abc import Sequence |
5 | 6 | from typing import cast |
6 | 7 |
|
7 | 8 | from pymodbus.datastore import ModbusDeviceContext |
@@ -37,8 +38,6 @@ async def update_datastore(self, context: ModbusDeviceContext) -> ModbusPDU: |
37 | 38 | values = await context.async_getValues( |
38 | 39 | self.function_code, self.address, self.count |
39 | 40 | ) |
40 | | - if isinstance(values, int): |
41 | | - return ExceptionResponse(self.function_code, values) |
42 | 41 | response_class = (ReadHoldingRegistersResponse if self.function_code == 3 else ReadInputRegistersResponse) |
43 | 42 | return response_class(registers=cast(list[int], values), dev_id=self.dev_id, transaction_id=self.transaction_id) |
44 | 43 |
|
@@ -147,8 +146,6 @@ async def update_datastore(self, context: ModbusDeviceContext) -> ModbusPDU: |
147 | 146 | registers = await context.async_getValues( |
148 | 147 | self.function_code, self.read_address, self.read_count |
149 | 148 | ) |
150 | | - if isinstance(registers, int): |
151 | | - return ExceptionResponse(self.function_code, registers) |
152 | 149 | return ReadWriteMultipleRegistersResponse(registers=cast(list[int], registers), dev_id=self.dev_id, transaction_id=self.transaction_id) |
153 | 150 |
|
154 | 151 | def get_response_pdu_size(self) -> int: |
@@ -194,8 +191,6 @@ async def update_datastore(self, context: ModbusDeviceContext) -> ModbusPDU: |
194 | 191 | if rc: |
195 | 192 | return ExceptionResponse(self.function_code, rc) |
196 | 193 | values = await context.async_getValues(self.function_code, self.address, 1) |
197 | | - if isinstance(values, int): |
198 | | - return ExceptionResponse(self.function_code, values) |
199 | 194 | return WriteSingleRegisterResponse(address=self.address, registers=cast(list[int], values)) |
200 | 195 |
|
201 | 196 | def get_response_pdu_size(self) -> int: |
@@ -288,9 +283,7 @@ async def update_datastore(self, context: ModbusDeviceContext) -> ModbusPDU: |
288 | 283 | if not 0x0000 <= self.or_mask <= 0xFFFF: |
289 | 284 | return ExceptionResponse(self.function_code, ExceptionResponse.ILLEGAL_VALUE) |
290 | 285 | values = await context.async_getValues(self.function_code, self.address, 1) |
291 | | - if isinstance(values, int): |
292 | | - return ExceptionResponse(self.function_code, values) |
293 | | - values = (values[0] & self.and_mask) | (self.or_mask & ~self.and_mask) |
| 286 | + values = (cast(Sequence[int | bool], values)[0] & self.and_mask) | (self.or_mask & ~self.and_mask) |
294 | 287 | rc = await context.async_setValues( |
295 | 288 | self.function_code, self.address, cast(list[int], [values]) |
296 | 289 | ) |
|
0 commit comments