1313from homeassistant .const import CONF_ENTITY_ID
1414from homeassistant .core import HomeAssistant , ServiceCall , callback
1515from homeassistant .helpers .entity_platform import AddEntitiesCallback
16- from homeassistant .helpers .event import async_track_state_change
16+ from homeassistant .helpers .event import async_track_state_change_event
1717
1818from homeassistant .helpers .update_coordinator import (
1919 CoordinatorEntity ,
@@ -56,7 +56,11 @@ async def async_setup_entry(
5656 coordinator : DataUpdateCoordinator = hass .data [DOMAIN ][config_entry .entry_id ][
5757 COORDINATOR
5858 ]
59- async def state_change_listener (entity_id , old_state , new_state ):
59+ async def state_change_listener (event ):
60+ entity_id = event .data .get ("entity_id" )
61+ old_state = event .data .get ("old_state" )
62+ new_state = event .data .get ("new_state" )
63+
6064 if old_state and new_state and old_state != new_state :
6165 # Fire a custom event
6266 hass .bus .async_fire ("aliexpress_package_data_updated" , {
@@ -81,7 +85,7 @@ async def state_change_listener(entity_id, old_state, new_state):
8185
8286 if sensors :
8387 for sensor in sensors :
84- async_track_state_change (hass , f"sensor.{ sensor .name .lower ().replace (" " ,"_" )} " , state_change_listener )
88+ async_track_state_change_event (hass , f"sensor.{ sensor .name .lower ().replace (" " ,"_" )} " , state_change_listener )
8589
8690 async_add_entities (sensors , True ) # Add initial sensors
8791
0 commit comments