From 860ae4efb9c59b36e30cca9368272cbc1f48d078 Mon Sep 17 00:00:00 2001 From: Wim <11030068+wimb0@users.noreply.github.com> Date: Mon, 24 Feb 2025 09:20:28 +0100 Subject: [PATCH] Fix crash/errors when inverter is offline. --- custom_components/saj_modbus/hub.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/saj_modbus/hub.py b/custom_components/saj_modbus/hub.py index c06372e..ad961bf 100644 --- a/custom_components/saj_modbus/hub.py +++ b/custom_components/saj_modbus/hub.py @@ -89,13 +89,14 @@ async def _async_update_data(self) -> dict: self.read_modbus_realtime_data ) - self.close() - except ConnectionException: + except (BrokenPipeError, ConnectionResetError, ConnectionException) as conerr: _LOGGER.error("Reading realtime data failed! Inverter is unreachable.") + _LOGGER.debug("Connection error: %s", conerr) realtime_data["mpvmode"] = 0 realtime_data["mpvstatus"] = DEVICE_STATUSSES[0] realtime_data["power"] = 0 - + + self.close() return {**self.inverter_data, **realtime_data} def read_modbus_inverter_data(self) -> dict: