mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Undo NUT update listener on config reload (#33986)
This commit is contained in:
parent
5b5a232695
commit
c8aa55439f
@ -29,6 +29,7 @@ from .const import (
|
||||
PYNUT_MODEL,
|
||||
PYNUT_NAME,
|
||||
PYNUT_UNIQUE_ID,
|
||||
UNDO_UPDATE_LISTENER,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -77,6 +78,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
|
||||
_LOGGER.debug("NUT Sensors Available: %s", status)
|
||||
|
||||
undo_listener = entry.add_update_listener(_async_update_listener)
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id] = {
|
||||
COORDINATOR: coordinator,
|
||||
PYNUT_DATA: data,
|
||||
@ -85,10 +88,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
PYNUT_MODEL: _model_from_status(status),
|
||||
PYNUT_FIRMWARE: _firmware_from_status(status),
|
||||
PYNUT_NAME: data.name,
|
||||
UNDO_UPDATE_LISTENER: undo_listener,
|
||||
}
|
||||
|
||||
entry.add_update_listener(_async_update_listener)
|
||||
|
||||
for component in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
||||
@ -171,6 +173,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
|
@ -10,6 +10,7 @@ DOMAIN = "nut"
|
||||
|
||||
PLATFORMS = ["sensor"]
|
||||
|
||||
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
||||
|
||||
DEFAULT_NAME = "NUT UPS"
|
||||
DEFAULT_HOST = "localhost"
|
||||
|
@ -57,7 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Import the platform into a config entry."""
|
||||
|
||||
hass.async_create_task(
|
||||
|
Loading…
x
Reference in New Issue
Block a user