From d0e2c8b694b213aa70098f98a7a93977723e5d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 29 Nov 2021 17:03:49 +0100 Subject: [PATCH] Split homeassistant watchdog conditions (#3318) --- supervisor/misc/tasks.py | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/supervisor/misc/tasks.py b/supervisor/misc/tasks.py index f5623a5da..989902f0d 100644 --- a/supervisor/misc/tasks.py +++ b/supervisor/misc/tasks.py @@ -170,19 +170,20 @@ class Tasks(CoreSysAttributes): async def _watchdog_homeassistant_docker(self): """Check running state of Docker and start if they is close.""" - # if Home Assistant is active - if ( - not await self.sys_homeassistant.core.is_failed() - or not self.sys_homeassistant.watchdog - or self.sys_homeassistant.error_state - ): + if not self.sys_homeassistant.watchdog: + # Watchdog is not enabled for Home Assistant return - - # if Home Assistant is running - if ( - self.sys_homeassistant.core.in_progress - or await self.sys_homeassistant.core.is_running() - ): + if self.sys_homeassistant.error_state: + # Home Assistant is in an error state, this is handled by the rollback feature + return + if not await self.sys_homeassistant.core.is_failed(): + # The home assistant container is not in a failed state + return + if self.sys_homeassistant.core.in_progress: + # Home Assistant has a task in progress + return + if await self.sys_homeassistant.core.is_running(): + # Home Assistant is running return _LOGGER.warning("Watchdog found a problem with Home Assistant Docker!") @@ -203,24 +204,25 @@ class Tasks(CoreSysAttributes): Try 2 times to call API before we restart Home-Assistant. Maybe we had a delay in our system. """ - # Home-Assistant is active/running - if ( - not await self.sys_homeassistant.core.is_running() - or not self.sys_homeassistant.watchdog - or self.sys_homeassistant.error_state - ): + if not self.sys_homeassistant.watchdog: + # Watchdog is not enabled for Home Assistant + return + if self.sys_homeassistant.error_state: + # Home Assistant is in an error state, this is handled by the rollback feature + return + if not await self.sys_homeassistant.core.is_running(): + # The home assistant container is not running + return + if self.sys_homeassistant.core.in_progress: + # Home Assistant has a task in progress + return + if await self.sys_homeassistant.api.check_api_state(): + # Home Assistant is running properly return # Init cache data retry_scan = self._cache.get(HASS_WATCHDOG_API, 0) - # Home-Assistant API is up - if ( - self.sys_homeassistant.core.in_progress - or await self.sys_homeassistant.api.check_api_state() - ): - return - # Look like we run into a problem retry_scan += 1 if retry_scan == 1: