|
14 | 14 | from pymodbus.constants import Endian |
15 | 15 | from pymodbus.exceptions import ConnectionException, ModbusIOException |
16 | 16 | from pymodbus.payload import BinaryPayloadDecoder |
17 | | -from pymodbus.pdu import ExceptionResponse, ModbusExceptions |
| 17 | +from pymodbus.pdu import ExceptionResponse |
18 | 18 |
|
19 | 19 | from .const import ( |
20 | 20 | BATTERY_REG_BASE, |
|
25 | 25 | ConfDefaultStr, |
26 | 26 | ConfName, |
27 | 27 | ModbusDefaults, |
| 28 | + ModbusExceptions, |
28 | 29 | RetrySettings, |
29 | 30 | SolarEdgeTimeouts, |
30 | 31 | SunSpecNotImpl, |
@@ -506,19 +507,21 @@ async def modbus_read_holding_registers(self, unit, address, rcount): |
506 | 507 | ) |
507 | 508 |
|
508 | 509 | if result.isError(): |
509 | | - _LOGGER.debug(f"Unit {unit}: {result}") |
510 | 510 |
|
511 | 511 | if type(result) is ModbusIOException: |
512 | 512 | raise ModbusIOError(result) |
513 | 513 |
|
514 | 514 | if type(result) is ExceptionResponse: |
515 | 515 | if result.exception_code == ModbusExceptions.IllegalAddress: |
| 516 | + _LOGGER.debug(f"Unit {unit} Read IllegalAddress: {result}") |
516 | 517 | raise ModbusIllegalAddress(result) |
517 | 518 |
|
518 | 519 | if result.exception_code == ModbusExceptions.IllegalFunction: |
| 520 | + _LOGGER.debug(f"Unit {unit} Read IllegalFunction: {result}") |
519 | 521 | raise ModbusIllegalFunction(result) |
520 | 522 |
|
521 | 523 | if result.exception_code == ModbusExceptions.IllegalValue: |
| 524 | + _LOGGER.debug(f"Unit {unit} Read IllegalValue: {result}") |
522 | 525 | raise ModbusIllegalValue(result) |
523 | 526 |
|
524 | 527 | raise ModbusReadError(result) |
@@ -592,19 +595,25 @@ async def write_registers(self, unit: int, address: int, payload) -> None: |
592 | 595 |
|
593 | 596 | if type(result) is ExceptionResponse: |
594 | 597 | if result.exception_code == ModbusExceptions.IllegalAddress: |
595 | | - _LOGGER.debug(f"Write IllegalAddress: {result}") |
| 598 | + _LOGGER.debug( |
| 599 | + f"Unit {self._wr_unit} Write IllegalAddress: {result}" |
| 600 | + ) |
596 | 601 | raise HomeAssistantError( |
597 | 602 | "Address not supported at device at ID {self._wr_unit}." |
598 | 603 | ) |
599 | 604 |
|
600 | 605 | if result.exception_code == ModbusExceptions.IllegalFunction: |
601 | | - _LOGGER.debug(f"Write IllegalFunction: {result}") |
| 606 | + _LOGGER.debug( |
| 607 | + f"Unit {self._wr_unit} Write IllegalFunction: {result}" |
| 608 | + ) |
602 | 609 | raise HomeAssistantError( |
603 | 610 | "Function not supported by device at ID {self._wr_unit}." |
604 | 611 | ) |
605 | 612 |
|
606 | 613 | if result.exception_code == ModbusExceptions.IllegalValue: |
607 | | - _LOGGER.debug(f"Write IllegalValue: {result}") |
| 614 | + _LOGGER.debug( |
| 615 | + f"Unit {self._wr_unit} Write IllegalValue: {result}" |
| 616 | + ) |
608 | 617 | raise HomeAssistantError( |
609 | 618 | "Value invalid for device at ID {self._wr_unit}." |
610 | 619 | ) |
|
0 commit comments