diff --git a/homeassistant/components/dsmr/__init__.py b/homeassistant/components/dsmr/__init__.py index 3ebac7b42fc..0e238363fc0 100644 --- a/homeassistant/components/dsmr/__init__.py +++ b/homeassistant/components/dsmr/__init__.py @@ -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 diff --git a/homeassistant/components/dsmr/const.py b/homeassistant/components/dsmr/const.py index 5c75dcc61ca..b26caa5c865 100644 --- a/homeassistant/components/dsmr/const.py +++ b/homeassistant/components/dsmr/const.py @@ -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"