diff --git a/homeassistant/components/deconz/alarm_control_panel.py b/homeassistant/components/deconz/alarm_control_panel.py index 4592a8014fc..7a6ed19bcd6 100644 --- a/homeassistant/components/deconz/alarm_control_panel.py +++ b/homeassistant/components/deconz/alarm_control_panel.py @@ -62,7 +62,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities) -> None: if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_SENSOR), diff --git a/homeassistant/components/deconz/binary_sensor.py b/homeassistant/components/deconz/binary_sensor.py index 99f559eec3d..7bf05ee6edd 100644 --- a/homeassistant/components/deconz/binary_sensor.py +++ b/homeassistant/components/deconz/binary_sensor.py @@ -58,7 +58,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_SENSOR), async_add_sensor ) diff --git a/homeassistant/components/deconz/climate.py b/homeassistant/components/deconz/climate.py index 49f0cc4d149..1ef881e9c90 100644 --- a/homeassistant/components/deconz/climate.py +++ b/homeassistant/components/deconz/climate.py @@ -97,7 +97,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_SENSOR), async_add_climate ) diff --git a/homeassistant/components/deconz/cover.py b/homeassistant/components/deconz/cover.py index 301d1753591..68fb9527e87 100644 --- a/homeassistant/components/deconz/cover.py +++ b/homeassistant/components/deconz/cover.py @@ -43,7 +43,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_cover ) diff --git a/homeassistant/components/deconz/deconz_event.py b/homeassistant/components/deconz/deconz_event.py index da80e2e6bf2..11dbfa89c90 100644 --- a/homeassistant/components/deconz/deconz_event.py +++ b/homeassistant/components/deconz/deconz_event.py @@ -65,7 +65,7 @@ async def async_setup_events(gateway) -> None: gateway.hass.async_create_task(new_event.async_update_device_registry()) gateway.events.append(new_event) - gateway.listeners.append( + gateway.config_entry.async_on_unload( async_dispatcher_connect( gateway.hass, gateway.async_signal_new_device(NEW_SENSOR), async_add_sensor ) diff --git a/homeassistant/components/deconz/fan.py b/homeassistant/components/deconz/fan.py index aca92f893c7..dfb6802fd75 100644 --- a/homeassistant/components/deconz/fan.py +++ b/homeassistant/components/deconz/fan.py @@ -45,7 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities) -> None: if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_fan ) diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 93a0befa937..fa674727a80 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -53,7 +53,6 @@ class DeconzGateway: self.deconz_ids = {} self.entities = {} self.events = [] - self.listeners = [] @property def bridgeid(self) -> str: @@ -256,10 +255,6 @@ class DeconzGateway: self.config_entry, platform ) - for unsub_dispatcher in self.listeners: - unsub_dispatcher() - self.listeners = [] - async_unload_events(self) self.deconz_ids = {} diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index f7ae45781ac..838e7639fc7 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -61,7 +61,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_light ) @@ -87,7 +87,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_GROUP), async_add_group ) diff --git a/homeassistant/components/deconz/lock.py b/homeassistant/components/deconz/lock.py index 4b6da1e0b97..6daa6cd1537 100644 --- a/homeassistant/components/deconz/lock.py +++ b/homeassistant/components/deconz/lock.py @@ -26,7 +26,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_lock_from_light ) @@ -45,7 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_SENSOR), diff --git a/homeassistant/components/deconz/scene.py b/homeassistant/components/deconz/scene.py index 4fbc1bfe453..ecd363f121a 100644 --- a/homeassistant/components/deconz/scene.py +++ b/homeassistant/components/deconz/scene.py @@ -21,7 +21,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_SCENE), async_add_scene ) diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index 311dd9be82c..92686892d6a 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -117,7 +117,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_SENSOR), async_add_sensor ) diff --git a/homeassistant/components/deconz/switch.py b/homeassistant/components/deconz/switch.py index f497e06c7af..492872ecca0 100644 --- a/homeassistant/components/deconz/switch.py +++ b/homeassistant/components/deconz/switch.py @@ -37,7 +37,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entities: async_add_entities(entities) - gateway.listeners.append( + config_entry.async_on_unload( async_dispatcher_connect( hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_switch )