mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Reduce duplicate code in the device registry (#115677)
This commit is contained in:
parent
45f025480e
commit
bd2efffb4a
@ -1235,21 +1235,21 @@ def async_setup_cleanup(hass: HomeAssistant, dev_reg: DeviceRegistry) -> None:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if hass.is_running:
|
def _async_listen_for_cleanup() -> None:
|
||||||
|
"""Listen for entity registry changes."""
|
||||||
hass.bus.async_listen(
|
hass.bus.async_listen(
|
||||||
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
||||||
_async_entity_registry_changed,
|
_async_entity_registry_changed,
|
||||||
event_filter=entity_registry_changed_filter,
|
event_filter=entity_registry_changed_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if hass.is_running:
|
||||||
|
_async_listen_for_cleanup()
|
||||||
return
|
return
|
||||||
|
|
||||||
async def startup_clean(event: Event) -> None:
|
async def startup_clean(event: Event) -> None:
|
||||||
"""Clean up on startup."""
|
"""Clean up on startup."""
|
||||||
hass.bus.async_listen(
|
_async_listen_for_cleanup()
|
||||||
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
|
|
||||||
_async_entity_registry_changed,
|
|
||||||
event_filter=entity_registry_changed_filter,
|
|
||||||
)
|
|
||||||
await debounced_cleanup.async_call()
|
await debounced_cleanup.async_call()
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, startup_clean)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, startup_clean)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user