DSMR: Use entry unload to unsub update listener (#52220)
parent
75d29b3d9e
commit
3f49cdf9bf
|
@ -5,7 +5,7 @@ from contextlib import suppress
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DATA_LISTENER, DATA_TASK, DOMAIN, PLATFORMS
|
||||
from .const import DATA_TASK, DOMAIN, PLATFORMS
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
@ -14,9 +14,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
hass.data[DOMAIN][entry.entry_id] = {}
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
listener = entry.add_update_listener(async_update_options)
|
||||
hass.data[DOMAIN][entry.entry_id][DATA_LISTENER] = listener
|
||||
entry.async_on_unload(entry.add_update_listener(async_update_options))
|
||||
|
||||
return True
|
||||
|
||||
|
@ -24,7 +22,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."""
|
||||
task = hass.data[DOMAIN][entry.entry_id][DATA_TASK]
|
||||
listener = hass.data[DOMAIN][entry.entry_id][DATA_LISTENER]
|
||||
|
||||
# Cancel the reconnect task
|
||||
task.cancel()
|
||||
|
@ -33,8 +30,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
listener()
|
||||
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
|
|
@ -36,7 +36,6 @@ DEFAULT_PRECISION = 3
|
|||
DEFAULT_RECONNECT_INTERVAL = 30
|
||||
DEFAULT_TIME_BETWEEN_UPDATE = 30
|
||||
|
||||
DATA_LISTENER = "listener"
|
||||
DATA_TASK = "task"
|
||||
|
||||
DEVICE_NAME_ENERGY = "Energy Meter"
|
||||
|
|
Loading…
Reference in New Issue