Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1d7f341

Browse files
bdracoballoob
andauthoredJul 15, 2020
Switch async_track_state_change to the faster async_track_state_change_event part 7 (home-assistant#37870)
Co-authored-by: Paulus Schoutsen <[email protected]>
1 parent 44fefb3 commit 1d7f341

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed
 

‎homeassistant/components/alert/__init__.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ def __init__(
199199
self._send_done_message = False
200200
self.entity_id = f"{DOMAIN}.{entity_id}"
201201

202-
event.async_track_state_change(
203-
hass, watched_entity_id, self.watched_entity_change
202+
event.async_track_state_change_event(
203+
hass, [watched_entity_id], self.watched_entity_change
204204
)
205205

206206
@property
@@ -222,9 +222,12 @@ def state(self):
222222
return STATE_ON
223223
return STATE_IDLE
224224

225-
async def watched_entity_change(self, entity, from_state, to_state):
225+
async def watched_entity_change(self, ev):
226226
"""Determine if the alert should start or stop."""
227-
_LOGGER.debug("Watched entity (%s) has changed", entity)
227+
to_state = ev.data.get("new_state")
228+
if to_state is None:
229+
return
230+
_LOGGER.debug("Watched entity (%s) has changed", ev.data.get("entity_id"))
228231
if to_state.state == self._alert_state and not self._firing:
229232
await self.begin_alerting()
230233
if to_state.state != self._alert_state and self._firing:

‎homeassistant/components/knx/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from homeassistant.core import callback
2323
from homeassistant.helpers import discovery
2424
import homeassistant.helpers.config_validation as cv
25-
from homeassistant.helpers.event import async_track_state_change
25+
from homeassistant.helpers.event import async_track_state_change_event
2626
from homeassistant.helpers.script import Script
2727

2828
_LOGGER = logging.getLogger(__name__)
@@ -364,17 +364,22 @@ def async_register(self):
364364
self.xknx, name=_name, group_address=self.address, value_type=self.type,
365365
)
366366
self.xknx.devices.add(self.device)
367-
async_track_state_change(self.hass, self.entity_id, self._async_entity_changed)
367+
async_track_state_change_event(
368+
self.hass, [self.entity_id], self._async_entity_changed
369+
)
368370

369-
async def _async_entity_changed(self, entity_id, old_state, new_state):
371+
async def _async_entity_changed(self, event):
370372
"""Handle entity change."""
373+
new_state = event.data.get("new_state")
371374
if new_state is None:
372375
return
373376
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
374377
return
375378

376379
if self.expose_attribute is not None:
377380
new_attribute = new_state.attributes.get(self.expose_attribute)
381+
old_state = event.data.get("old_state")
382+
378383
if old_state is not None:
379384
old_attribute = old_state.attributes.get(self.expose_attribute)
380385
if old_attribute == new_attribute:

‎homeassistant/components/zha/entity.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import logging
55
from typing import Any, Awaitable, Dict, List, Optional
66

7-
from homeassistant.core import CALLBACK_TYPE, State, callback
7+
from homeassistant.core import CALLBACK_TYPE, Event, callback
88
from homeassistant.helpers import entity
99
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
1010
from homeassistant.helpers.dispatcher import (
1111
async_dispatcher_connect,
1212
async_dispatcher_send,
1313
)
14-
from homeassistant.helpers.event import async_track_state_change
14+
from homeassistant.helpers.event import async_track_state_change_event
1515
from homeassistant.helpers.restore_state import RestoreEntity
1616

1717
from .core.const import (
@@ -245,7 +245,7 @@ async def async_added_to_hass(self) -> None:
245245
signal_override=True,
246246
)
247247

248-
self._async_unsub_state_changed = async_track_state_change(
248+
self._async_unsub_state_changed = async_track_state_change_event(
249249
self.hass, self._entity_ids, self.async_state_changed_listener
250250
)
251251

@@ -258,9 +258,7 @@ def send_removed_signal():
258258
await self.async_update()
259259

260260
@callback
261-
def async_state_changed_listener(
262-
self, entity_id: str, old_state: State, new_state: State
263-
):
261+
def async_state_changed_listener(self, event: Event):
264262
"""Handle child updates."""
265263
self.async_schedule_update_ha_state(True)
266264

‎pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ persistent=no
88
extension-pkg-whitelist=ciso8601
99

1010
[BASIC]
11-
good-names=id,i,j,k,ex,Run,_,fp,T
11+
good-names=id,i,j,k,ex,Run,_,fp,T,ev
1212

1313
[MESSAGES CONTROL]
1414
# Reasons disabled:

0 commit comments

Comments
 (0)
Please sign in to comment.