Use EventType for system events (#115190)

pull/115230/head
Marc Mueller 2024-04-08 20:25:34 +02:00 committed by GitHub
parent a52a80f806
commit 6116f11e6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 10 deletions

View File

@ -49,6 +49,7 @@ from homeassistant.helpers import config_validation as cv, template
from homeassistant.helpers.json import json_dumps, json_fragment
from homeassistant.helpers.service import async_get_all_descriptions
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.event_type import EventType
from homeassistant.util.json import json_loads
_LOGGER = logging.getLogger(__name__)
@ -134,7 +135,7 @@ class APIEventStream(HomeAssistantView):
stop_obj = object()
to_write: asyncio.Queue[object | str] = asyncio.Queue()
restrict: list[str] | None = None
restrict: list[EventType[Any] | str] | None = None
if restrict_str := request.query.get("restrict"):
restrict = [*restrict_str.split(","), EVENT_HOMEASSISTANT_STOP]

View File

@ -12,6 +12,7 @@ from homeassistant.components.logbook import (
)
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers.typing import NoEventData
from homeassistant.util.event_type import EventType
from . import DOMAIN
@ -25,12 +26,14 @@ EVENT_TO_NAME: dict[EventType[Any] | str, str] = {
@callback
def async_describe_events(
hass: HomeAssistant,
async_describe_event: Callable[[str, str, Callable[[Event], dict[str, str]]], None],
async_describe_event: Callable[
[str, EventType[NoEventData] | str, Callable[[Event], dict[str, str]]], None
],
) -> None:
"""Describe logbook events."""
@callback
def async_describe_hass_event(event: Event) -> dict[str, str]:
def async_describe_hass_event(event: Event[NoEventData]) -> dict[str, str]:
"""Describe homeassistant logbook event."""
return {
LOGBOOK_ENTRY_NAME: "Home Assistant",

View File

@ -18,6 +18,7 @@ from .util.signal_type import SignalType
if TYPE_CHECKING:
from .core import EventStateChangedData
from .helpers.typing import NoEventData
APPLICATION_NAME: Final = "HomeAssistant"
MAJOR_VERSION: Final = 2024
@ -302,11 +303,13 @@ CONF_ZONE: Final = "zone"
EVENT_CALL_SERVICE: Final = "call_service"
EVENT_COMPONENT_LOADED: Final = "component_loaded"
EVENT_CORE_CONFIG_UPDATE: Final = "core_config_updated"
EVENT_HOMEASSISTANT_CLOSE: Final = "homeassistant_close"
EVENT_HOMEASSISTANT_START: Final = "homeassistant_start"
EVENT_HOMEASSISTANT_STARTED: Final = "homeassistant_started"
EVENT_HOMEASSISTANT_STOP: Final = "homeassistant_stop"
EVENT_HOMEASSISTANT_FINAL_WRITE: Final = "homeassistant_final_write"
EVENT_HOMEASSISTANT_CLOSE: EventType[NoEventData] = EventType("homeassistant_close")
EVENT_HOMEASSISTANT_START: EventType[NoEventData] = EventType("homeassistant_start")
EVENT_HOMEASSISTANT_STARTED: EventType[NoEventData] = EventType("homeassistant_started")
EVENT_HOMEASSISTANT_STOP: EventType[NoEventData] = EventType("homeassistant_stop")
EVENT_HOMEASSISTANT_FINAL_WRITE: EventType[NoEventData] = EventType(
"homeassistant_final_write"
)
EVENT_LOGBOOK_ENTRY: Final = "logbook_entry"
EVENT_LOGGING_CHANGED: Final = "logging_changed"
EVENT_SERVICE_REGISTERED: Final = "service_registered"

View File

@ -14,13 +14,16 @@ from homeassistant.core import (
HomeAssistant,
callback,
)
from homeassistant.util.event_type import EventType
from .typing import NoEventData
@callback
def _async_at_core_state(
hass: HomeAssistant,
at_start_cb: Callable[[HomeAssistant], Coroutine[Any, Any, None] | None],
event_type: str,
event_type: EventType[NoEventData],
check_state: Callable[[HomeAssistant], bool],
) -> CALLBACK_TYPE:
"""Execute a job at_start_cb when Home Assistant has the wanted state.

View File

@ -3,7 +3,7 @@
from collections.abc import Mapping
from enum import Enum
from functools import partial
from typing import Any
from typing import Any, Never
import homeassistant.core
@ -20,6 +20,7 @@ DiscoveryInfoType = dict[str, Any]
ServiceDataType = dict[str, Any]
StateType = str | int | float | None
TemplateVarsType = Mapping[str, Any] | None
NoEventData = Mapping[str, Never]
# Custom type for recorder Queries
QueryType = Any