Use config_entry.on_unload rather than local listener implementation in Axis (#49495)

pull/49500/head
Robert Svensson 2021-04-20 20:53:05 +02:00 committed by GitHub
parent 63616a9e36
commit 12a9695798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 10 deletions

View File

@ -26,7 +26,7 @@ async def async_setup_entry(hass, config_entry):
await device.async_update_device_registry()
device.listeners.append(
config_entry.async_on_unload(
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.shutdown)
)

View File

@ -53,7 +53,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
):
async_add_entities([AxisBinarySensor(event, device)])
device.listeners.append(
config_entry.async_on_unload(
async_dispatcher_connect(hass, device.signal_new_event, async_add_sensor)
)

View File

@ -58,8 +58,6 @@ class AxisNetworkDevice:
self.fw_version = None
self.product_type = None
self.listeners = []
@property
def host(self):
"""Return the host address of this device."""
@ -190,7 +188,7 @@ class AxisNetworkDevice:
status = {}
if status.get("data", {}).get("status", {}).get("state") == "active":
self.listeners.append(
self.config_entry.async_on_unload(
await mqtt.async_subscribe(
hass, f"{self.api.vapix.serial_number}/#", self.mqtt_message
)
@ -279,9 +277,6 @@ class AxisNetworkDevice:
if not unload_ok:
return False
for unsubscribe_listener in self.listeners:
unsubscribe_listener()
return True

View File

@ -32,7 +32,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
if event.CLASS == CLASS_LIGHT and event.TYPE == "Light":
async_add_entities([AxisLight(event, device)])
device.listeners.append(
config_entry.async_on_unload(
async_dispatcher_connect(hass, device.signal_new_event, async_add_sensor)
)

View File

@ -22,7 +22,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
if event.CLASS == CLASS_OUTPUT:
async_add_entities([AxisSwitch(event, device)])
device.listeners.append(
config_entry.async_on_unload(
async_dispatcher_connect(hass, device.signal_new_event, async_add_switch)
)