From 74530baeb778fa234eeb9f7b4dc19f964b2e82ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 18 Sep 2021 14:30:01 +0200 Subject: [PATCH] Detect if frontend is not loaded (#3124) * Detect if frontend is not loaded * update --- supervisor/homeassistant/api.py | 21 +++++++++++++-------- supervisor/homeassistant/core.py | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/supervisor/homeassistant/api.py b/supervisor/homeassistant/api.py index 70fa0a28a..9ae6e2f60 100644 --- a/supervisor/homeassistant/api.py +++ b/supervisor/homeassistant/api.py @@ -105,6 +105,15 @@ class HomeAssistantAPI(CoreSysAttributes): raise HomeAssistantAPIError() + async def get_config(self) -> Dict[str, Any]: + """Return Home Assistant config.""" + async with self.make_request("get", "api/config") as resp: + if resp.status in (200, 201): + return await resp.json() + else: + _LOGGER.debug("Home Assistant API return: %d", resp.status) + raise HomeAssistantAPIError() + async def check_api_state(self) -> bool: """Return True if Home Assistant up and running.""" # Skip check on landingpage @@ -124,12 +133,8 @@ class HomeAssistantAPI(CoreSysAttributes): # Check if API is up with suppress(HomeAssistantAPIError): - async with self.make_request("get", "api/config") as resp: - if resp.status in (200, 201): - data = await resp.json() - if data.get("state", "RUNNING") == "RUNNING": - return True - else: - _LOGGER.debug("Home Assistant API return: %d", resp.status) - + data = await self.get_config() + # Older versions of home assistant does not expose the state + if data and data.get("state", "RUNNING") == "RUNNING": + return True return False diff --git a/supervisor/homeassistant/core.py b/supervisor/homeassistant/core.py index 8ea5c17cc..57132a89f 100644 --- a/supervisor/homeassistant/core.py +++ b/supervisor/homeassistant/core.py @@ -214,7 +214,20 @@ class HomeAssistantCore(CoreSysAttributes): # Update Home Assistant with suppress(HomeAssistantError): await _update(version) - return + + if not self.error_state and rollback: + try: + data = await self.sys_homeassistant.api.get_config() + except HomeAssistantError: + # The API stoped responding between the up checks an now + self._error_state = True + + # Verify that the frontend is loaded + if data and "frontend" not in data.get("components", []): + _LOGGER.error("API responds but frontend is not loaded") + self._error_state = True + else: + return # Update going wrong, revert it if self.error_state and rollback: