diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py index e4966a1a4ce..5a2c11dc481 100644 --- a/homeassistant/components/group/__init__.py +++ b/homeassistant/components/group/__init__.py @@ -32,7 +32,7 @@ from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity, async_generate_entity_id from homeassistant.helpers.entity_component import EntityComponent -from homeassistant.helpers.event import async_track_state_change +from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.typing import HomeAssistantType from homeassistant.loader import bind_hass @@ -499,7 +499,7 @@ class Group(Entity): This method must be run in the event loop. """ if self._async_unsub_state_changed is None: - self._async_unsub_state_changed = async_track_state_change( + self._async_unsub_state_changed = async_track_state_change_event( self.hass, self.tracking, self._async_state_changed_listener ) @@ -528,7 +528,7 @@ class Group(Entity): self._async_unsub_state_changed() self._async_unsub_state_changed = None - async def _async_state_changed_listener(self, entity_id, old_state, new_state): + async def _async_state_changed_listener(self, event): """Respond to a member state changing. This method must be run in the event loop. @@ -537,7 +537,7 @@ class Group(Entity): if self._async_unsub_state_changed is None: return - self._async_update_group_state(new_state) + self._async_update_group_state(event.data.get("new_state")) self.async_write_ha_state() @property diff --git a/homeassistant/components/group/cover.py b/homeassistant/components/group/cover.py index 427530dadb5..02de871cb7a 100644 --- a/homeassistant/components/group/cover.py +++ b/homeassistant/components/group/cover.py @@ -41,7 +41,7 @@ from homeassistant.const import ( ) from homeassistant.core import State, callback 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 # mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs # mypy: no-check-untyped-defs @@ -94,13 +94,15 @@ class CoverGroup(CoverEntity): KEY_POSITION: set(), } + @callback + def _update_supported_features_event(self, event): + self.update_supported_features( + event.data.get("entity_id"), event.data.get("new_state") + ) + @callback def update_supported_features( - self, - entity_id: str, - old_state: Optional[State], - new_state: Optional[State], - update_state: bool = True, + self, entity_id: str, new_state: Optional[State], update_state: bool = True, ) -> None: """Update dictionaries with supported features.""" if not new_state: @@ -147,11 +149,9 @@ class CoverGroup(CoverEntity): """Register listeners.""" for entity_id in self._entities: new_state = self.hass.states.get(entity_id) - self.update_supported_features( - entity_id, None, new_state, update_state=False - ) - async_track_state_change( - self.hass, self._entities, self.update_supported_features + self.update_supported_features(entity_id, new_state, update_state=False) + async_track_state_change_event( + self.hass, self._entities, self._update_supported_features_event ) await self.async_update() diff --git a/homeassistant/components/group/light.py b/homeassistant/components/group/light.py index 69329b96122..1b33a0a6e88 100644 --- a/homeassistant/components/group/light.py +++ b/homeassistant/components/group/light.py @@ -38,7 +38,7 @@ from homeassistant.const import ( ) from homeassistant.core import CALLBACK_TYPE, State, callback 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.typing import ConfigType, HomeAssistantType from homeassistant.util import color as color_util @@ -100,14 +100,12 @@ class LightGroup(light.LightEntity): """Register callbacks.""" @callback - def async_state_changed_listener( - entity_id: str, old_state: State, new_state: State - ): + def async_state_changed_listener(*_): """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._async_unsub_state_changed = async_track_state_change_event( self.hass, self._entity_ids, async_state_changed_listener ) await self.async_update()