Allow for translating service examples (#97141)
parent
0c4e341189
commit
b655b9d530
|
@ -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"]
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue