From 767283b6781a26eb38dd5fede692591a45a24f6c Mon Sep 17 00:00:00 2001 From: wrfz Date: Mon, 4 Mar 2024 18:25:51 +0000 Subject: [PATCH] Fix adding Solax integration without HA restart --- custom_components/solax_modbus/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/solax_modbus/__init__.py b/custom_components/solax_modbus/__init__.py index 93bcf627..5d5225ba 100644 --- a/custom_components/solax_modbus/__init__.py +++ b/custom_components/solax_modbus/__init__.py @@ -143,9 +143,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Register the hub.""" hass.data[DOMAIN][name] = { "hub": hub, } - # Tests on some systems have shown that establishing the Modbus connection + # Tests on some systems have shown that establishing the Modbus connection # can occasionally lead to errors if Home Assistant is not fully loaded. - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, hub.async_init()) + if hass.is_running: + await hub.async_init() + else: + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, hub.async_init()) entry.async_on_unload(entry.add_update_listener(config_entry_update_listener)) return True