File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
custom_components/solaredge_modbus_multi Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 88from pymodbus .client .sync import ModbusTcpClient
99from pymodbus .compat import iteritems
1010from pymodbus .constants import Endian
11+ from pymodbus .exceptions import ConnectionException
1112from pymodbus .payload import BinaryPayloadDecoder
1213from pymodbus .pdu import ModbusExceptions
1314
@@ -276,7 +277,12 @@ async def async_refresh_modbus_data(self, _now: Optional[int] = None) -> bool:
276277 await self .connect ()
277278
278279 if not self .initalized :
279- await self ._async_init_solaredge ()
280+ try :
281+ await self ._async_init_solaredge ()
282+
283+ except ConnectionException as e :
284+ self .disconnect ()
285+ raise HubInitFailed (f"Setup failed: { e } " )
280286
281287 if not self .is_socket_open ():
282288 self .online = False
@@ -295,16 +301,21 @@ async def async_refresh_modbus_data(self, _now: Optional[int] = None) -> bool:
295301 await self ._hass .async_add_executor_job (battery .read_modbus_data )
296302
297303 except ModbusReadError as e :
298- self .disconnect ()
299304 self .online = False
305+ self .disconnect ()
300306 raise DataUpdateFailed (f"Update failed: { e } " )
301307
302308 except DeviceInvalid as e :
309+ self .online = False
303310 if not self .keep_modbus_open :
304311 self .disconnect ()
305- self .online = False
306312 raise DataUpdateFailed (f"Invalid device: { e } " )
307313
314+ except ConnectionException as e :
315+ self .online = False
316+ self .disconnect ()
317+ raise DataUpdateFailed (f"Connection failed: { e } " )
318+
308319 if not self .keep_modbus_open :
309320 self .disconnect ()
310321
You can’t perform that action at this time.
0 commit comments