Replace EventType with Event [h-i] (#112740)

pull/112753/head
Marc Mueller 2024-03-08 19:35:47 +01:00 committed by GitHub
parent 25237e0377
commit 8f1e2f1a7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 54 additions and 42 deletions

View File

@ -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"]

View File

@ -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))

View File

@ -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

View File

@ -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"]

View File

@ -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"]

View File

@ -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"])

View File

@ -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:

View File

@ -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):

View File

@ -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"])

View File

@ -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"])

View File

@ -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"]

View File

@ -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"]

View File

@ -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: