From 00387bf87031857e8ffc249c11e812b0e6af14b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 2 Jun 2020 17:02:09 -0500 Subject: [PATCH] Make the frontend available sooner (Part 2 of 2) (#36264) * Part 1 of 2 (no breaking changes in part 1). When integrations configured via the UI block startup or fail to start, the webserver can remain offline which make it is impossible to recover without manually changing files in .storage since the UI is not available. This change is the foundation that part 2 will build on and enable a listener to start the webserver when the frontend is finished loading. Frontend Changes (home-assistant/frontend#6068) * Part 1 of 2 (no breaking changes in part 1). When integrations configured via the UI block startup or fail to start, the webserver can remain offline which make it is impossible to recover without manually changing files in .storage since the UI is not available. This change is the foundation that part 2 will build on and enable a listener to start the webserver when the frontend is finished loading. Frontend Changes (home-assistant/frontend#6068) * Part 2 of 2 (breaking changes in part 2). When integrations configured via the UI block startup or fail to start, the webserver can remain offline which make it is impossible to recover without manually changing files in .storage since the UI is not available. This change is the foundation that part 2 will build on and enable a listener to start the webserver when the frontend is finished loading. * bump timeout to 1800s, adjust comment * bump timeout to 1800s, adjust comment * bump timeout to 4h * bump timeout to 4h * remove timeout failsafe * remove timeout failsafe * and the test * and the test * find the test that needs mocking * find the test that needs mocking * Revert "find the test that needs mocking" This reverts commit 064e7787a8e9bc65df965530726fa1c41f8bcd36. * Revert "find the test that needs mocking" This reverts commit 064e7787a8e9bc65df965530726fa1c41f8bcd36. * fix the one that was missed due to the conflict --- homeassistant/components/http/__init__.py | 12 ++++++++++++ tests/test_bootstrap.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index e06ceb087c2..b387cea350e 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -19,6 +19,7 @@ from homeassistant.core import Event, HomeAssistant from homeassistant.helpers import storage import homeassistant.helpers.config_validation as cv from homeassistant.loader import bind_hass +from homeassistant.setup import ATTR_COMPONENT, EVENT_COMPONENT_LOADED import homeassistant.util as hass_util from homeassistant.util import ssl as ssl_util @@ -232,6 +233,17 @@ async def async_setup(hass, config): await start_http_server_and_save_config(hass, dict(conf), server) + async def async_wait_frontend_load(event: Event) -> None: + """Wait for the frontend to load.""" + + if event.data[ATTR_COMPONENT] != "frontend": + return + + await start_server(event) + + startup_listeners.append( + hass.bus.async_listen(EVENT_COMPONENT_LOADED, async_wait_frontend_load) + ) startup_listeners.append( hass.bus.async_listen(EVENT_HOMEASSISTANT_START, start_server) ) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 3ea42d4545b..e14afdca28a 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -316,6 +316,8 @@ async def test_setup_hass_takes_longer_than_log_slow_startup( ), patch.object(bootstrap, "LOG_SLOW_STARTUP_INTERVAL", 0.3), patch( "homeassistant.components.frontend.async_setup", side_effect=_async_setup_that_blocks_startup, + ), patch( + "homeassistant.components.http.start_http_server_and_save_config" ): await bootstrap.async_setup_hass( config_dir=get_test_config_dir(),