1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Run registry cleanup listeners immediately (#113646)

This commit is contained in:
J. Nick Koston 2024-03-17 08:15:55 -10:00 committed by GitHub
parent 091199d24a
commit 93497dde8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 15 deletions

View File

@ -1191,6 +1191,7 @@ def async_setup_cleanup(hass: HomeAssistant, dev_reg: DeviceRegistry) -> None:
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
_async_entity_registry_changed,
event_filter=entity_registry_changed_filter,
run_immediately=True,
)
return
@ -1200,10 +1201,13 @@ def async_setup_cleanup(hass: HomeAssistant, dev_reg: DeviceRegistry) -> None:
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
_async_entity_registry_changed,
event_filter=entity_registry_changed_filter,
run_immediately=True,
)
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, run_immediately=True
)
@callback
def _on_homeassistant_stop(event: Event) -> None:

View File

@ -1476,7 +1476,9 @@ def _async_setup_cleanup(hass: HomeAssistant, registry: EntityRegistry) -> None:
"""Cancel cleanup."""
cancel()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _on_homeassistant_stop)
hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, _on_homeassistant_stop, run_immediately=True
)
@callback
@ -1502,6 +1504,7 @@ def _async_setup_entity_restore(hass: HomeAssistant, registry: EntityRegistry) -
EVENT_ENTITY_REGISTRY_UPDATED,
cleanup_restored_states,
event_filter=cleanup_restored_states_filter,
run_immediately=True,
)
if hass.is_running:

View File

@ -266,9 +266,8 @@ async def test_setup_entry_no_options(
domain_data_mock.async_release_event_notifier.assert_awaited_once()
dmr_device_mock.async_unsubscribe_services.assert_awaited_once()
assert dmr_device_mock.on_event is None
mock_state = hass.states.get(mock_entity_id)
assert mock_state is not None
assert mock_state.state == ha_const.STATE_UNAVAILABLE
# Entity should be removed by the cleanup
assert hass.states.get(mock_entity_id) is None
@pytest.mark.parametrize(
@ -345,9 +344,8 @@ async def test_setup_entry_with_options(
domain_data_mock.async_release_event_notifier.assert_awaited_once()
dmr_device_mock.async_unsubscribe_services.assert_awaited_once()
assert dmr_device_mock.on_event is None
mock_state = hass.states.get(mock_entity_id)
assert mock_state is not None
assert mock_state.state == ha_const.STATE_UNAVAILABLE
# Entity should be removed by the cleanup
assert hass.states.get(mock_entity_id) is None
async def test_setup_entry_mac_address(
@ -1384,10 +1382,8 @@ async def test_unavailable_device(
# Check event notifiers are not released
domain_data_mock.async_release_event_notifier.assert_not_called()
# Confirm the entity is still unavailable
mock_state = hass.states.get(mock_entity_id)
assert mock_state is not None
assert mock_state.state == ha_const.STATE_UNAVAILABLE
# Entity should be removed by the cleanup
assert hass.states.get(mock_entity_id) is None
@pytest.mark.parametrize(
@ -1477,9 +1473,8 @@ async def test_become_available(
domain_data_mock.async_release_event_notifier.assert_awaited_once()
dmr_device_mock.async_unsubscribe_services.assert_awaited_once()
assert dmr_device_mock.on_event is None
mock_state = hass.states.get(mock_entity_id)
assert mock_state is not None
assert mock_state.state == ha_const.STATE_UNAVAILABLE
# Entity should be removed by the cleanup
assert hass.states.get(mock_entity_id) is None
@pytest.mark.parametrize(