diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 5470a94896d..74823dea953 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -666,6 +666,10 @@ async def async_get_all_descriptions( f"component.{domain}.services.{service_name}.fields.{field_name}.description" ): field_schema["description"] = desc + if example := translations.get( + f"component.{domain}.services.{service_name}.fields.{field_name}.example" + ): + field_schema["example"] = example if "target" in yaml_description: description["target"] = yaml_description["target"] diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 597b8e1ae1f..1754c166ef7 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -334,6 +334,7 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema: { vol.Required("name"): str, vol.Required("description"): translation_value_validator, + vol.Optional("example"): translation_value_validator, }, slug_validator=translation_key_validator, ), diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index 7348e1bf3e2..56ee3f74140 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -573,6 +573,7 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None: f"{translation_key_prefix}.description": "Translated description", f"{translation_key_prefix}.fields.level.name": "Field name", f"{translation_key_prefix}.fields.level.description": "Field description", + f"{translation_key_prefix}.fields.level.example": "Field example", } with patch( @@ -599,6 +600,10 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None: ] == "Field description" ) + assert ( + descriptions[logger.DOMAIN]["set_default_level"]["fields"]["level"]["example"] + == "Field example" + ) hass.services.async_register(logger.DOMAIN, "new_service", lambda x: None, None) service.async_set_service_schema(