From 9e67bccb89de3ef3627ddf892cb422e8cbcf1295 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 18 Jul 2023 08:51:06 +0200 Subject: [PATCH] Replace EventType annotations with Event (#96426) --- homeassistant/components/dsmr/sensor.py | 4 ++-- homeassistant/components/group/media_player.py | 6 +++--- homeassistant/components/min_max/sensor.py | 3 +-- homeassistant/components/shelly/logbook.py | 7 +++---- homeassistant/components/shelly/utils.py | 5 ++--- homeassistant/helpers/typing.py | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/dsmr/sensor.py b/homeassistant/components/dsmr/sensor.py index e6d1d035e3b..12ad3350e44 100644 --- a/homeassistant/components/dsmr/sensor.py +++ b/homeassistant/components/dsmr/sensor.py @@ -35,7 +35,7 @@ from homeassistant.const import ( from homeassistant.core import CoreState, Event, HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import EventType, StateType +from homeassistant.helpers.typing import StateType from homeassistant.util import Throttle from .const import ( @@ -457,7 +457,7 @@ async def async_setup_entry( if transport: # Register listener to close transport on HA shutdown @callback - def close_transport(_event: EventType) -> None: + def close_transport(_event: Event) -> None: """Close the transport on HA shutdown.""" if not transport: # noqa: B023 return diff --git a/homeassistant/components/group/media_player.py b/homeassistant/components/group/media_player.py index b271e57cb8a..ad375630bea 100644 --- a/homeassistant/components/group/media_player.py +++ b/homeassistant/components/group/media_player.py @@ -44,11 +44,11 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) -from homeassistant.core import HomeAssistant, State, callback +from homeassistant.core import Event, HomeAssistant, State, callback from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_state_change_event -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, EventType +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType KEY_ANNOUNCE = "announce" KEY_CLEAR_PLAYLIST = "clear_playlist" @@ -130,7 +130,7 @@ class MediaPlayerGroup(MediaPlayerEntity): } @callback - def async_on_state_change(self, event: EventType) -> None: + def async_on_state_change(self, event: Event) -> None: """Update supported features and state when a new state is received.""" self.async_set_context(event.context) self.async_update_supported_features( diff --git a/homeassistant/components/min_max/sensor.py b/homeassistant/components/min_max/sensor.py index d0064d07511..d1ea9695322 100644 --- a/homeassistant/components/min_max/sensor.py +++ b/homeassistant/components/min_max/sensor.py @@ -30,7 +30,6 @@ from homeassistant.helpers.reload import async_setup_reload_service from homeassistant.helpers.typing import ( ConfigType, DiscoveryInfoType, - EventType, StateType, ) @@ -287,7 +286,7 @@ class MinMaxSensor(SensorEntity): @callback def _async_min_max_sensor_state_listener( - self, event: EventType, update_state: bool = True + self, event: Event, update_state: bool = True ) -> None: """Handle the sensor state changes.""" new_state: State | None = event.data.get("new_state") diff --git a/homeassistant/components/shelly/logbook.py b/homeassistant/components/shelly/logbook.py index 57df5d1ab0a..d55ffe0fd28 100644 --- a/homeassistant/components/shelly/logbook.py +++ b/homeassistant/components/shelly/logbook.py @@ -5,8 +5,7 @@ from collections.abc import Callable from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME from homeassistant.const import ATTR_DEVICE_ID -from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers.typing import EventType +from homeassistant.core import Event, HomeAssistant, callback from .const import ( ATTR_CHANNEL, @@ -27,12 +26,12 @@ from .utils import get_rpc_entity_name @callback def async_describe_events( hass: HomeAssistant, - async_describe_event: Callable[[str, str, Callable[[EventType], dict]], None], + async_describe_event: Callable[[str, str, Callable[[Event], dict]], None], ) -> None: """Describe logbook events.""" @callback - def async_describe_shelly_click_event(event: EventType) -> dict[str, str]: + def async_describe_shelly_click_event(event: Event) -> dict[str, str]: """Describe shelly.click logbook event (block device).""" device_id = event.data[ATTR_DEVICE_ID] click_type = event.data[ATTR_CLICK_TYPE] diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 03df3da346b..a66b77ed94b 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -12,7 +12,7 @@ from aioshelly.rpc_device import RpcDevice, WsServer from homeassistant.components.http import HomeAssistantView from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import singleton from homeassistant.helpers.device_registry import ( CONNECTION_NETWORK_MAC, @@ -20,7 +20,6 @@ from homeassistant.helpers.device_registry import ( format_mac, ) from homeassistant.helpers.entity_registry import async_get as er_async_get -from homeassistant.helpers.typing import EventType from homeassistant.util.dt import utcnow from .const import ( @@ -211,7 +210,7 @@ async def get_coap_context(hass: HomeAssistant) -> COAP: await context.initialize(port) @callback - def shutdown_listener(ev: EventType) -> None: + def shutdown_listener(ev: Event) -> None: context.close() hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown_listener) diff --git a/homeassistant/helpers/typing.py b/homeassistant/helpers/typing.py index 326d2f98259..5a76fd262a8 100644 --- a/homeassistant/helpers/typing.py +++ b/homeassistant/helpers/typing.py @@ -9,7 +9,6 @@ GPSType = tuple[float, float] ConfigType = dict[str, Any] ContextType = homeassistant.core.Context DiscoveryInfoType = dict[str, Any] -EventType = homeassistant.core.Event ServiceDataType = dict[str, Any] StateType = str | int | float | None TemplateVarsType = Mapping[str, Any] | None @@ -33,4 +32,5 @@ UNDEFINED = UndefinedType._singleton # pylint: disable=protected-access # that may rely on them. # In due time they will be removed. HomeAssistantType = homeassistant.core.HomeAssistant +EventType = homeassistant.core.Event ServiceCallType = homeassistant.core.ServiceCall