Use EventType for system events (#115190)
This commit is contained in:
parent
a52a80f806
commit
6116f11e6c
5 changed files with 21 additions and 10 deletions
|
@ -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.json import json_dumps, json_fragment
|
||||||
from homeassistant.helpers.service import async_get_all_descriptions
|
from homeassistant.helpers.service import async_get_all_descriptions
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
from homeassistant.util.event_type import EventType
|
||||||
from homeassistant.util.json import json_loads
|
from homeassistant.util.json import json_loads
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -134,7 +135,7 @@ class APIEventStream(HomeAssistantView):
|
||||||
stop_obj = object()
|
stop_obj = object()
|
||||||
to_write: asyncio.Queue[object | str] = asyncio.Queue()
|
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"):
|
if restrict_str := request.query.get("restrict"):
|
||||||
restrict = [*restrict_str.split(","), EVENT_HOMEASSISTANT_STOP]
|
restrict = [*restrict_str.split(","), EVENT_HOMEASSISTANT_STOP]
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.logbook import (
|
||||||
)
|
)
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.typing import NoEventData
|
||||||
from homeassistant.util.event_type import EventType
|
from homeassistant.util.event_type import EventType
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import DOMAIN
|
||||||
|
@ -25,12 +26,14 @@ EVENT_TO_NAME: dict[EventType[Any] | str, str] = {
|
||||||
@callback
|
@callback
|
||||||
def async_describe_events(
|
def async_describe_events(
|
||||||
hass: HomeAssistant,
|
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:
|
) -> None:
|
||||||
"""Describe logbook events."""
|
"""Describe logbook events."""
|
||||||
|
|
||||||
@callback
|
@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."""
|
"""Describe homeassistant logbook event."""
|
||||||
return {
|
return {
|
||||||
LOGBOOK_ENTRY_NAME: "Home Assistant",
|
LOGBOOK_ENTRY_NAME: "Home Assistant",
|
||||||
|
|
|
@ -18,6 +18,7 @@ from .util.signal_type import SignalType
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .core import EventStateChangedData
|
from .core import EventStateChangedData
|
||||||
|
from .helpers.typing import NoEventData
|
||||||
|
|
||||||
APPLICATION_NAME: Final = "HomeAssistant"
|
APPLICATION_NAME: Final = "HomeAssistant"
|
||||||
MAJOR_VERSION: Final = 2024
|
MAJOR_VERSION: Final = 2024
|
||||||
|
@ -302,11 +303,13 @@ CONF_ZONE: Final = "zone"
|
||||||
EVENT_CALL_SERVICE: Final = "call_service"
|
EVENT_CALL_SERVICE: Final = "call_service"
|
||||||
EVENT_COMPONENT_LOADED: Final = "component_loaded"
|
EVENT_COMPONENT_LOADED: Final = "component_loaded"
|
||||||
EVENT_CORE_CONFIG_UPDATE: Final = "core_config_updated"
|
EVENT_CORE_CONFIG_UPDATE: Final = "core_config_updated"
|
||||||
EVENT_HOMEASSISTANT_CLOSE: Final = "homeassistant_close"
|
EVENT_HOMEASSISTANT_CLOSE: EventType[NoEventData] = EventType("homeassistant_close")
|
||||||
EVENT_HOMEASSISTANT_START: Final = "homeassistant_start"
|
EVENT_HOMEASSISTANT_START: EventType[NoEventData] = EventType("homeassistant_start")
|
||||||
EVENT_HOMEASSISTANT_STARTED: Final = "homeassistant_started"
|
EVENT_HOMEASSISTANT_STARTED: EventType[NoEventData] = EventType("homeassistant_started")
|
||||||
EVENT_HOMEASSISTANT_STOP: Final = "homeassistant_stop"
|
EVENT_HOMEASSISTANT_STOP: EventType[NoEventData] = EventType("homeassistant_stop")
|
||||||
EVENT_HOMEASSISTANT_FINAL_WRITE: Final = "homeassistant_final_write"
|
EVENT_HOMEASSISTANT_FINAL_WRITE: EventType[NoEventData] = EventType(
|
||||||
|
"homeassistant_final_write"
|
||||||
|
)
|
||||||
EVENT_LOGBOOK_ENTRY: Final = "logbook_entry"
|
EVENT_LOGBOOK_ENTRY: Final = "logbook_entry"
|
||||||
EVENT_LOGGING_CHANGED: Final = "logging_changed"
|
EVENT_LOGGING_CHANGED: Final = "logging_changed"
|
||||||
EVENT_SERVICE_REGISTERED: Final = "service_registered"
|
EVENT_SERVICE_REGISTERED: Final = "service_registered"
|
||||||
|
|
|
@ -14,13 +14,16 @@ from homeassistant.core import (
|
||||||
HomeAssistant,
|
HomeAssistant,
|
||||||
callback,
|
callback,
|
||||||
)
|
)
|
||||||
|
from homeassistant.util.event_type import EventType
|
||||||
|
|
||||||
|
from .typing import NoEventData
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_at_core_state(
|
def _async_at_core_state(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
at_start_cb: Callable[[HomeAssistant], Coroutine[Any, Any, None] | None],
|
at_start_cb: Callable[[HomeAssistant], Coroutine[Any, Any, None] | None],
|
||||||
event_type: str,
|
event_type: EventType[NoEventData],
|
||||||
check_state: Callable[[HomeAssistant], bool],
|
check_state: Callable[[HomeAssistant], bool],
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Execute a job at_start_cb when Home Assistant has the wanted state.
|
"""Execute a job at_start_cb when Home Assistant has the wanted state.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any
|
from typing import Any, Never
|
||||||
|
|
||||||
import homeassistant.core
|
import homeassistant.core
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ DiscoveryInfoType = dict[str, Any]
|
||||||
ServiceDataType = dict[str, Any]
|
ServiceDataType = dict[str, Any]
|
||||||
StateType = str | int | float | None
|
StateType = str | int | float | None
|
||||||
TemplateVarsType = Mapping[str, Any] | None
|
TemplateVarsType = Mapping[str, Any] | None
|
||||||
|
NoEventData = Mapping[str, Never]
|
||||||
|
|
||||||
# Custom type for recorder Queries
|
# Custom type for recorder Queries
|
||||||
QueryType = Any
|
QueryType = Any
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue