diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index b363bc21e86..baf1f144a3f 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -551,6 +551,12 @@ def async_track_entity_registry_updated_event( ) +@callback +def async_has_entity_registry_updated_listeners(hass: HomeAssistant) -> bool: + """Check if async_track_entity_registry_updated_event has been called yet.""" + return _KEYED_TRACK_ENTITY_REGISTRY_UPDATED.key in hass.data + + @callback def _async_device_registry_updated_filter( hass: HomeAssistant, diff --git a/tests/helpers/test_event.py b/tests/helpers/test_event.py index a8691771580..b8bc89e29d7 100644 --- a/tests/helpers/test_event.py +++ b/tests/helpers/test_event.py @@ -30,6 +30,7 @@ from homeassistant.helpers.event import ( TrackTemplate, TrackTemplateResult, async_call_later, + async_has_entity_registry_updated_listeners, async_track_device_registry_updated_event, async_track_entity_registry_updated_event, async_track_point_in_time, @@ -4682,12 +4683,17 @@ async def test_async_track_entity_registry_updated_event(hass: HomeAssistant) -> def run_callback(event): event_data.append(event.data) + assert async_has_entity_registry_updated_listeners(hass) is False + unsub1 = async_track_entity_registry_updated_event( hass, entity_id, run_callback, job_type=ha.HassJobType.Callback ) unsub2 = async_track_entity_registry_updated_event( hass, new_entity_id, run_callback ) + + assert async_has_entity_registry_updated_listeners(hass) is True + hass.bus.async_fire( EVENT_ENTITY_REGISTRY_UPDATED, {"action": "create", "entity_id": entity_id} )