Use entry.async_on_unload in gpslogger (#144883)

This commit is contained in:
epenet 2025-05-14 14:31:50 +02:00 committed by GitHub
parent 993e98a43f
commit a9238c7577
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 5 deletions

View File

@ -90,7 +90,7 @@ async def handle_webhook(
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Configure based on config entry."""
hass.data.setdefault(DOMAIN, {"devices": set(), "unsub_device_tracker": {}})
hass.data.setdefault(DOMAIN, {"devices": set()})
webhook.async_register(
hass, DOMAIN, "GPSLogger", entry.data[CONF_WEBHOOK_ID], handle_webhook
)
@ -103,7 +103,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
webhook.async_unregister(hass, entry.data[CONF_WEBHOOK_ID])
hass.data[DOMAIN]["unsub_device_tracker"].pop(entry.entry_id)()
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

View File

@ -42,9 +42,7 @@ async def async_setup_entry(
async_add_entities([GPSLoggerEntity(device, gps, battery, accuracy, attrs)])
hass.data[DOMAIN]["unsub_device_tracker"][entry.entry_id] = (
async_dispatcher_connect(hass, TRACKER_UPDATE, _receive_data)
)
entry.async_on_unload(async_dispatcher_connect(hass, TRACKER_UPDATE, _receive_data))
# Restore previously loaded devices
dev_reg = dr.async_get(hass)