Skip to content

Commit 0931994

Browse files
authored
Update to async_track_state_change_event
1 parent 3f533a7 commit 0931994

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • custom_components/aliexpress_package_tracker

custom_components/aliexpress_package_tracker/sensor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from homeassistant.core import HomeAssistant, ServiceCall, callback
1515
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1616
from homeassistant.helpers.event import async_track_state_change
17+
from homeassistant.helpers.event import async_track_state_change_event
1718

1819
from 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

Comments
 (0)