def _state_generator(hass: HomeAssistant, domain: (str | None)) -> Generator:
    'State generator for a domain or all states.'
    for state in sorted(hass.states.async_all(domain), key=attrgetter('entity_id')):
        (yield TemplateState(hass, state, collect=False))
State generator for a domain or all states.
def _state_generator(hass: HomeAssistant, domain: (str | None)) -> Generator:
    
    for state in sorted(hass.states.async_all(domain), key=attrgetter('entity_id')):
        (yield TemplateState(hass, state, collect=False))