diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 8ebb0397579..ed3a9510f5a 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -64,7 +64,7 @@ MAX_CLIENT_SIZE: int = 1024 ** 2 * 16 STORAGE_KEY = DOMAIN STORAGE_VERSION = 1 - +SAVE_DELAY = 180 HTTP_SCHEMA = vol.All( cv.deprecated(CONF_BASE_URL), @@ -371,7 +371,7 @@ async def start_http_server_and_save_config( str(ip.network_address) for ip in conf[CONF_TRUSTED_PROXIES] ] - await store.async_save(conf) + store.async_delay_save(lambda: conf, SAVE_DELAY) current_request: ContextVar[web.Request | None] = ContextVar( diff --git a/tests/components/http/test_init.py b/tests/components/http/test_init.py index 993f0dba1fd..65f01118c71 100644 --- a/tests/components/http/test_init.py +++ b/tests/components/http/test_init.py @@ -1,4 +1,5 @@ """The tests for the Home Assistant HTTP component.""" +from datetime import timedelta from ipaddress import ip_network import logging from unittest.mock import Mock, patch @@ -7,8 +8,11 @@ import pytest import homeassistant.components.http as http from homeassistant.setup import async_setup_component +from homeassistant.util import dt as dt_util from homeassistant.util.ssl import server_context_intermediate, server_context_modern +from tests.common import async_fire_time_changed + @pytest.fixture def mock_stack(): @@ -189,6 +193,10 @@ async def test_storing_config(hass, aiohttp_client, aiohttp_unused_port): assert await async_setup_component(hass, http.DOMAIN, {http.DOMAIN: config}) await hass.async_start() + + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=200)) + await hass.async_block_till_done() + restored = await hass.components.http.async_get_last_config() restored["trusted_proxies"][0] = ip_network(restored["trusted_proxies"][0])