From 32fe97c2ad76380cd5a0fa128b4616f011224d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Tue, 12 Dec 2023 23:24:11 +0100 Subject: [PATCH] Add: Reload integration on connection failure --- custom_components/lights_app/__init__.py | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/custom_components/lights_app/__init__.py b/custom_components/lights_app/__init__.py index 3ad3188..e6eba86 100644 --- a/custom_components/lights_app/__init__.py +++ b/custom_components/lights_app/__init__.py @@ -119,21 +119,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): async def async_update_data(): LOGGER.debug("async_update_data - entry") - await sendCommand( - hass.data[DOMAIN][entry.entry_id], - hass.data[DOMAIN][entry.entry_id]["connection"]["client"], - hass.data[DOMAIN][entry.entry_id]["connection"]["service"], - getLightStateCommand(), - ) - await sendCommand( - hass.data[DOMAIN][entry.entry_id], - hass.data[DOMAIN][entry.entry_id]["connection"]["client"], - hass.data[DOMAIN][entry.entry_id]["connection"]["service"], - getModeStateCommand(), - ) + if not hass.data[DOMAIN][entry.entry_id]["connection"]["connected"]: - LOGGER.debug("Not connected, reconnecting...") - await setupConnection(hass, address, entry) + LOGGER.debug("Not connected, reloading...") + await hass.config_entries.async_reload(entry.entry_id) + else: + await sendCommand( + hass.data[DOMAIN][entry.entry_id], + hass.data[DOMAIN][entry.entry_id]["connection"]["client"], + hass.data[DOMAIN][entry.entry_id]["connection"]["service"], + getLightStateCommand(), + ) + await sendCommand( + hass.data[DOMAIN][entry.entry_id], + hass.data[DOMAIN][entry.entry_id]["connection"]["client"], + hass.data[DOMAIN][entry.entry_id]["connection"]["service"], + getModeStateCommand(), + ) lightsAppCoordinator = DataUpdateCoordinator( hass,