Skip to content

Commit 1f99dc3

Browse files
committed
Improve cleanup in case of error in startup
1 parent 14f6f98 commit 1f99dc3

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

custom_components/victron_mqtt/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,21 @@ async def async_setup_entry(
9696
hub = Hub(hass, entry)
9797
entry.runtime_data = hub
9898

99+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
100+
# All platforms should be set up before starting the hub
101+
try:
102+
await hub.start()
103+
except Exception as exc:
104+
_LOGGER.error("hub.start() failed for entry %s: %s", entry.entry_id, exc, exc_info=True)
105+
# Clean up partial setup to avoid double setup issues
106+
await async_unload_entry(hass, entry)
107+
raise
108+
99109
# Register the update listener
100110
entry.async_on_unload(entry.add_update_listener(_update_listener))
101111

102-
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
103-
# All platforms should be set up before starting the hub
104-
await hub.start()
105-
106112
# Register services
107113
await async_setup_services(hass, entry)
108-
109114
_LOGGER.info("async_setup_entry completed for entry: %s", entry.entry_id)
110115
return True
111116

0 commit comments

Comments
 (0)