mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Improve reliability of homeassistant_alerts updates (#115974)
This commit is contained in:
parent
65b2c1519c
commit
37d329c286
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user