1414from homeassistant .core import HomeAssistant , ServiceCall , callback
1515from homeassistant .helpers .entity_platform import AddEntitiesCallback
1616from homeassistant .helpers .event import async_track_state_change
17+ from homeassistant .helpers .event import async_track_state_change_event
1718
1819from homeassistant .helpers .update_coordinator import (
1920 CoordinatorEntity ,
@@ -56,7 +57,11 @@ async def async_setup_entry(
5657 coordinator : DataUpdateCoordinator = hass .data [DOMAIN ][config_entry .entry_id ][
5758 COORDINATOR
5859 ]
59- async def state_change_listener (entity_id , old_state , new_state ):
60+ async def state_change_listener (event ):
61+ entity_id = event .data .get ("entity_id" )
62+ old_state = event .data .get ("old_state" )
63+ new_state = event .data .get ("new_state" )
64+
6065 if old_state and new_state and old_state != new_state :
6166 # Fire a custom event
6267 hass .bus .async_fire ("aliexpress_package_data_updated" , {
@@ -81,7 +86,7 @@ async def state_change_listener(entity_id, old_state, new_state):
8186
8287 if sensors :
8388 for sensor in sensors :
84- async_track_state_change (hass , f"sensor.{ sensor .name .lower ().replace (" " ,"_" )} " , state_change_listener )
89+ async_track_state_change_event (hass , f"sensor.{ sensor .name .lower ().replace (" " ,"_" )} " , state_change_listener )
8590
8691 async_add_entities (sensors , True ) # Add initial sensors
8792
0 commit comments