Use config_entry.on_unload rather than local listener implementation in Axis (#49495)
parent
63616a9e36
commit
12a9695798
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue