Use config_entry.on_unload rather than local listener implementation in UniFi (#49496)

This commit is contained in:
Robert Svensson 2021-04-20 20:50:42 +02:00 committed by GitHub
parent 138226fa14
commit 63616a9e36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 11 deletions

View file

@ -101,7 +101,6 @@ class UniFiController:
self.progress = None
self.wireless_clients = None
self.listeners = []
self.site_id: str = ""
self._site_name = None
self._site_role = None
@ -466,10 +465,6 @@ class UniFiController:
if not unload_ok:
return False
for unsub_dispatcher in self.listeners:
unsub_dispatcher()
self.listeners = []
if self._cancel_heartbeat_check:
self._cancel_heartbeat_check()
self._cancel_heartbeat_check = None

View file

@ -85,7 +85,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
add_device_entities(controller, async_add_entities, devices)
for signal in (controller.signal_update, controller.signal_options_update):
controller.listeners.append(async_dispatcher_connect(hass, signal, items_added))
config_entry.async_on_unload(
async_dispatcher_connect(hass, signal, items_added)
)
items_added()

View file

@ -41,7 +41,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
add_uptime_entities(controller, async_add_entities, clients)
for signal in (controller.signal_update, controller.signal_options_update):
controller.listeners.append(async_dispatcher_connect(hass, signal, items_added))
config_entry.async_on_unload(
async_dispatcher_connect(hass, signal, items_added)
)
items_added()

View file

@ -86,7 +86,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
add_dpi_entities(controller, async_add_entities, dpi_groups)
for signal in (controller.signal_update, controller.signal_options_update):
controller.listeners.append(async_dispatcher_connect(hass, signal, items_added))
config_entry.async_on_unload(
async_dispatcher_connect(hass, signal, items_added)
)
items_added()
known_poe_clients.clear()

View file

@ -313,13 +313,10 @@ async def test_reset_after_successful_setup(hass, aioclient_mock):
config_entry = await setup_unifi_integration(hass, aioclient_mock)
controller = hass.data[UNIFI_DOMAIN][config_entry.entry_id]
assert len(controller.listeners) == 6
result = await controller.async_reset()
await hass.async_block_till_done()
assert result is True
assert len(controller.listeners) == 0
async def test_reset_fails(hass, aioclient_mock):