def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
    'Expand out any groups into entity states.'
    search = list(args)
    found = {}
    while search:
        entity = search.pop()
        if isinstance(entity, str):
            entity_id = entity
            entity = _get_state(hass, entity)
            if (entity is None):
                continue
        elif isinstance(entity, State):
            entity_id = entity.entity_id
        elif isinstance(entity, collections.abc.Iterable):
            search += entity
            continue
        else:
            continue
        if entity_id.startswith(_GROUP_DOMAIN_PREFIX):
            group_entities = entity.attributes.get(ATTR_ENTITY_ID)
            if group_entities:
                search += group_entities
        else:
            _collect_state(hass, entity_id)
            found[entity_id] = entity
    return sorted(found.values(), key=(lambda a: a.entity_id))
Expand out any groups into entity states.
def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
    
    search = list(args)
    found = {}
    while search:
        entity = search.pop()
        if isinstance(entity, str):
            entity_id = entity
            entity = _get_state(hass, entity)
            if (entity is None):
                continue
        elif isinstance(entity, State):
            entity_id = entity.entity_id
        elif isinstance(entity, collections.abc.Iterable):
            search += entity
            continue
        else:
            continue
        if entity_id.startswith(_GROUP_DOMAIN_PREFIX):
            group_entities = entity.attributes.get(ATTR_ENTITY_ID)
            if group_entities:
                search += group_entities
        else:
            _collect_state(hass, entity_id)
            found[entity_id] = entity
    return sorted(found.values(), key=(lambda a: a.entity_id))