mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Switch async_track_state_change to the faster async_track_state_change_event part 7 (#37870)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
44fefb3216
commit
1d7f3416d3
@ -199,8 +199,8 @@ class Alert(ToggleEntity):
|
||||
self._send_done_message = False
|
||||
self.entity_id = f"{DOMAIN}.{entity_id}"
|
||||
|
||||
event.async_track_state_change(
|
||||
hass, watched_entity_id, self.watched_entity_change
|
||||
event.async_track_state_change_event(
|
||||
hass, [watched_entity_id], self.watched_entity_change
|
||||
)
|
||||
|
||||
@property
|
||||
@ -222,9 +222,12 @@ class Alert(ToggleEntity):
|
||||
return STATE_ON
|
||||
return STATE_IDLE
|
||||
|
||||
async def watched_entity_change(self, entity, from_state, to_state):
|
||||
async def watched_entity_change(self, ev):
|
||||
"""Determine if the alert should start or stop."""
|
||||
_LOGGER.debug("Watched entity (%s) has changed", entity)
|
||||
to_state = ev.data.get("new_state")
|
||||
if to_state is None:
|
||||
return
|
||||
_LOGGER.debug("Watched entity (%s) has changed", ev.data.get("entity_id"))
|
||||
if to_state.state == self._alert_state and not self._firing:
|
||||
await self.begin_alerting()
|
||||
if to_state.state != self._alert_state and self._firing:
|
||||
|
@ -22,7 +22,7 @@ from homeassistant.const import (
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import async_track_state_change
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -364,10 +364,13 @@ class KNXExposeSensor:
|
||||
self.xknx, name=_name, group_address=self.address, value_type=self.type,
|
||||
)
|
||||
self.xknx.devices.add(self.device)
|
||||
async_track_state_change(self.hass, self.entity_id, self._async_entity_changed)
|
||||
async_track_state_change_event(
|
||||
self.hass, [self.entity_id], self._async_entity_changed
|
||||
)
|
||||
|
||||
async def _async_entity_changed(self, entity_id, old_state, new_state):
|
||||
async def _async_entity_changed(self, event):
|
||||
"""Handle entity change."""
|
||||
new_state = event.data.get("new_state")
|
||||
if new_state is None:
|
||||
return
|
||||
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
||||
@ -375,6 +378,8 @@ class KNXExposeSensor:
|
||||
|
||||
if self.expose_attribute is not None:
|
||||
new_attribute = new_state.attributes.get(self.expose_attribute)
|
||||
old_state = event.data.get("old_state")
|
||||
|
||||
if old_state is not None:
|
||||
old_attribute = old_state.attributes.get(self.expose_attribute)
|
||||
if old_attribute == new_attribute:
|
||||
|
@ -4,14 +4,14 @@ import asyncio
|
||||
import logging
|
||||
from typing import Any, Awaitable, Dict, List, Optional
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, State, callback
|
||||
from homeassistant.core import CALLBACK_TYPE, Event, callback
|
||||
from homeassistant.helpers import entity
|
||||
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.event import async_track_state_change
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from .core.const import (
|
||||
@ -245,7 +245,7 @@ class ZhaGroupEntity(BaseZhaEntity):
|
||||
signal_override=True,
|
||||
)
|
||||
|
||||
self._async_unsub_state_changed = async_track_state_change(
|
||||
self._async_unsub_state_changed = async_track_state_change_event(
|
||||
self.hass, self._entity_ids, self.async_state_changed_listener
|
||||
)
|
||||
|
||||
@ -258,9 +258,7 @@ class ZhaGroupEntity(BaseZhaEntity):
|
||||
await self.async_update()
|
||||
|
||||
@callback
|
||||
def async_state_changed_listener(
|
||||
self, entity_id: str, old_state: State, new_state: State
|
||||
):
|
||||
def async_state_changed_listener(self, event: Event):
|
||||
"""Handle child updates."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user