Switch a few more async_track_state_change to the faster async_track_state_change_event (#37833)

async_track_state_change_event is faster than async_track_state_change
and since we do not care about the data being returned to the callback
this is a simple speedup
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-07-14 22:31:34 -07:00
1 parent b12566e265
commit 20d5d3c162
3 files changed
+10 -12

No files matched your search

+6 -8
View File
@@ -1,6 +1,6 @@
"""Light support for switch entities."""
import logging
from typing import Callable, Optional, Sequence, cast
from typing import Any, Callable, Optional, Sequence, cast
import voluptuous as vol
@@ -13,10 +13,10 @@ from homeassistant.const import (
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import CALLBACK_TYPE, State, callback
from homeassistant.core import CALLBACK_TYPE, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import (
ConfigType,
DiscoveryInfoType,
@@ -117,15 +117,13 @@ class LightSwitch(LightEntity):
"""Register callbacks."""
@callback
def async_state_changed_listener(
entity_id: str, old_state: State, new_state: State
) -> None:
def async_state_changed_listener(*_: Any) -> None:
"""Handle child updates."""
self.async_schedule_update_ha_state(True)
assert self.hass is not None
self._async_unsub_state_changed = async_track_state_change(
self.hass, self._switch_entity_id, async_state_changed_listener
self._async_unsub_state_changed = async_track_state_change_event(
self.hass, [self._switch_entity_id], async_state_changed_listener
)
async def async_will_remove_from_hass(self):