diff --git a/custom_components/gardena_smart_system/__init__.py b/custom_components/gardena_smart_system/__init__.py index 1c8f810..6b2b289 100644 --- a/custom_components/gardena_smart_system/__init__.py +++ b/custom_components/gardena_smart_system/__init__.py @@ -44,18 +44,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: client_id=entry.data[CONF_CLIENT_ID], client_secret=entry.data[CONF_CLIENT_SECRET], ) - - try: - await gardena_system.start() - except AccessDeniedError as ex: - _LOGGER.error('Got Access Denied Error when setting up Gardena Smart System: %s', ex) - return False - except InvalidClientError as ex: - _LOGGER.error('Got Invalid Client Error when setting up Gardena Smart System: %s', ex) - return False - except MissingTokenError as ex: - _LOGGER.error('Got Missing Token Error when setting up Gardena Smart System: %s', ex) - return False + while True: + try: + await gardena_system.start() + break # If connection is successful, return True + except ConnectionError: + await asyncio.sleep(60) # Wait for 60 seconds before trying to reconnect + except AccessDeniedError as ex: + _LOGGER.error('Got Access Denied Error when setting up Gardena Smart System: %s', ex) + return False + except InvalidClientError as ex: + _LOGGER.error('Got Invalid Client Error when setting up Gardena Smart System: %s', ex) + return False + except MissingTokenError as ex: + _LOGGER.error('Got Missing Token Error when setting up Gardena Smart System: %s', ex) + return False hass.data[DOMAIN][GARDENA_SYSTEM] = gardena_system