Skip to content

Commit

Permalink
Update error strings a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCodeForCats committed Jul 8, 2023
1 parent 8ec729c commit b6f1442
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions custom_components/solaredge_modbus_multi/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,30 +559,39 @@ async def write_registers(self, unit: int, address: int, payload) -> None:

except ConnectionException as e:
_LOGGER.error(f"Write command failed: {e}")
raise HomeAssistantError("Connection to device failed.")
raise HomeAssistantError(
f"Connection to inverter ID {self._wr_unit} failed."
)

if result.isError():
if type(result) is ModbusIOException:
_LOGGER.error("Write command failed: No response from device.")
_LOGGER.error(
f"Write failed: No response from inverter ID {self._wr_unit}."
)

if not self.keep_modbus_open:
await self.disconnect()

raise HomeAssistantError("No response from device.")
raise HomeAssistantError(
"No response from inverter ID {self._wr_unit}."
)

elif type(result) is ExceptionResponse:
if result.exception_code == ModbusExceptions.IllegalAddress:
_LOGGER.error(
(
"Write command failed: "
f"Illegal address {hex(self._wr_address)}"
"Write failed: "
f"Illegal address {hex(self._wr_address)} "
f"at unit ID {self._wr_unit}"
),
)

if not self.keep_modbus_open:
await self.disconnect()

raise HomeAssistantError("Command not supported by device.")
raise HomeAssistantError(
"Command not supported by device at ID {self._wr_unit}."
)

else:
raise ModbusWriteError(result)
Expand Down

0 comments on commit b6f1442

Please sign in to comment.