Skip to content

Commit

Permalink
Undo NUT update listener on config reload (#33986)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Apr 10, 2020
1 parent 5b5a232 commit c8aa554
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions homeassistant/components/nut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
PYNUT_MODEL,
PYNUT_NAME,
PYNUT_UNIQUE_ID,
UNDO_UPDATE_LISTENER,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -77,6 +78,8 @@ async def async_update_data():

_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,
Expand All @@ -85,10 +88,9 @@ async def async_update_data():
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)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/nut/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

PLATFORMS = ["sensor"]

UNDO_UPDATE_LISTENER = "undo_update_listener"

DEFAULT_NAME = "NUT UPS"
DEFAULT_HOST = "localhost"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/nut/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
)


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(
Expand Down

0 comments on commit c8aa554

Please sign in to comment.