Repository: home-assistant/core
File: homeassistant/helpers/service.py (Python)

Code before:
            entity_device_classes=entity_device_classes,
            required_features=required_features,
        ),
        schema,
        supports_response,
        job_type=HassJobType.Coroutinefunction,
        description_placeholders=description_placeholders,
    )


@callback
def async_get_service_config_entry(
    hass: HomeAssistant, domain: str, entry_id: str
) -> ConfigEntry:
    """Get and validate a service config entry."""
    config_entry = hass.config_entries.async_get_entry(entry_id)
    if not config_entry:
        raise ServiceValidationError(
            translation_domain=HOMEASSISTANT_DOMAIN,
            translation_key="service_config_entry_not_found",
            translation_placeholders={
                "domain": domain,
                "entry_id": entry_id,
            },
        )
    if config_entry.domain != domain:
        raise ServiceValidationError(
            translation_domain=HOMEASSISTANT_DOMAIN,
            translation_key="service_config_entry_wrong_domain",
            translation_placeholders={
                "domain": domain,
                "entry_title": config_entry.title,
            },
        )
    if config_entry.state is not ConfigEntryState.LOADED:
        raise ServiceValidationError(
            translation_domain=HOMEASSISTANT_DOMAIN,
            translation_key="service_config_entry_not_loaded",
            translation_placeholders={
                "domain": domain,
                "entry_title": config_entry.title,
            },
        )
    return config_entry


Review comment (bug):
when do we expect this to happen? 
if its only due to a bug in the integration code, should we raise something other than ServiceValidationError?

Code after:
            entity_device_classes=entity_device_classes,
            required_features=required_features,
        ),
        schema,
        supports_response,
        job_type=HassJobType.Coroutinefunction,
        description_placeholders=description_placeholders,
    )


@callback
def async_get_config_entry(
    hass: HomeAssistant, domain: str, entry_id: str
) -> ConfigEntry:
    """Get and validate a service config entry."""
    config_entry = hass.config_entries.async_get_entry(entry_id)
    if not config_entry:
        raise ServiceValidationError(
            translation_domain=HOMEASSISTANT_DOMAIN,
            translation_key="service_config_entry_not_found",
            translation_placeholders={
                "domain": domain,
                "entry_id": entry_id,
            },
        )
    if config_entry.domain != domain:
        raise ServiceValidationError(
            translation_domain=HOMEASSISTANT_DOMAIN,
            translation_key="service_config_entry_wrong_domain",
            translation_placeholders={
                "domain": domain,
                "entry_title": config_entry.title,
            },
        )
    if config_entry.state is not ConfigEntryState.LOADED:
        raise ServiceValidationError(
            translation_domain=HOMEASSISTANT_DOMAIN,
            translation_key="service_config_entry_not_loaded",
            translation_placeholders={
                "domain": domain,
                "entry_title": config_entry.title,
            },
        )
    return config_entry