From db446ea2b426fcfe31b33d9e5a384d86c9a41290 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 31 Oct 2023 13:31:56 +0100 Subject: [PATCH] Don't check if Core is running to trigger rollback Currently we check for Core API access and that the state is running. If this is not fulfilled within 5 minutes, we rollback to the previous version. It can take quite a while until Home Assistant Core is in state running. In fact, after going through bootstrap, it can theoretically take indefinitely (as in there is no timeout from Core side). So to trigger rollback, rather than check the state to be running, just check if the API is accessible in this case. This prevents spurious rollbacks. --- supervisor/homeassistant/api.py | 6 ++++-- supervisor/homeassistant/core.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/supervisor/homeassistant/api.py b/supervisor/homeassistant/api.py index 1885ff56ce0..27c66951b25 100644 --- a/supervisor/homeassistant/api.py +++ b/supervisor/homeassistant/api.py @@ -130,7 +130,7 @@ async def get_core_state(self) -> dict[str, Any]: """Return Home Assistant core state.""" return await self._get_json("api/core/state") - async def check_api_state(self) -> bool: + async def check_api_state(self, check_running: bool = True) -> bool: """Return True if Home Assistant up and running.""" # Skip check on landingpage if ( @@ -157,7 +157,9 @@ async def check_api_state(self) -> bool: else: data = await self.get_config() # Older versions of home assistant does not expose the state - if data and data.get("state", "RUNNING") == "RUNNING": + if data: + if check_running: + return data.get("state", "RUNNING") == "RUNNING" return True return False diff --git a/supervisor/homeassistant/core.py b/supervisor/homeassistant/core.py index 6a5374e5f18..918b8c7b361 100644 --- a/supervisor/homeassistant/core.py +++ b/supervisor/homeassistant/core.py @@ -450,7 +450,7 @@ async def _block_till_run(self, version: AwesomeVersion) -> None: break # 2: Check if API response - if await self.sys_homeassistant.api.check_api_state(): + if await self.sys_homeassistant.api.check_api_state(check_running=False): _LOGGER.info("Detect a running Home Assistant instance") self._error_state = False return