Use EventType for state changed [h-m] (#97117)
This commit is contained in:
parent
40382f0caa
commit
5b73bd2f8e
10 changed files with 104 additions and 57 deletions
|
@ -26,7 +26,7 @@ from homeassistant.const import (
|
|||
STATE_UNKNOWN,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, State, callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
device_registry as dr,
|
||||
|
@ -34,8 +34,11 @@ from homeassistant.helpers import (
|
|||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.event import (
|
||||
EventStateChangedData,
|
||||
async_track_state_change_event,
|
||||
)
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, EventType
|
||||
|
||||
from .const import (
|
||||
CONF_ROUND_DIGITS,
|
||||
|
@ -290,10 +293,10 @@ class IntegrationSensor(RestoreSensor):
|
|||
self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
|
||||
@callback
|
||||
def calc_integration(event: Event) -> None:
|
||||
def calc_integration(event: EventType[EventStateChangedData]) -> None:
|
||||
"""Handle the sensor state changes."""
|
||||
old_state: State | None = event.data.get("old_state")
|
||||
new_state: State | None = event.data.get("new_state")
|
||||
old_state = event.data["old_state"]
|
||||
new_state = event.data["new_state"]
|
||||
|
||||
# We may want to update our state before an early return,
|
||||
# based on the source sensor's unit_of_measurement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue