Replace EventType with Event [missing] (#112753)

This commit is contained in:
Marc Mueller 2024-03-08 21:56:42 +01:00 committed by GitHub
parent c7eabd95e6
commit cef20506dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 28 additions and 35 deletions

View File

@ -5,9 +5,8 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME
from homeassistant.core import HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers.device_registry import async_get from homeassistant.helpers.device_registry import async_get
from homeassistant.helpers.typing import EventType
from .const import BTHOME_BLE_EVENT, DOMAIN, BTHomeBleEvent from .const import BTHOME_BLE_EVENT, DOMAIN, BTHomeBleEvent
@ -16,14 +15,14 @@ from .const import BTHOME_BLE_EVENT, DOMAIN, BTHomeBleEvent
def async_describe_events( def async_describe_events(
hass: HomeAssistant, hass: HomeAssistant,
async_describe_event: Callable[ async_describe_event: Callable[
[str, str, Callable[[EventType[BTHomeBleEvent]], dict[str, str]]], None [str, str, Callable[[Event[BTHomeBleEvent]], dict[str, str]]], None
], ],
) -> None: ) -> None:
"""Describe logbook events.""" """Describe logbook events."""
dr = async_get(hass) dr = async_get(hass)
@callback @callback
def async_describe_bthome_event(event: EventType[BTHomeBleEvent]) -> dict[str, str]: def async_describe_bthome_event(event: Event[BTHomeBleEvent]) -> dict[str, str]:
"""Describe bthome logbook event.""" """Describe bthome logbook event."""
data = event.data data = event.data
device = dr.async_get(data["device_id"]) device = dr.async_get(data["device_id"])

View File

@ -43,7 +43,6 @@ from homeassistant.helpers.event import (
EventStateChangedData, EventStateChangedData,
async_track_state_added_domain, async_track_state_added_domain,
) )
from homeassistant.helpers.typing import EventType
from homeassistant.util.json import JsonObjectType, json_loads_object from homeassistant.util.json import JsonObjectType, json_loads_object
from .agent import AbstractConversationAgent, ConversationInput, ConversationResult from .agent import AbstractConversationAgent, ConversationInput, ConversationResult
@ -696,14 +695,14 @@ class DefaultAgent(AbstractConversationAgent):
@core.callback @core.callback
def _async_handle_area_registry_changed( def _async_handle_area_registry_changed(
self, event: EventType[ar.EventAreaRegistryUpdatedData] self, event: core.Event[ar.EventAreaRegistryUpdatedData]
) -> None: ) -> None:
"""Clear area area cache when the area registry has changed.""" """Clear area area cache when the area registry has changed."""
self._slot_lists = None self._slot_lists = None
@core.callback @core.callback
def _async_handle_entity_registry_changed( def _async_handle_entity_registry_changed(
self, event: EventType[er.EventEntityRegistryUpdatedData] self, event: core.Event[er.EventEntityRegistryUpdatedData]
) -> None: ) -> None:
"""Clear names list cache when an entity registry entry has changed.""" """Clear names list cache when an entity registry entry has changed."""
if event.data["action"] != "update" or not any( if event.data["action"] != "update" or not any(

View File

@ -31,7 +31,7 @@ from homeassistant.helpers.event import (
async_track_time_interval, async_track_time_interval,
) )
from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.helpers.typing import UNDEFINED, ConfigType, EventType, UndefinedType from homeassistant.helpers.typing import UNDEFINED, ConfigType, UndefinedType
from .const import DOMAIN, IMAGE_TIMEOUT # noqa: F401 from .const import DOMAIN, IMAGE_TIMEOUT # noqa: F401
@ -342,7 +342,7 @@ async def async_get_still_stream(
event = asyncio.Event() event = asyncio.Event()
async def image_state_update(_event: EventType[EventStateChangedData]) -> None: async def image_state_update(_event: Event[EventStateChangedData]) -> None:
"""Write image to stream.""" """Write image to stream."""
event.set() event.set()

View File

@ -60,7 +60,6 @@ from homeassistant.helpers.typing import (
UNDEFINED, UNDEFINED,
ConfigType, ConfigType,
DiscoveryInfoType, DiscoveryInfoType,
EventType,
UndefinedType, UndefinedType,
) )
from homeassistant.util.json import json_loads from homeassistant.util.json import json_loads
@ -769,7 +768,7 @@ async def async_remove_discovery_payload(
async def async_clear_discovery_topic_if_entity_removed( async def async_clear_discovery_topic_if_entity_removed(
hass: HomeAssistant, hass: HomeAssistant,
discovery_data: DiscoveryInfoType, discovery_data: DiscoveryInfoType,
event: EventType[er.EventEntityRegistryUpdatedData], event: Event[er.EventEntityRegistryUpdatedData],
) -> None: ) -> None:
"""Clear the discovery topic if the entity is removed.""" """Clear the discovery topic if the entity is removed."""
if event.data["action"] == "remove": if event.data["action"] == "remove":

View File

@ -15,10 +15,10 @@ from homeassistant.const import (
CONF_ZONE, CONF_ZONE,
UnitOfLength, UnitOfLength,
) )
from homeassistant.core import HomeAssistant, State, callback from homeassistant.core import Event, HomeAssistant, State, callback
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, EventType from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util.location import distance from homeassistant.util.location import distance
from homeassistant.util.unit_conversion import DistanceConverter from homeassistant.util.unit_conversion import DistanceConverter
@ -107,7 +107,7 @@ class ProximityDataUpdateCoordinator(DataUpdateCoordinator[ProximityData]):
await self.async_refresh() await self.async_refresh()
async def async_check_tracked_entity_change( async def async_check_tracked_entity_change(
self, event: EventType[er.EventEntityRegistryUpdatedData] self, event: Event[er.EventEntityRegistryUpdatedData]
) -> None: ) -> None:
"""Fetch and process tracked entity change event.""" """Fetch and process tracked entity change event."""
data = event.data data = event.data

View File

@ -9,10 +9,9 @@ import voluptuous as vol
from homeassistant.components.homeassistant import exposed_entities from homeassistant.components.homeassistant import exposed_entities
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ENTITY_ID from homeassistant.const import CONF_ENTITY_ID
from homeassistant.core import HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.event import async_track_entity_registry_updated_event from homeassistant.helpers.event import async_track_entity_registry_updated_event
from homeassistant.helpers.typing import EventType
from .const import CONF_INVERT, CONF_TARGET_DOMAIN from .const import CONF_INVERT, CONF_TARGET_DOMAIN
from .light import LightSwitch from .light import LightSwitch
@ -58,7 +57,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return False return False
async def async_registry_updated( async def async_registry_updated(
event: EventType[er.EventEntityRegistryUpdatedData], event: Event[er.EventEntityRegistryUpdatedData],
) -> None: ) -> None:
"""Handle entity registry update.""" """Handle entity registry update."""
data = event.data data = event.data

View File

@ -68,7 +68,7 @@ from .event import (
async_track_device_registry_updated_event, async_track_device_registry_updated_event,
async_track_entity_registry_updated_event, async_track_entity_registry_updated_event,
) )
from .typing import UNDEFINED, EventType, StateType, UndefinedType from .typing import UNDEFINED, StateType, UndefinedType
if TYPE_CHECKING: if TYPE_CHECKING:
from functools import cached_property from functools import cached_property
@ -1455,7 +1455,7 @@ class Entity(
@callback @callback
def _async_registry_updated( def _async_registry_updated(
self, event: EventType[er.EventEntityRegistryUpdatedData] self, event: Event[er.EventEntityRegistryUpdatedData]
) -> None: ) -> None:
"""Handle entity registry update.""" """Handle entity registry update."""
action = event.data["action"] action = event.data["action"]
@ -1467,7 +1467,7 @@ class Entity(
) )
async def _async_process_registry_update_or_remove( async def _async_process_registry_update_or_remove(
self, event: EventType[er.EventEntityRegistryUpdatedData] self, event: Event[er.EventEntityRegistryUpdatedData]
) -> None: ) -> None:
"""Handle entity registry update or remove.""" """Handle entity registry update or remove."""
data = event.data data = event.data

View File

@ -7,7 +7,7 @@ import dataclasses
from dataclasses import dataclass from dataclasses import dataclass
from typing import TYPE_CHECKING, Literal, TypedDict, cast from typing import TYPE_CHECKING, Literal, TypedDict, cast
from homeassistant.core import HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.util import slugify from homeassistant.util import slugify
from .normalized_name_base_registry import ( from .normalized_name_base_registry import (
@ -17,7 +17,7 @@ from .normalized_name_base_registry import (
) )
from .registry import BaseRegistry from .registry import BaseRegistry
from .storage import Store from .storage import Store
from .typing import UNDEFINED, EventType, UndefinedType from .typing import UNDEFINED, UndefinedType
DATA_REGISTRY = "floor_registry" DATA_REGISTRY = "floor_registry"
EVENT_FLOOR_REGISTRY_UPDATED = "floor_registry_updated" EVENT_FLOOR_REGISTRY_UPDATED = "floor_registry_updated"
@ -32,7 +32,7 @@ class EventFloorRegistryUpdatedData(TypedDict):
floor_id: str floor_id: str
EventFloorRegistryUpdated = EventType[EventFloorRegistryUpdatedData] EventFloorRegistryUpdated = Event[EventFloorRegistryUpdatedData]
@dataclass(slots=True, kw_only=True, frozen=True) @dataclass(slots=True, kw_only=True, frozen=True)

View File

@ -11,7 +11,7 @@ from types import ModuleType
from typing import Any from typing import Any
from homeassistant.const import EVENT_COMPONENT_LOADED from homeassistant.const import EVENT_COMPONENT_LOADED
from homeassistant.core import HassJob, HomeAssistant, callback from homeassistant.core import Event, HassJob, HomeAssistant, callback
from homeassistant.loader import ( from homeassistant.loader import (
Integration, Integration,
async_get_integrations, async_get_integrations,
@ -22,8 +22,6 @@ from homeassistant.loader import (
from homeassistant.setup import ATTR_COMPONENT, EventComponentLoaded from homeassistant.setup import ATTR_COMPONENT, EventComponentLoaded
from homeassistant.util.logging import catch_log_exception from homeassistant.util.logging import catch_log_exception
from .typing import EventType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DATA_INTEGRATION_PLATFORMS = "integration_platforms" DATA_INTEGRATION_PLATFORMS = "integration_platforms"
@ -41,7 +39,7 @@ class IntegrationPlatform:
def _async_integration_platform_component_loaded( def _async_integration_platform_component_loaded(
hass: HomeAssistant, hass: HomeAssistant,
integration_platforms: list[IntegrationPlatform], integration_platforms: list[IntegrationPlatform],
event: EventType[EventComponentLoaded], event: Event[EventComponentLoaded],
) -> None: ) -> None:
"""Process integration platforms for a component.""" """Process integration platforms for a component."""
if "." in (component_name := event.data[ATTR_COMPONENT]): if "." in (component_name := event.data[ATTR_COMPONENT]):

View File

@ -7,7 +7,7 @@ import dataclasses
from dataclasses import dataclass from dataclasses import dataclass
from typing import Literal, TypedDict, cast from typing import Literal, TypedDict, cast
from homeassistant.core import HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.util import slugify from homeassistant.util import slugify
from .normalized_name_base_registry import ( from .normalized_name_base_registry import (
@ -17,7 +17,7 @@ from .normalized_name_base_registry import (
) )
from .registry import BaseRegistry from .registry import BaseRegistry
from .storage import Store from .storage import Store
from .typing import UNDEFINED, EventType, UndefinedType from .typing import UNDEFINED, UndefinedType
DATA_REGISTRY = "label_registry" DATA_REGISTRY = "label_registry"
EVENT_LABEL_REGISTRY_UPDATED = "label_registry_updated" EVENT_LABEL_REGISTRY_UPDATED = "label_registry_updated"
@ -32,7 +32,7 @@ class EventLabelRegistryUpdatedData(TypedDict):
label_id: str label_id: str
EventLabelRegistryUpdated = EventType[EventLabelRegistryUpdatedData] EventLabelRegistryUpdated = Event[EventLabelRegistryUpdatedData]
@dataclass(slots=True, frozen=True, kw_only=True) @dataclass(slots=True, frozen=True, kw_only=True)

View File

@ -28,7 +28,7 @@ from .core import (
from .exceptions import DependencyError, HomeAssistantError from .exceptions import DependencyError, HomeAssistantError
from .helpers import translation from .helpers import translation
from .helpers.issue_registry import IssueSeverity, async_create_issue from .helpers.issue_registry import IssueSeverity, async_create_issue
from .helpers.typing import ConfigType, EventType from .helpers.typing import ConfigType
from .util import ensure_unique_string from .util import ensure_unique_string
from .util.async_ import create_eager_task from .util.async_ import create_eager_task
@ -592,7 +592,7 @@ def _async_when_setup(
await when_setup() await when_setup()
@callback @callback
def _async_is_component_filter(event: EventType[EventComponentLoaded]) -> bool: def _async_is_component_filter(event: Event[EventComponentLoaded]) -> bool:
"""Check if the event is for the component.""" """Check if the event is for the component."""
return event.data[ATTR_COMPONENT] == component return event.data[ATTR_COMPONENT] == component

View File

@ -23,13 +23,12 @@ from homeassistant.const import (
STATE_ON, STATE_ON,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.event import ( from homeassistant.helpers.event import (
EventStateChangedData, EventStateChangedData,
async_track_state_change_event, async_track_state_change_event,
) )
from homeassistant.helpers.typing import EventType
from .conftest import MockESPHomeDevice from .conftest import MockESPHomeDevice
@ -225,7 +224,7 @@ async def test_entities_removed_after_reload(
on_future = hass.loop.create_future() on_future = hass.loop.create_future()
@callback @callback
def _async_wait_for_on(event: EventType[EventStateChangedData]) -> None: def _async_wait_for_on(event: Event[EventStateChangedData]) -> None:
if event.data["new_state"].state == STATE_ON: if event.data["new_state"].state == STATE_ON:
on_future.set_result(None) on_future.set_result(None)