Skip to content

Commit c856458

Browse files
Qualify exceptions during init
1 parent d95f4c4 commit c856458

File tree

1 file changed

+30
-5
lines changed
  • custom_components/solaredge_modbus_multi

1 file changed

+30
-5
lines changed

custom_components/solaredge_modbus_multi/hub.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def _async_init_solaredge(self) -> None:
115115
await self._hass.async_add_executor_job(new_inverter.init_device)
116116
self.inverters.append(new_inverter)
117117

118-
except Exception as e:
118+
except DeviceInvalid as e:
119119
"""Inverters are required"""
120120
_LOGGER.error(f"Inverter device ID {inverter_unit_id}: {e}")
121121
raise HubInitFailed(f"Inverter device ID {inverter_unit_id} not found.")
@@ -139,7 +139,11 @@ async def _async_init_solaredge(self) -> None:
139139

140140
self.meters.append(new_meter_1)
141141
_LOGGER.debug(f"Found meter 1 on inverter ID {inverter_unit_id}")
142-
except Exception:
142+
143+
except ModbusReadError:
144+
raise HubInitFailed
145+
146+
except DeviceInvalid:
143147
pass
144148

145149
try:
@@ -160,7 +164,11 @@ async def _async_init_solaredge(self) -> None:
160164

161165
self.meters.append(new_meter_2)
162166
_LOGGER.debug(f"Found meter 2 on inverter ID {inverter_unit_id}")
163-
except Exception:
167+
168+
except ModbusReadError:
169+
raise HubInitFailed
170+
171+
except DeviceInvalid:
164172
pass
165173

166174
try:
@@ -181,7 +189,11 @@ async def _async_init_solaredge(self) -> None:
181189

182190
self.meters.append(new_meter_3)
183191
_LOGGER.debug(f"Found meter 3 on inverter ID {inverter_unit_id}")
184-
except Exception:
192+
193+
except ModbusReadError:
194+
raise HubInitFailed
195+
196+
except DeviceInvalid:
185197
pass
186198

187199
if self._detect_batteries:
@@ -203,6 +215,10 @@ async def _async_init_solaredge(self) -> None:
203215

204216
self.batteries.append(new_battery_1)
205217
_LOGGER.debug(f"Found battery 1 inverter {inverter_unit_id}")
218+
219+
except ModbusReadError:
220+
raise HubInitFailed
221+
206222
except DeviceInvalid:
207223
pass
208224

@@ -224,6 +240,10 @@ async def _async_init_solaredge(self) -> None:
224240

225241
self.batteries.append(new_battery_2)
226242
_LOGGER.debug(f"Found battery 2 inverter {inverter_unit_id}")
243+
244+
except ModbusReadError:
245+
raise HubInitFailed
246+
227247
except DeviceInvalid:
228248
pass
229249

@@ -556,7 +576,12 @@ def init_device(self) -> None:
556576
f"meter {self.meter_id}: {meter_info}"
557577
),
558578
)
559-
raise ModbusReadError(meter_info)
579+
580+
if meter_info.exception_code == ModbusExceptions.IllegalAddress:
581+
raise DeviceInvalid(meter_info)
582+
583+
else:
584+
raise ModbusReadError(meter_info)
560585

561586
decoder = BinaryPayloadDecoder.fromRegisters(
562587
meter_info.registers, byteorder=Endian.Big

0 commit comments

Comments
 (0)