Skip to content

Commit

Permalink
fix: Removed tracked package must be removed
Browse files Browse the repository at this point in the history
Instead of just unregistered
  • Loading branch information
storm1er committed Oct 12, 2024
1 parent 61d30f4 commit 74abab5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/parcelsapp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
CONF_DESTINATION_COUNTRY = "destination_country"
DEFAULT_SCAN_INTERVAL = 900
SERVICE_TRACK_PACKAGE = "track_package"
SERVICE_REMOVE_PACKAGE = "remove_package" # Added new service constant
SERVICE_REMOVE_PACKAGE = "remove_package"
7 changes: 7 additions & 0 deletions custom_components/parcelsapp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers import entity_registry as er

from .const import DOMAIN
from .coordinator import ParcelsAppCoordinator
Expand Down Expand Up @@ -44,6 +45,12 @@ async def handle_remove_package(tracking_id: str):
await entity_to_remove.async_remove()
entities.remove(entity_to_remove)

# Remove entity from entity registry
entity_registry = er.async_get(hass)
entity_id = entity_to_remove.entity_id
if entity_registry.async_is_registered(entity_id):
entity_registry.async_remove(entity_id)

unsub_new_package = async_dispatcher_connect(
hass, f"{DOMAIN}_new_package", handle_new_package
)
Expand Down

0 comments on commit 74abab5

Please sign in to comment.