From 37d329c2867629db59a12cc3ed63675315aa288f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 22 Apr 2024 16:51:19 +0200 Subject: [PATCH] Improve reliability of homeassistant_alerts updates (#115974) --- .../components/homeassistant_alerts/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/homeassistant_alerts/__init__.py b/homeassistant/components/homeassistant_alerts/__init__.py index 7dcd9f8db97..ef5e330699a 100644 --- a/homeassistant/components/homeassistant_alerts/__init__.py +++ b/homeassistant/components/homeassistant_alerts/__init__.py @@ -20,7 +20,7 @@ from homeassistant.helpers.issue_registry import ( async_create_issue, async_delete_issue, ) -from homeassistant.helpers.start import async_at_start +from homeassistant.helpers.start import async_at_started from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.setup import EventComponentLoaded @@ -30,6 +30,8 @@ DOMAIN = "homeassistant_alerts" UPDATE_INTERVAL = timedelta(hours=3) _LOGGER = logging.getLogger(__name__) +REQUEST_TIMEOUT = aiohttp.ClientTimeout(total=30) + CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) @@ -52,7 +54,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: try: response = await async_get_clientsession(hass).get( f"https://alerts.home-assistant.io/alerts/{alert.alert_id}.json", - timeout=aiohttp.ClientTimeout(total=30), + timeout=REQUEST_TIMEOUT, ) except TimeoutError: _LOGGER.warning("Error fetching %s: timeout", alert.filename) @@ -106,7 +108,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await coordinator.async_refresh() hass.bus.async_listen(EVENT_COMPONENT_LOADED, _component_loaded) - async_at_start(hass, initial_refresh) + async_at_started(hass, initial_refresh) return True @@ -146,7 +148,7 @@ class AlertUpdateCoordinator(DataUpdateCoordinator[dict[str, IntegrationAlert]]) async def _async_update_data(self) -> dict[str, IntegrationAlert]: response = await async_get_clientsession(self.hass).get( "https://alerts.home-assistant.io/alerts.json", - timeout=aiohttp.ClientTimeout(total=10), + timeout=REQUEST_TIMEOUT, ) alerts = await response.json()