Improve generic event typing [EventComponentLoaded] (#114739)

This commit is contained in:
Marc Mueller 2024-04-06 14:18:03 +02:00 committed by GitHub
parent fa7da34298
commit e0f5559c8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View file

@ -7,7 +7,7 @@ from homeassistant.const import EVENT_COMPONENT_LOADED
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import ATTR_COMPONENT
from homeassistant.setup import EventComponentLoaded
from . import (
area_registry,
@ -56,6 +56,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
if panel.async_setup(hass):
name = panel.__name__.split(".")[-1]
key = f"{DOMAIN}.{name}"
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: key})
hass.bus.async_fire(
EVENT_COMPONENT_LOADED, EventComponentLoaded(component=key)
)
return True

View file

@ -23,6 +23,7 @@ from homeassistant.helpers.issue_registry import (
from homeassistant.helpers.start import async_at_start
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.setup import EventComponentLoaded
COMPONENT_LOADED_COOLDOWN = 30
DOMAIN = "homeassistant_alerts"
@ -99,7 +100,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
)
@callback
def _component_loaded(_: Event) -> None:
def _component_loaded(_: Event[EventComponentLoaded]) -> None:
refresh_debouncer.async_schedule_call()
await coordinator.async_refresh()

View file

@ -455,7 +455,7 @@ async def _async_setup_component( # noqa: C901
if domain in hass.data[DATA_SETUP]:
hass.data[DATA_SETUP].pop(domain)
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: domain})
hass.bus.async_fire(EVENT_COMPONENT_LOADED, EventComponentLoaded(component=domain))
return True