From 524a56aa31b2093cc261f3ae95d853526c7771f5 Mon Sep 17 00:00:00 2001 From: basbruss <68892092+basbruss@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:43:57 +0200 Subject: [PATCH 1/2] Update hacs.json --- hacs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hacs.json b/hacs.json index cb37b2b..24f7488 100644 --- a/hacs.json +++ b/hacs.json @@ -1,7 +1,7 @@ { "name": "Adaptive Cover", "filename": "adaptive_cover.zip", - "homeassistant": "2022.1.0", + "homeassistant": "2024.5.0b1", "render_readme": true, "zip_release": true } From 56ace9158553b53e51d86d7630ae9a567ca1d45d Mon Sep 17 00:00:00 2001 From: basbruss <68892092+basbruss@users.noreply.github.com> Date: Wed, 1 May 2024 13:17:27 +0200 Subject: [PATCH 2/2] change event listeners --- custom_components/adaptive_cover/__init__.py | 6 +++--- custom_components/adaptive_cover/coordinator.py | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/custom_components/adaptive_cover/__init__.py b/custom_components/adaptive_cover/__init__.py index ab1b6c2..8c6a21f 100644 --- a/custom_components/adaptive_cover/__init__.py +++ b/custom_components/adaptive_cover/__init__.py @@ -6,7 +6,7 @@ from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.event import ( - async_track_state_change, + async_track_state_change_event, ) from .const import ( @@ -48,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _entities.append(entity) entry.async_on_unload( - async_track_state_change( + async_track_state_change_event( hass, _entities, coordinator.async_check_entity_state_change, @@ -56,7 +56,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) entry.async_on_unload( - async_track_state_change( + async_track_state_change_event( hass, _cover_entities, coordinator.async_check_cover_state_change, diff --git a/custom_components/adaptive_cover/coordinator.py b/custom_components/adaptive_cover/coordinator.py index 4d71955..7edbea8 100644 --- a/custom_components/adaptive_cover/coordinator.py +++ b/custom_components/adaptive_cover/coordinator.py @@ -13,7 +13,7 @@ SERVICE_SET_COVER_POSITION, SERVICE_SET_COVER_TILT_POSITION, ) -from homeassistant.core import HomeAssistant, State +from homeassistant.core import Event, EventStateChangedData, HomeAssistant, State from homeassistant.helpers.template import state_attr from homeassistant.helpers.update_coordinator import DataUpdateCoordinator @@ -121,7 +121,7 @@ async def async_config_entry_first_refresh(self) -> None: _LOGGER.debug("Config entry first refresh") async def async_check_entity_state_change( - self, entity: str, old_state: State | None, new_state: State | None + self, event: Event[EventStateChangedData] ) -> None: """Fetch and process state change event.""" _LOGGER.debug("Entity state change") @@ -129,11 +129,14 @@ async def async_check_entity_state_change( await self.async_refresh() async def async_check_cover_state_change( - self, entity: str, old_state: State | None, new_state: State | None + self, event: Event[EventStateChangedData] ) -> None: """Fetch and process state change event.""" _LOGGER.debug("Cover state change") - self.state_change_data = StateChangedData(entity, old_state, new_state) + data = event.data + self.state_change_data = StateChangedData( + data["entity_id"], data["old_state"], data["new_state"] + ) self.cover_state_change = True self.process_entity_state_change() await self.async_refresh()