Detect if frontend is not loaded (#3124)

* Detect if frontend is not loaded

* update
This commit is contained in:
Joakim Sørensen 2021-09-18 14:30:01 +02:00 committed by GitHub
parent 271e4f0cc4
commit 74530baeb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View File

@ -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

View File

@ -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: