mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Replace EventType with Event [a-g] (#112739)
This commit is contained in:
parent
a6b842f818
commit
25237e0377
@ -26,7 +26,7 @@ from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import HassJob, HomeAssistant
|
||||
from homeassistant.core import Event, HassJob, HomeAssistant
|
||||
from homeassistant.exceptions import ServiceNotFound
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
@ -37,7 +37,7 @@ from homeassistant.helpers.event import (
|
||||
async_track_state_change_event,
|
||||
)
|
||||
from homeassistant.helpers.template import Template
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.dt import now
|
||||
|
||||
from .const import (
|
||||
@ -199,9 +199,7 @@ class Alert(Entity):
|
||||
return STATE_ON
|
||||
return STATE_IDLE
|
||||
|
||||
async def watched_entity_change(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
) -> None:
|
||||
async def watched_entity_change(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Determine if the alert should start or stop."""
|
||||
if (to_state := event.data["new_state"]) is None:
|
||||
return
|
||||
|
@ -23,7 +23,7 @@ from homeassistant.core import Event, HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entityfilter import FILTER_SCHEMA, EntityFilter
|
||||
from homeassistant.helpers.event import EventStateChangedData
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import ssl as ssl_util
|
||||
|
||||
DOMAIN = "apache_kafka"
|
||||
@ -117,7 +117,7 @@ class KafkaManager:
|
||||
)
|
||||
self._topic = topic
|
||||
|
||||
def _encode_event(self, event: EventType[EventStateChangedData]) -> bytes | None:
|
||||
def _encode_event(self, event: Event[EventStateChangedData]) -> bytes | None:
|
||||
"""Translate events into a binary JSON payload."""
|
||||
state = event.data["new_state"]
|
||||
if (
|
||||
@ -140,7 +140,7 @@ class KafkaManager:
|
||||
"""Shut the manager down."""
|
||||
await self._producer.stop()
|
||||
|
||||
async def write(self, event: EventType[EventStateChangedData]) -> None:
|
||||
async def write(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Write a binary payload to Kafka."""
|
||||
payload = self._encode_event(event)
|
||||
|
||||
|
@ -49,7 +49,7 @@ from homeassistant.helpers import config_validation as cv, template
|
||||
from homeassistant.helpers.event import EventStateChangedData
|
||||
from homeassistant.helpers.json import json_dumps, json_fragment
|
||||
from homeassistant.helpers.service import async_get_all_descriptions
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.json import json_loads
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -390,7 +390,7 @@ class APIDomainServicesView(HomeAssistantView):
|
||||
|
||||
@ha.callback
|
||||
def _async_save_changed_entities(
|
||||
event: EventType[EventStateChangedData],
|
||||
event: Event[EventStateChangedData],
|
||||
) -> None:
|
||||
if event.context == context and (state := event.data["new_state"]):
|
||||
changed_states.append(state.json_fragment)
|
||||
|
@ -28,7 +28,7 @@ from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConditionError, TemplateError
|
||||
from homeassistant.helpers import condition
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@ -43,7 +43,7 @@ from homeassistant.helpers.event import (
|
||||
)
|
||||
from homeassistant.helpers.reload import async_setup_reload_service
|
||||
from homeassistant.helpers.template import Template, result_as_boolean
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, PLATFORMS
|
||||
from .const import (
|
||||
@ -234,7 +234,7 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
|
||||
@callback
|
||||
def async_threshold_sensor_state_listener(
|
||||
event: EventType[EventStateChangedData],
|
||||
event: Event[EventStateChangedData],
|
||||
) -> None:
|
||||
"""Handle sensor state changes.
|
||||
|
||||
@ -260,7 +260,7 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
|
||||
@callback
|
||||
def _async_template_result_changed(
|
||||
event: EventType[EventStateChangedData] | None,
|
||||
event: Event[EventStateChangedData] | None,
|
||||
updates: list[TrackTemplateResult],
|
||||
) -> None:
|
||||
track_template_result = updates.pop()
|
||||
|
@ -18,13 +18,13 @@ from homeassistant.const import (
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State, callback
|
||||
from homeassistant.core import Event, HomeAssistant, State, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
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_COMPENSATION,
|
||||
@ -129,7 +129,7 @@ class CompensationSensor(SensorEntity):
|
||||
|
||||
@callback
|
||||
def _async_compensation_sensor_state_listener(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
self, event: Event[EventStateChangedData]
|
||||
) -> None:
|
||||
"""Handle sensor state changes."""
|
||||
new_state: State | None
|
||||
|
@ -115,7 +115,7 @@ def async_setup(hass: core.HomeAssistant) -> None:
|
||||
async_should_expose(hass, DOMAIN, entity_id)
|
||||
|
||||
@core.callback
|
||||
def async_entity_state_listener(event: EventType[EventStateChangedData]) -> None:
|
||||
def async_entity_state_listener(event: core.Event[EventStateChangedData]) -> None:
|
||||
"""Set expose flag on new entities."""
|
||||
async_should_expose(hass, DOMAIN, event.data["entity_id"])
|
||||
|
||||
@ -714,7 +714,7 @@ class DefaultAgent(AbstractConversationAgent):
|
||||
|
||||
@core.callback
|
||||
def _async_handle_state_changed(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
self, event: core.Event[EventStateChangedData]
|
||||
) -> None:
|
||||
"""Clear names list cache when a state is added or removed from the state machine."""
|
||||
if event.data["old_state"] and event.data["new_state"]:
|
||||
|
@ -19,7 +19,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,
|
||||
@ -31,7 +31,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,
|
||||
@ -212,7 +212,7 @@ class DerivativeSensor(RestoreSensor, SensorEntity):
|
||||
_LOGGER.warning("Could not restore last state: %s", err)
|
||||
|
||||
@callback
|
||||
def calc_derivative(event: EventType[EventStateChangedData]) -> None:
|
||||
def calc_derivative(event: Event[EventStateChangedData]) -> None:
|
||||
"""Handle the sensor state changes."""
|
||||
if (
|
||||
(old_state := event.data["old_state"]) is None
|
||||
|
@ -53,7 +53,7 @@ from homeassistant.helpers.event import (
|
||||
async_track_state_added_domain,
|
||||
async_track_time_interval,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import DHCPMatcher, async_get_dhcp
|
||||
|
||||
from .const import DOMAIN
|
||||
@ -345,9 +345,7 @@ class DeviceTrackerWatcher(WatcherBase):
|
||||
self._async_process_device_state(state)
|
||||
|
||||
@callback
|
||||
def _async_process_device_event(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
) -> None:
|
||||
def _async_process_device_event(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Process a device tracker state change event."""
|
||||
self._async_process_device_state(event.data["new_state"])
|
||||
|
||||
|
@ -16,14 +16,14 @@ from homeassistant.components import (
|
||||
script,
|
||||
)
|
||||
from homeassistant.const import CONF_ENTITIES, CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant, State, callback, split_entity_id
|
||||
from homeassistant.core import Event, HomeAssistant, State, callback, split_entity_id
|
||||
from homeassistant.helpers import storage
|
||||
from homeassistant.helpers.event import (
|
||||
EventStateChangedData,
|
||||
async_track_state_added_domain,
|
||||
async_track_state_removed_domain,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
SUPPORTED_DOMAINS = {
|
||||
climate.DOMAIN,
|
||||
@ -224,7 +224,7 @@ class Config:
|
||||
]
|
||||
|
||||
@callback
|
||||
def _clear_exposed_cache(self, event: EventType[EventStateChangedData]) -> None:
|
||||
def _clear_exposed_cache(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Clear the cache of exposed entity ids."""
|
||||
self.get_exposed_entity_ids.cache_clear()
|
||||
|
||||
|
@ -65,12 +65,11 @@ from homeassistant.const import (
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
from homeassistant.core import Event, State
|
||||
from homeassistant.helpers.event import (
|
||||
EventStateChangedData,
|
||||
async_track_state_change_event,
|
||||
)
|
||||
from homeassistant.helpers.typing import EventType
|
||||
from homeassistant.util.json import json_loads
|
||||
from homeassistant.util.network import is_local
|
||||
|
||||
@ -916,7 +915,7 @@ async def wait_for_state_change_or_timeout(
|
||||
ev = asyncio.Event()
|
||||
|
||||
@core.callback
|
||||
def _async_event_changed(event: EventType[EventStateChangedData]) -> None:
|
||||
def _async_event_changed(event: Event[EventStateChangedData]) -> None:
|
||||
ev.set()
|
||||
|
||||
unsub = async_track_state_change_event(hass, [entity_id], _async_event_changed)
|
||||
|
@ -50,7 +50,6 @@ from homeassistant.helpers.issue_registry import (
|
||||
)
|
||||
from homeassistant.helpers.service import async_set_service_schema
|
||||
from homeassistant.helpers.template import Template
|
||||
from homeassistant.helpers.typing import EventType
|
||||
from homeassistant.util.async_ import create_eager_task
|
||||
|
||||
from .bluetooth import async_connect_scanner
|
||||
@ -283,7 +282,7 @@ class ESPHomeManager:
|
||||
def _send_home_assistant_state_event(
|
||||
self,
|
||||
attribute: str | None,
|
||||
event: EventType[EventStateChangedData],
|
||||
event: Event[EventStateChangedData],
|
||||
) -> None:
|
||||
"""Forward Home Assistant states updates to ESPHome."""
|
||||
event_data = event.data
|
||||
|
@ -35,7 +35,7 @@ from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State, callback
|
||||
from homeassistant.core import Event, HomeAssistant, State, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import (
|
||||
@ -44,12 +44,7 @@ from homeassistant.helpers.event import (
|
||||
)
|
||||
from homeassistant.helpers.reload import async_setup_reload_service
|
||||
from homeassistant.helpers.start import async_at_started
|
||||
from homeassistant.helpers.typing import (
|
||||
ConfigType,
|
||||
DiscoveryInfoType,
|
||||
EventType,
|
||||
StateType,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
from homeassistant.util.decorator import Registry
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@ -227,7 +222,7 @@ class SensorFilter(SensorEntity):
|
||||
|
||||
@callback
|
||||
def _update_filter_sensor_state_event(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
self, event: Event[EventStateChangedData]
|
||||
) -> None:
|
||||
"""Handle device state changes."""
|
||||
_LOGGER.debug("Update filter on event: %s", event)
|
||||
|
@ -60,7 +60,7 @@ from homeassistant.helpers.event import (
|
||||
)
|
||||
from homeassistant.helpers.reload import async_setup_reload_service
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, PLATFORMS
|
||||
|
||||
@ -413,9 +413,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
||||
# Get default temp from super class
|
||||
return super().max_temp
|
||||
|
||||
async def _async_sensor_changed(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
) -> None:
|
||||
async def _async_sensor_changed(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Handle temperature changes."""
|
||||
new_state = event.data["new_state"]
|
||||
if new_state is None or new_state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||
@ -438,7 +436,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
||||
await self._async_heater_turn_off()
|
||||
|
||||
@callback
|
||||
def _async_switch_changed(self, event: EventType[EventStateChangedData]) -> None:
|
||||
def _async_switch_changed(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Handle heater switch state changes."""
|
||||
new_state = event.data["new_state"]
|
||||
old_state = event.data["old_state"]
|
||||
|
@ -8,7 +8,14 @@ from typing import Final
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_EVENT, CONF_PLATFORM, CONF_SOURCE, CONF_ZONE
|
||||
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
|
||||
from homeassistant.helpers.config_validation import entity_domain
|
||||
from homeassistant.helpers.event import (
|
||||
@ -17,7 +24,7 @@ from homeassistant.helpers.event import (
|
||||
async_track_state_change_filtered,
|
||||
)
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
@ -58,7 +65,7 @@ async def async_attach_trigger(
|
||||
job = HassJob(action)
|
||||
|
||||
@callback
|
||||
def state_change_listener(event: EventType[EventStateChangedData]) -> None:
|
||||
def state_change_listener(event: Event[EventStateChangedData]) -> None:
|
||||
"""Handle specific state changes."""
|
||||
# Skip if the event's source does not match the trigger's source.
|
||||
from_state = event.data["old_state"]
|
||||
|
@ -27,6 +27,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import (
|
||||
CALLBACK_TYPE,
|
||||
Event,
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
State,
|
||||
@ -48,7 +49,7 @@ from homeassistant.helpers.integration_platform import (
|
||||
async_process_integration_platforms,
|
||||
)
|
||||
from homeassistant.helpers.reload import async_reload_integration_platforms
|
||||
from homeassistant.helpers.typing import ConfigType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
from .const import CONF_HIDE_MEMBERS
|
||||
@ -456,7 +457,7 @@ class GroupEntity(Entity):
|
||||
|
||||
@callback
|
||||
def async_state_changed_listener(
|
||||
event: EventType[EventStateChangedData] | None,
|
||||
event: Event[EventStateChangedData] | None,
|
||||
) -> None:
|
||||
"""Handle child updates."""
|
||||
self.async_update_group_state()
|
||||
@ -481,7 +482,7 @@ class GroupEntity(Entity):
|
||||
|
||||
@callback
|
||||
def async_state_changed_listener(
|
||||
event: EventType[EventStateChangedData],
|
||||
event: Event[EventStateChangedData],
|
||||
) -> None:
|
||||
"""Handle child updates."""
|
||||
self.async_set_context(event.context)
|
||||
@ -762,7 +763,7 @@ class Group(Entity):
|
||||
self._async_stop()
|
||||
|
||||
async def _async_state_changed_listener(
|
||||
self, event: EventType[EventStateChangedData]
|
||||
self, event: Event[EventStateChangedData]
|
||||
) -> None:
|
||||
"""Respond to a member state changing.
|
||||
|
||||
|
@ -25,14 +25,14 @@ from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import Event, HomeAssistant, 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 (
|
||||
EventStateChangedData,
|
||||
async_track_state_change_event,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, EventType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import GroupEntity
|
||||
|
||||
@ -125,7 +125,7 @@ class EventGroup(GroupEntity, EventEntity):
|
||||
|
||||
@callback
|
||||
def async_state_changed_listener(
|
||||
event: EventType[EventStateChangedData],
|
||||
event: Event[EventStateChangedData],
|
||||
) -> None:
|
||||
"""Handle child updates."""
|
||||
if not self.hass.is_running:
|
||||
|
@ -45,14 +45,14 @@ from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, State, callback
|
||||
from homeassistant.core import CALLBACK_TYPE, 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 (
|
||||
EventStateChangedData,
|
||||
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"
|
||||
@ -148,7 +148,7 @@ class MediaPlayerGroup(MediaPlayerEntity):
|
||||
}
|
||||
|
||||
@callback
|
||||
def async_on_state_change(self, event: EventType[EventStateChangedData]) -> None:
|
||||
def async_on_state_change(self, event: Event[EventStateChangedData]) -> None:
|
||||
"""Update supported features and state when a new state is received."""
|
||||
self.async_set_context(event.context)
|
||||
self.async_update_supported_features(
|
||||
@ -233,7 +233,7 @@ class MediaPlayerGroup(MediaPlayerEntity):
|
||||
|
||||
@callback
|
||||
def async_state_changed_listener(
|
||||
event: EventType[EventStateChangedData] | None,
|
||||
event: Event[EventStateChangedData] | None,
|
||||
) -> None:
|
||||
"""Handle child updates."""
|
||||
self.async_update_group_state()
|
||||
|
Loading…
x
Reference in New Issue
Block a user