diff --git a/homeassistant/components/history/websocket_api.py b/homeassistant/components/history/websocket_api.py index 63142b139bc..1f1c5064c5a 100644 --- a/homeassistant/components/history/websocket_api.py +++ b/homeassistant/components/history/websocket_api.py @@ -36,7 +36,6 @@ from homeassistant.helpers.event import ( async_track_state_change_event, ) from homeassistant.helpers.json import json_bytes -from homeassistant.helpers.typing import EventType import homeassistant.util.dt as dt_util from .const import EVENT_COALESCE_TIME, MAX_PENDING_HISTORY_STATES @@ -373,7 +372,7 @@ def _async_subscribe_events( assert is_callback(target), "target must be a callback" @callback - def _forward_state_events_filtered(event: EventType[EventStateChangedData]) -> None: + def _forward_state_events_filtered(event: Event[EventStateChangedData]) -> None: """Filter state events and forward them.""" if (new_state := event.data["new_state"]) is None or ( old_state := event.data["old_state"] diff --git a/homeassistant/components/history_stats/coordinator.py b/homeassistant/components/history_stats/coordinator.py index 0ab68adda57..2127f1d3dc5 100644 --- a/homeassistant/components/history_stats/coordinator.py +++ b/homeassistant/components/history_stats/coordinator.py @@ -6,14 +6,13 @@ from datetime import timedelta import logging from typing import Any -from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback +from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback from homeassistant.exceptions import TemplateError from homeassistant.helpers.event import ( EventStateChangedData, async_track_state_change_event, ) from homeassistant.helpers.start import async_at_start -from homeassistant.helpers.typing import EventType from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .data import HistoryStats, HistoryStatsState @@ -88,7 +87,7 @@ class HistoryStatsUpdateCoordinator(DataUpdateCoordinator[HistoryStatsState]): ) async def _async_update_from_event( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Process an update from an event.""" self.async_set_updated_data(await self._history_stats.async_update(event)) diff --git a/homeassistant/components/history_stats/data.py b/homeassistant/components/history_stats/data.py index 9a26853cbb5..62ab28dc4f1 100644 --- a/homeassistant/components/history_stats/data.py +++ b/homeassistant/components/history_stats/data.py @@ -6,10 +6,9 @@ from dataclasses import dataclass import datetime from homeassistant.components.recorder import get_instance, history -from homeassistant.core import HomeAssistant, State +from homeassistant.core import Event, HomeAssistant, State from homeassistant.helpers.event import EventStateChangedData from homeassistant.helpers.template import Template -from homeassistant.helpers.typing import EventType import homeassistant.util.dt as dt_util from .helpers import async_calculate_period, floored_timestamp @@ -59,7 +58,7 @@ class HistoryStats: self._end = end async def async_update( - self, event: EventType[EventStateChangedData] | None + self, event: Event[EventStateChangedData] | None ) -> HistoryStatsState: """Update the stats at a given time.""" # Get previous values of start and end diff --git a/homeassistant/components/homeassistant/triggers/numeric_state.py b/homeassistant/components/homeassistant/triggers/numeric_state.py index 713c72acb89..2575af41401 100644 --- a/homeassistant/components/homeassistant/triggers/numeric_state.py +++ b/homeassistant/components/homeassistant/triggers/numeric_state.py @@ -19,7 +19,14 @@ from homeassistant.const import ( CONF_PLATFORM, CONF_VALUE_TEMPLATE, ) -from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, State, callback +from homeassistant.core import ( + CALLBACK_TYPE, + Event, + HassJob, + HomeAssistant, + State, + callback, +) from homeassistant.helpers import ( condition, config_validation as cv, @@ -32,7 +39,7 @@ from homeassistant.helpers.event import ( async_track_state_change_event, ) from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo -from homeassistant.helpers.typing import ConfigType, EventType +from homeassistant.helpers.typing import ConfigType _T = TypeVar("_T", bound=dict[str, Any]) @@ -152,7 +159,7 @@ async def async_attach_trigger( ) @callback - def state_automation_listener(event: EventType[EventStateChangedData]) -> None: + def state_automation_listener(event: Event[EventStateChangedData]) -> None: """Listen for state changes and calls action.""" entity_id = event.data["entity_id"] from_s = event.data["old_state"] diff --git a/homeassistant/components/homeassistant/triggers/state.py b/homeassistant/components/homeassistant/triggers/state.py index a728a8f42e4..6f3183e2b40 100644 --- a/homeassistant/components/homeassistant/triggers/state.py +++ b/homeassistant/components/homeassistant/triggers/state.py @@ -10,7 +10,14 @@ import voluptuous as vol from homeassistant import exceptions from homeassistant.const import CONF_ATTRIBUTE, CONF_FOR, CONF_PLATFORM, MATCH_ALL -from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, State, callback +from homeassistant.core import ( + CALLBACK_TYPE, + Event, + HassJob, + HomeAssistant, + State, + callback, +) from homeassistant.helpers import ( config_validation as cv, entity_registry as er, @@ -23,7 +30,7 @@ from homeassistant.helpers.event import ( process_state_match, ) from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo -from homeassistant.helpers.typing import ConfigType, EventType +from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -125,7 +132,7 @@ async def async_attach_trigger( _variables = trigger_info["variables"] or {} @callback - def state_automation_listener(event: EventType[EventStateChangedData]) -> None: + def state_automation_listener(event: Event[EventStateChangedData]) -> None: """Listen for state changes and calls action.""" entity = event.data["entity_id"] from_s = event.data["old_state"] diff --git a/homeassistant/components/homeassistant/triggers/time.py b/homeassistant/components/homeassistant/triggers/time.py index 4f2ac9e8480..b1d19d54795 100644 --- a/homeassistant/components/homeassistant/triggers/time.py +++ b/homeassistant/components/homeassistant/triggers/time.py @@ -13,7 +13,14 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) -from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, State, callback +from homeassistant.core import ( + CALLBACK_TYPE, + Event, + HassJob, + HomeAssistant, + State, + callback, +) from homeassistant.helpers import config_validation as cv from homeassistant.helpers.event import ( EventStateChangedData, @@ -22,7 +29,7 @@ from homeassistant.helpers.event import ( async_track_time_change, ) from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo -from homeassistant.helpers.typing import ConfigType, EventType +from homeassistant.helpers.typing import ConfigType import homeassistant.util.dt as dt_util _TIME_TRIGGER_SCHEMA = vol.Any( @@ -72,7 +79,7 @@ async def async_attach_trigger( ) @callback - def update_entity_trigger_event(event: EventType[EventStateChangedData]) -> None: + def update_entity_trigger_event(event: Event[EventStateChangedData]) -> None: """update_entity_trigger from the event.""" return update_entity_trigger(event.data["entity_id"], event.data["new_state"]) diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index 5303b2a6736..7c8eb973911 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -44,6 +44,7 @@ from homeassistant.const import ( from homeassistant.core import ( CALLBACK_TYPE, Context, + Event, HomeAssistant, State, callback as ha_callback, @@ -54,7 +55,6 @@ from homeassistant.helpers.event import ( EventStateChangedData, async_track_state_change_event, ) -from homeassistant.helpers.typing import EventType from homeassistant.util.decorator import Registry from .const import ( @@ -478,7 +478,7 @@ class HomeAccessory(Accessory): # type: ignore[misc] @ha_callback def async_update_event_state_callback( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle state change event listener callback.""" new_state = event.data["new_state"] @@ -530,7 +530,7 @@ class HomeAccessory(Accessory): # type: ignore[misc] @ha_callback def async_update_linked_battery_callback( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle linked battery sensor state change listener callback.""" if (new_state := event.data["new_state"]) is None: @@ -543,7 +543,7 @@ class HomeAccessory(Accessory): # type: ignore[misc] @ha_callback def async_update_linked_battery_charging_callback( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle linked battery charging sensor state change listener callback.""" if (new_state := event.data["new_state"]) is None: diff --git a/homeassistant/components/homekit/type_cameras.py b/homeassistant/components/homekit/type_cameras.py index 28b34503355..d47d9775ed2 100644 --- a/homeassistant/components/homekit/type_cameras.py +++ b/homeassistant/components/homekit/type_cameras.py @@ -17,13 +17,12 @@ from pyhap.util import callback as pyhap_callback from homeassistant.components import camera from homeassistant.components.ffmpeg import get_ffmpeg_manager from homeassistant.const import STATE_ON -from homeassistant.core import HomeAssistant, State, callback +from homeassistant.core import Event, HomeAssistant, State, callback from homeassistant.helpers.event import ( EventStateChangedData, async_track_state_change_event, async_track_time_interval, ) -from homeassistant.helpers.typing import EventType from .accessories import TYPES, HomeAccessory, HomeDriver from .const import ( @@ -284,7 +283,7 @@ class Camera(HomeAccessory, PyhapCamera): # type: ignore[misc] @callback def _async_update_motion_state_event( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle state change event listener callback.""" if not state_changed_event_is_same_state(event): @@ -311,7 +310,7 @@ class Camera(HomeAccessory, PyhapCamera): # type: ignore[misc] @callback def _async_update_doorbell_state_event( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle state change event listener callback.""" if not state_changed_event_is_same_state(event): diff --git a/homeassistant/components/homekit/type_covers.py b/homeassistant/components/homekit/type_covers.py index 5e60875e485..2452fd65026 100644 --- a/homeassistant/components/homekit/type_covers.py +++ b/homeassistant/components/homekit/type_covers.py @@ -34,12 +34,11 @@ from homeassistant.const import ( STATE_OPEN, STATE_OPENING, ) -from homeassistant.core import State, callback +from homeassistant.core import Event, State, callback from homeassistant.helpers.event import ( EventStateChangedData, async_track_state_change_event, ) -from homeassistant.helpers.typing import EventType from .accessories import TYPES, HomeAccessory from .const import ( @@ -147,7 +146,7 @@ class GarageDoorOpener(HomeAccessory): @callback def _async_update_obstruction_event( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle state change event listener callback.""" self._async_update_obstruction_state(event.data["new_state"]) diff --git a/homeassistant/components/homekit/type_humidifiers.py b/homeassistant/components/homekit/type_humidifiers.py index a9782aedaf0..2b4de072b6a 100644 --- a/homeassistant/components/homekit/type_humidifiers.py +++ b/homeassistant/components/homekit/type_humidifiers.py @@ -25,12 +25,11 @@ from homeassistant.const import ( SERVICE_TURN_ON, STATE_ON, ) -from homeassistant.core import State, callback +from homeassistant.core import Event, State, callback from homeassistant.helpers.event import ( EventStateChangedData, async_track_state_change_event, ) -from homeassistant.helpers.typing import EventType from .accessories import TYPES, HomeAccessory from .const import ( @@ -195,7 +194,7 @@ class HumidifierDehumidifier(HomeAccessory): @callback def async_update_current_humidity_event( - self, event: EventType[EventStateChangedData] + self, event: Event[EventStateChangedData] ) -> None: """Handle state change event listener callback.""" self._async_update_current_humidity(event.data["new_state"]) diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index 35e60bff2df..2d0eccf9b7c 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -38,11 +38,10 @@ from homeassistant.const import ( CONF_TYPE, UnitOfTemperature, ) -from homeassistant.core import HomeAssistant, State, callback, split_entity_id +from homeassistant.core import Event, HomeAssistant, State, callback, split_entity_id import homeassistant.helpers.config_validation as cv from homeassistant.helpers.event import EventStateChangedData from homeassistant.helpers.storage import STORAGE_DIR -from homeassistant.helpers.typing import EventType from homeassistant.util.unit_conversion import TemperatureConverter from .const import ( @@ -624,7 +623,7 @@ def state_needs_accessory_mode(state: State) -> bool: ) -def state_changed_event_is_same_state(event: EventType[EventStateChangedData]) -> bool: +def state_changed_event_is_same_state(event: Event[EventStateChangedData]) -> bool: """Check if a state changed event is the same state.""" event_data = event.data old_state = event_data["old_state"] diff --git a/homeassistant/components/integration/sensor.py b/homeassistant/components/integration/sensor.py index 63b01d13805..956b868272f 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -27,7 +27,7 @@ from homeassistant.const import ( STATE_UNKNOWN, UnitOfTime, ) -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import ( config_validation as cv, device_registry as dr, @@ -39,7 +39,7 @@ from homeassistant.helpers.event import ( EventStateChangedData, async_track_state_change_event, ) -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, EventType +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from .const import ( CONF_ROUND_DIGITS, @@ -293,7 +293,7 @@ class IntegrationSensor(RestoreSensor): self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) @callback - def calc_integration(event: EventType[EventStateChangedData]) -> None: + def calc_integration(event: Event[EventStateChangedData]) -> None: """Handle the sensor state changes.""" old_state = event.data["old_state"] new_state = event.data["new_state"] diff --git a/homeassistant/components/knx/expose.py b/homeassistant/components/knx/expose.py index aee6e148e62..6e4a3b80f6e 100644 --- a/homeassistant/components/knx/expose.py +++ b/homeassistant/components/knx/expose.py @@ -18,12 +18,12 @@ 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.event import ( EventStateChangedData, async_track_state_change_event, ) -from homeassistant.helpers.typing import ConfigType, EventType, StateType +from homeassistant.helpers.typing import ConfigType, StateType from .const import CONF_RESPOND_TO_READ, KNX_ADDRESS from .schema import ExposeSchema @@ -149,9 +149,7 @@ class KNXExposeSensor: return str(value)[:14] return value - async def _async_entity_changed( - self, event: EventType[EventStateChangedData] - ) -> None: + async def _async_entity_changed(self, event: Event[EventStateChangedData]) -> None: """Handle entity change.""" new_state = event.data["new_state"] if (new_value := self._get_expose_value(new_state)) is None: