mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 02:56:31 +00:00
Handle new API / Frontend early boot (#1770)
* Handle new API / Frontend early boot * Adjust part 2 * fix hanging landingpage * Fix catch error * Fix watchdog
This commit is contained in:
parent
ec43448163
commit
af412c3105
@ -75,6 +75,8 @@ class APIProxy(CoreSysAttributes):
|
|||||||
async def stream(self, request: web.Request):
|
async def stream(self, request: web.Request):
|
||||||
"""Proxy HomeAssistant EventStream Requests."""
|
"""Proxy HomeAssistant EventStream Requests."""
|
||||||
self._check_access(request)
|
self._check_access(request)
|
||||||
|
if not await self.sys_homeassistant.check_api_state():
|
||||||
|
raise HTTPBadGateway()
|
||||||
|
|
||||||
_LOGGER.info("Home Assistant EventStream start")
|
_LOGGER.info("Home Assistant EventStream start")
|
||||||
async with self._api_client(request, "stream", timeout=None) as client:
|
async with self._api_client(request, "stream", timeout=None) as client:
|
||||||
@ -94,6 +96,8 @@ class APIProxy(CoreSysAttributes):
|
|||||||
async def api(self, request: web.Request):
|
async def api(self, request: web.Request):
|
||||||
"""Proxy Home Assistant API Requests."""
|
"""Proxy Home Assistant API Requests."""
|
||||||
self._check_access(request)
|
self._check_access(request)
|
||||||
|
if not await self.sys_homeassistant.check_api_state():
|
||||||
|
raise HTTPBadGateway()
|
||||||
|
|
||||||
# Normal request
|
# Normal request
|
||||||
path = request.match_info.get("path", "")
|
path = request.match_info.get("path", "")
|
||||||
@ -153,6 +157,8 @@ class APIProxy(CoreSysAttributes):
|
|||||||
|
|
||||||
async def websocket(self, request: web.Request):
|
async def websocket(self, request: web.Request):
|
||||||
"""Initialize a WebSocket API connection."""
|
"""Initialize a WebSocket API connection."""
|
||||||
|
if not await self.sys_homeassistant.check_api_state():
|
||||||
|
raise HTTPBadGateway()
|
||||||
_LOGGER.info("Home Assistant WebSocket API request initialize")
|
_LOGGER.info("Home Assistant WebSocket API request initialize")
|
||||||
|
|
||||||
# init server
|
# init server
|
||||||
|
@ -374,6 +374,10 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
await self.instance.run()
|
await self.instance.run()
|
||||||
except DockerAPIError:
|
except DockerAPIError:
|
||||||
raise HomeAssistantError() from None
|
raise HomeAssistantError() from None
|
||||||
|
|
||||||
|
# Don't block for landingpage
|
||||||
|
if self.version == "landingpage":
|
||||||
|
return
|
||||||
await self._block_till_run()
|
await self._block_till_run()
|
||||||
|
|
||||||
@process_lock
|
@process_lock
|
||||||
@ -559,12 +563,21 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
|
|
||||||
async def check_api_state(self) -> bool:
|
async def check_api_state(self) -> bool:
|
||||||
"""Return True if Home Assistant up and running."""
|
"""Return True if Home Assistant up and running."""
|
||||||
|
# Check if port is up
|
||||||
|
if not await self.sys_run_in_executor(
|
||||||
|
check_port, self.ip_address, self.api_port
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Check if API is up
|
||||||
with suppress(HomeAssistantAPIError):
|
with suppress(HomeAssistantAPIError):
|
||||||
async with self.make_request("get", "api/") as resp:
|
async with self.make_request("get", "api/config") as resp:
|
||||||
if resp.status in (200, 201):
|
if resp.status in (200, 201):
|
||||||
|
data = await resp.json()
|
||||||
|
if data.get("state", "RUNNING") == "RUNNING":
|
||||||
return True
|
return True
|
||||||
status = resp.status
|
else:
|
||||||
_LOGGER.warning("Home Assistant API config mismatch: %s", status)
|
_LOGGER.debug("Home Assistant API return: %d", resp.status)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -589,9 +602,7 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# 2: Check if API response
|
# 2: Check if API response
|
||||||
if await self.sys_run_in_executor(
|
if await self.check_api_state():
|
||||||
check_port, self.ip_address, self.api_port
|
|
||||||
):
|
|
||||||
_LOGGER.info("Detect a running Home Assistant instance")
|
_LOGGER.info("Detect a running Home Assistant instance")
|
||||||
self._error_state = False
|
self._error_state = False
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user