mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use EventStateChangedData type when firing state changed event (#114740)
This commit is contained in:
parent
9189cd5ec2
commit
56ef9500f7
@ -161,6 +161,14 @@ class ConfigSource(enum.StrEnum):
|
||||
YAML = "yaml"
|
||||
|
||||
|
||||
class EventStateChangedData(TypedDict):
|
||||
"""EventStateChanged data."""
|
||||
|
||||
entity_id: str
|
||||
old_state: State | None
|
||||
new_state: State | None
|
||||
|
||||
|
||||
# SOURCE_* are deprecated as of Home Assistant 2022.2, use ConfigSource instead
|
||||
_DEPRECATED_SOURCE_DISCOVERED = DeprecatedConstantEnum(
|
||||
ConfigSource.DISCOVERED, "2025.1"
|
||||
@ -2019,9 +2027,14 @@ class StateMachine:
|
||||
return False
|
||||
|
||||
old_state.expire()
|
||||
state_changed_data: EventStateChangedData = {
|
||||
"entity_id": entity_id,
|
||||
"old_state": old_state,
|
||||
"new_state": None,
|
||||
}
|
||||
self._bus._async_fire( # pylint: disable=protected-access
|
||||
EVENT_STATE_CHANGED,
|
||||
{"entity_id": entity_id, "old_state": old_state, "new_state": None},
|
||||
state_changed_data,
|
||||
context=context,
|
||||
)
|
||||
return True
|
||||
@ -2170,9 +2183,14 @@ class StateMachine:
|
||||
if old_state is not None:
|
||||
old_state.expire()
|
||||
self._states[entity_id] = state
|
||||
state_changed_data: EventStateChangedData = {
|
||||
"entity_id": entity_id,
|
||||
"old_state": old_state,
|
||||
"new_state": state,
|
||||
}
|
||||
self._bus._async_fire( # pylint: disable=protected-access
|
||||
EVENT_STATE_CHANGED,
|
||||
{"entity_id": entity_id, "old_state": old_state, "new_state": state},
|
||||
state_changed_data,
|
||||
context=context,
|
||||
time_fired=timestamp,
|
||||
)
|
||||
|
@ -11,15 +11,7 @@ import functools as ft
|
||||
import logging
|
||||
from random import randint
|
||||
import time
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Concatenate,
|
||||
Generic,
|
||||
ParamSpec,
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any, Concatenate, Generic, ParamSpec, TypeVar
|
||||
|
||||
import attr
|
||||
|
||||
@ -33,6 +25,8 @@ from homeassistant.const import (
|
||||
from homeassistant.core import (
|
||||
CALLBACK_TYPE,
|
||||
Event,
|
||||
# Explicit reexport of 'EventStateChangedData' for backwards compatibility
|
||||
EventStateChangedData as EventStateChangedData, # noqa: PLC0414
|
||||
HassJob,
|
||||
HassJobType,
|
||||
HomeAssistant,
|
||||
@ -163,14 +157,6 @@ class TrackTemplateResult:
|
||||
result: Any
|
||||
|
||||
|
||||
class EventStateChangedData(TypedDict):
|
||||
"""EventStateChanged data."""
|
||||
|
||||
entity_id: str
|
||||
old_state: State | None
|
||||
new_state: State | None
|
||||
|
||||
|
||||
def threaded_listener_factory(
|
||||
async_factory: Callable[Concatenate[HomeAssistant, _P], Any],
|
||||
) -> Callable[Concatenate[HomeAssistant, _P], CALLBACK_TYPE]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user