Add async_has_entity_registry_updated_listeners (#142772)

This commit is contained in:
J. Nick Koston 2025-04-14 07:45:09 -10:00 committed by GitHub
parent 198a6b2e8f
commit 870350b961
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -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,

View File

@ -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}
)