Creating group in setup_platform

Hi All,
I am trying to put together my first integration. I am creating several entities in setup_platfrom and I want to show them grouped on a card. So after calling the add_entities function I create the group and trying to fetch the entities but they are still not available in hass[‘data’].entities (I guess because add_entities has not been finished yet). If I insert an explicit wait (4s) then it works fine, but I think it is not the best way. Can you please help me how to resolve this issue? Is there a callback function called after the platform has been set up or something else?
Thanks for your help,
Gabor

managed to find a solution with async_when_setup function which is called when a component finished set up.
so in setup_platform:

        ....
        add_entities(routes_in_stop, True)
        if config[CONF_SHOW_GROUPED]:
            async_when_setup(hass=hass, component="sensor", when_setup_cb=async_create_group)

and the async_create_group:

async def async_create_group(hass, component):
    entities = []
    name = ""
    for it in hass.data['sensor'].entities:
        if it.platform.platform_name == DOMAIN:
            if isinstance(it, BkkDataUpdater):
                name = it._data['references']['stops'][it.stop_id]['name']
            entities.append(it.entity_id)
    _LOGGER.debug(f"Entities to be grouped: {entities}")
    await group.Group.async_create_group(hass, name, entities)