mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Use config_entry.on_unload rather than local listener implementation in Axis (#49495)
This commit is contained in:
parent
63616a9e36
commit
12a9695798
@ -26,7 +26,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
|
|
||||||
await device.async_update_device_registry()
|
await device.async_update_device_registry()
|
||||||
|
|
||||||
device.listeners.append(
|
config_entry.async_on_unload(
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.shutdown)
|
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)])
|
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)
|
async_dispatcher_connect(hass, device.signal_new_event, async_add_sensor)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,8 +58,6 @@ class AxisNetworkDevice:
|
|||||||
self.fw_version = None
|
self.fw_version = None
|
||||||
self.product_type = None
|
self.product_type = None
|
||||||
|
|
||||||
self.listeners = []
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def host(self):
|
def host(self):
|
||||||
"""Return the host address of this device."""
|
"""Return the host address of this device."""
|
||||||
@ -190,7 +188,7 @@ class AxisNetworkDevice:
|
|||||||
status = {}
|
status = {}
|
||||||
|
|
||||||
if status.get("data", {}).get("status", {}).get("state") == "active":
|
if status.get("data", {}).get("status", {}).get("state") == "active":
|
||||||
self.listeners.append(
|
self.config_entry.async_on_unload(
|
||||||
await mqtt.async_subscribe(
|
await mqtt.async_subscribe(
|
||||||
hass, f"{self.api.vapix.serial_number}/#", self.mqtt_message
|
hass, f"{self.api.vapix.serial_number}/#", self.mqtt_message
|
||||||
)
|
)
|
||||||
@ -279,9 +277,6 @@ class AxisNetworkDevice:
|
|||||||
if not unload_ok:
|
if not unload_ok:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for unsubscribe_listener in self.listeners:
|
|
||||||
unsubscribe_listener()
|
|
||||||
|
|
||||||
return True
|
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":
|
if event.CLASS == CLASS_LIGHT and event.TYPE == "Light":
|
||||||
async_add_entities([AxisLight(event, device)])
|
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)
|
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:
|
if event.CLASS == CLASS_OUTPUT:
|
||||||
async_add_entities([AxisSwitch(event, device)])
|
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)
|
async_dispatcher_connect(hass, device.signal_new_event, async_add_switch)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user