1 """The Home Assistant alerts integration."""
3 from __future__
import annotations
21 from .const
import COMPONENT_LOADED_COOLDOWN, DOMAIN, REQUEST_TIMEOUT
22 from .coordinator
import AlertUpdateCoordinator
24 _LOGGER = logging.getLogger(__name__)
26 CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
29 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
31 last_alerts: dict[str, str |
None] = {}
33 async
def async_update_alerts() -> None:
36 active_alerts: dict[str, str |
None] = {}
38 for issue_id, alert
in coordinator.data.items():
40 if issue_id
in last_alerts
and alert.date_updated == last_alerts[issue_id]:
41 active_alerts[issue_id] = alert.date_updated
47 f
"https://alerts.home-assistant.io/alerts/{alert.alert_id}.json",
48 timeout=REQUEST_TIMEOUT,
51 _LOGGER.warning(
"Error fetching %s: timeout", alert.filename)
54 alert_content = await response.json()
60 issue_domain=alert.integration,
61 severity=IssueSeverity.WARNING,
62 translation_key=
"alert",
63 translation_placeholders={
64 "title": alert_content[
"title"],
65 "description": alert_content[
"content"],
68 active_alerts[issue_id] = alert.date_updated
70 inactive_alerts = last_alerts.keys() - active_alerts.keys()
71 for issue_id
in inactive_alerts:
74 last_alerts = active_alerts
77 def async_schedule_update_alerts() -> None:
78 if not coordinator.last_update_success:
81 hass.async_create_background_task(
82 async_update_alerts(),
"homeassistant_alerts update", eager_start=
True
86 coordinator.async_add_listener(async_schedule_update_alerts)
88 async
def initial_refresh(hass: HomeAssistant) ->
None:
92 cooldown=COMPONENT_LOADED_COOLDOWN,
94 function=coordinator.async_refresh,
99 def _component_loaded(_: Event[EventComponentLoaded]) ->
None:
100 refresh_debouncer.async_schedule_call()
102 await coordinator.async_refresh()
103 hass.bus.async_listen(EVENT_COMPONENT_LOADED, _component_loaded)
web.Response get(self, web.Request request, str config_key)
bool async_setup(HomeAssistant hass, ConfigType config)
None async_create_issue(HomeAssistant hass, str entry_id)
None async_delete_issue(HomeAssistant hass, str entry_id)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)
CALLBACK_TYPE async_at_started(HomeAssistant hass, Callable[[HomeAssistant], Coroutine[Any, Any, None]|None] at_start_cb)