Skip to content

Commit c803871

Browse files
authored
Merge pull request #21 from shardshunt/shardshunt-patch-1
Replace depricated async_track_state_change with async_track_state_change_event
2 parents 3f533a7 + d6b7cd6 commit c803871

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • custom_components/aliexpress_package_tracker

custom_components/aliexpress_package_tracker/sensor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from homeassistant.const import CONF_ENTITY_ID
1414
from homeassistant.core import HomeAssistant, ServiceCall, callback
1515
from 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

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

Comments
 (0)