mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Use entry.async_on_unload in monoprice (#148016)
This commit is contained in:
parent
d738c0d6b1
commit
5008151688
@ -10,13 +10,7 @@ from homeassistant.const import CONF_PORT, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import (
|
||||
CONF_NOT_FIRST_RUN,
|
||||
DOMAIN,
|
||||
FIRST_RUN,
|
||||
MONOPRICE_OBJECT,
|
||||
UNDO_UPDATE_LISTENER,
|
||||
)
|
||||
from .const import CONF_NOT_FIRST_RUN, DOMAIN, FIRST_RUN, MONOPRICE_OBJECT
|
||||
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||
|
||||
@ -41,11 +35,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
entry, data={**entry.data, CONF_NOT_FIRST_RUN: True}
|
||||
)
|
||||
|
||||
undo_listener = entry.add_update_listener(_update_listener)
|
||||
entry.async_on_unload(entry.add_update_listener(_update_listener))
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
|
||||
MONOPRICE_OBJECT: monoprice,
|
||||
UNDO_UPDATE_LISTENER: undo_listener,
|
||||
FIRST_RUN: first_run,
|
||||
}
|
||||
|
||||
@ -60,8 +53,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
if not unload_ok:
|
||||
return False
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||
|
||||
def _cleanup(monoprice) -> None:
|
||||
"""Destroy the Monoprice object.
|
||||
|
||||
|
@ -18,4 +18,3 @@ SERVICE_RESTORE = "restore"
|
||||
|
||||
FIRST_RUN = "first_run"
|
||||
MONOPRICE_OBJECT = "monoprice_object"
|
||||
UNDO_UPDATE_LISTENER = "update_update_listener"
|
||||
|
Loading…
x
Reference in New Issue
Block a user