Add support for common references in strings.json (#118783)

* Add support for common references in strings.json

* Update tests
This commit is contained in:
Erik Montnemery 2024-06-07 20:59:26 +02:00 committed by GitHub
parent b2a54c50e2
commit 6c15351c18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 107 additions and 70 deletions

View File

@ -1,5 +1,41 @@
{ {
"title": "Light", "title": "Light",
"common": {
"field_brightness_description": "Number indicating brightness, where 0 turns the light off, 1 is the minimum brightness, and 255 is the maximum brightness.",
"field_brightness_name": "Brightness value",
"field_brightness_pct_description": "Number indicating the percentage of full brightness, where 0 turns the light off, 1 is the minimum brightness, and 100 is the maximum brightness.",
"field_brightness_pct_name": "Brightness",
"field_brightness_step_description": "Change brightness by an amount.",
"field_brightness_step_name": "Brightness step value",
"field_brightness_step_pct_description": "Change brightness by a percentage.",
"field_brightness_step_pct_name": "Brightness step",
"field_color_name_description": "A human-readable color name.",
"field_color_name_name": "Color name",
"field_color_temp_description": "Color temperature in mireds.",
"field_color_temp_name": "Color temperature",
"field_effect_description": "Light effect.",
"field_effect_name": "Effect",
"field_flash_description": "Tell light to flash, can be either value short or long.",
"field_flash_name": "Flash",
"field_hs_color_description": "Color in hue/sat format. A list of two integers. Hue is 0-360 and Sat is 0-100.",
"field_hs_color_name": "Hue/Sat color",
"field_kelvin_description": "Color temperature in Kelvin.",
"field_kelvin_name": "Color temperature",
"field_profile_description": "Name of a light profile to use.",
"field_profile_name": "Profile",
"field_rgb_color_description": "The color in RGB format. A list of three integers between 0 and 255 representing the values of red, green, and blue.",
"field_rgb_color_name": "Color",
"field_rgbw_color_description": "The color in RGBW format. A list of four integers between 0 and 255 representing the values of red, green, blue, and white.",
"field_rgbw_color_name": "RGBW-color",
"field_rgbww_color_description": "The color in RGBWW format. A list of five integers between 0 and 255 representing the values of red, green, blue, cold white, and warm white.",
"field_rgbww_color_name": "RGBWW-color",
"field_transition_description": "Duration it takes to get to next state.",
"field_transition_name": "Transition",
"field_white_description": "Set the light to white mode.",
"field_white_name": "White",
"field_xy_color_description": "Color in XY-format. A list of two decimal numbers between 0 and 1.",
"field_xy_color_name": "XY-color"
},
"device_automation": { "device_automation": {
"action_type": { "action_type": {
"brightness_decrease": "Decrease {entity_name} brightness", "brightness_decrease": "Decrease {entity_name} brightness",
@ -247,72 +283,72 @@
"description": "Turn on one or more lights and adjust properties of the light, even when they are turned on already.", "description": "Turn on one or more lights and adjust properties of the light, even when they are turned on already.",
"fields": { "fields": {
"transition": { "transition": {
"name": "Transition", "name": "[%key:component::light::common::field_transition_name%]",
"description": "Duration it takes to get to next state." "description": "[%key:component::light::common::field_transition_description%]"
}, },
"rgb_color": { "rgb_color": {
"name": "Color", "name": "[%key:component::light::common::field_rgb_color_name%]",
"description": "The color in RGB format. A list of three integers between 0 and 255 representing the values of red, green, and blue." "description": "[%key:component::light::common::field_rgb_color_description%]"
}, },
"rgbw_color": { "rgbw_color": {
"name": "RGBW-color", "name": "[%key:component::light::common::field_rgbw_color_name%]",
"description": "The color in RGBW format. A list of four integers between 0 and 255 representing the values of red, green, blue, and white." "description": "[%key:component::light::common::field_rgbw_color_description%]"
}, },
"rgbww_color": { "rgbww_color": {
"name": "RGBWW-color", "name": "[%key:component::light::common::field_rgbww_color_name%]",
"description": "The color in RGBWW format. A list of five integers between 0 and 255 representing the values of red, green, blue, cold white, and warm white." "description": "[%key:component::light::common::field_rgbww_color_description%]"
}, },
"color_name": { "color_name": {
"name": "Color name", "name": "[%key:component::light::common::field_color_name_name%]",
"description": "A human-readable color name." "description": "[%key:component::light::common::field_color_name_description%]"
}, },
"hs_color": { "hs_color": {
"name": "Hue/Sat color", "name": "[%key:component::light::common::field_hs_color_name%]",
"description": "Color in hue/sat format. A list of two integers. Hue is 0-360 and Sat is 0-100." "description": "[%key:component::light::common::field_hs_color_description%]"
}, },
"xy_color": { "xy_color": {
"name": "XY-color", "name": "[%key:component::light::common::field_xy_color_name%]",
"description": "Color in XY-format. A list of two decimal numbers between 0 and 1." "description": "[%key:component::light::common::field_xy_color_description%]"
}, },
"color_temp": { "color_temp": {
"name": "Color temperature", "name": "[%key:component::light::common::field_color_temp_name%]",
"description": "Color temperature in mireds." "description": "[%key:component::light::common::field_color_temp_description%]"
}, },
"kelvin": { "kelvin": {
"name": "Color temperature", "name": "[%key:component::light::common::field_kelvin_name%]",
"description": "Color temperature in Kelvin." "description": "[%key:component::light::common::field_kelvin_description%]"
}, },
"brightness": { "brightness": {
"name": "Brightness value", "name": "[%key:component::light::common::field_brightness_name%]",
"description": "Number indicating brightness, where 0 turns the light off, 1 is the minimum brightness, and 255 is the maximum brightness." "description": "[%key:component::light::common::field_brightness_description%]"
}, },
"brightness_pct": { "brightness_pct": {
"name": "Brightness", "name": "[%key:component::light::common::field_brightness_pct_name%]",
"description": "Number indicating the percentage of full brightness, where 0 turns the light off, 1 is the minimum brightness, and 100 is the maximum brightness." "description": "[%key:component::light::common::field_brightness_pct_description%]"
}, },
"brightness_step": { "brightness_step": {
"name": "Brightness step value", "name": "[%key:component::light::common::field_brightness_step_name%]",
"description": "Change brightness by an amount." "description": "[%key:component::light::common::field_brightness_step_description%]"
}, },
"brightness_step_pct": { "brightness_step_pct": {
"name": "Brightness step", "name": "[%key:component::light::common::field_brightness_step_pct_name%]",
"description": "Change brightness by a percentage." "description": "[%key:component::light::common::field_brightness_step_pct_description%]"
}, },
"white": { "white": {
"name": "White", "name": "[%key:component::light::common::field_white_name%]",
"description": "Set the light to white mode." "description": "[%key:component::light::common::field_white_description%]"
}, },
"profile": { "profile": {
"name": "Profile", "name": "[%key:component::light::common::field_profile_name%]",
"description": "Name of a light profile to use." "description": "[%key:component::light::common::field_profile_description%]"
}, },
"flash": { "flash": {
"name": "Flash", "name": "[%key:component::light::common::field_flash_name%]",
"description": "Tell light to flash, can be either value short or long." "description": "[%key:component::light::common::field_flash_description%]"
}, },
"effect": { "effect": {
"name": "Effect", "name": "[%key:component::light::common::field_effect_name%]",
"description": "Light effect." "description": "[%key:component::light::common::field_effect_description%]"
} }
} }
}, },
@ -321,12 +357,12 @@
"description": "Turn off one or more lights.", "description": "Turn off one or more lights.",
"fields": { "fields": {
"transition": { "transition": {
"name": "[%key:component::light::services::turn_on::fields::transition::name%]", "name": "[%key:component::light::common::field_transition_name%]",
"description": "[%key:component::light::services::turn_on::fields::transition::description%]" "description": "[%key:component::light::common::field_transition_description%]"
}, },
"flash": { "flash": {
"name": "[%key:component::light::services::turn_on::fields::flash::name%]", "name": "[%key:component::light::common::field_flash_name%]",
"description": "[%key:component::light::services::turn_on::fields::flash::description%]" "description": "[%key:component::light::common::field_flash_description%]"
} }
} }
}, },
@ -335,64 +371,64 @@
"description": "Toggles one or more lights, from on to off, or, off to on, based on their current state.", "description": "Toggles one or more lights, from on to off, or, off to on, based on their current state.",
"fields": { "fields": {
"transition": { "transition": {
"name": "[%key:component::light::services::turn_on::fields::transition::name%]", "name": "[%key:component::light::common::field_transition_name%]",
"description": "[%key:component::light::services::turn_on::fields::transition::description%]" "description": "[%key:component::light::common::field_transition_description%]"
}, },
"rgb_color": { "rgb_color": {
"name": "[%key:component::light::services::turn_on::fields::rgb_color::name%]", "name": "[%key:component::light::common::field_rgb_color_name%]",
"description": "[%key:component::light::services::turn_on::fields::rgb_color::description%]" "description": "[%key:component::light::common::field_rgb_color_description%]"
}, },
"rgbw_color": { "rgbw_color": {
"name": "[%key:component::light::services::turn_on::fields::rgbw_color::name%]", "name": "[%key:component::light::common::field_rgbw_color_name%]",
"description": "[%key:component::light::services::turn_on::fields::rgbw_color::description%]" "description": "[%key:component::light::common::field_rgbw_color_description%]"
}, },
"rgbww_color": { "rgbww_color": {
"name": "[%key:component::light::services::turn_on::fields::rgbww_color::name%]", "name": "[%key:component::light::common::field_rgbww_color_name%]",
"description": "[%key:component::light::services::turn_on::fields::rgbww_color::description%]" "description": "[%key:component::light::common::field_rgbww_color_description%]"
}, },
"color_name": { "color_name": {
"name": "[%key:component::light::services::turn_on::fields::color_name::name%]", "name": "[%key:component::light::common::field_color_name_name%]",
"description": "[%key:component::light::services::turn_on::fields::color_name::description%]" "description": "[%key:component::light::common::field_color_name_description%]"
}, },
"hs_color": { "hs_color": {
"name": "[%key:component::light::services::turn_on::fields::hs_color::name%]", "name": "[%key:component::light::common::field_hs_color_name%]",
"description": "[%key:component::light::services::turn_on::fields::hs_color::description%]" "description": "[%key:component::light::common::field_hs_color_description%]"
}, },
"xy_color": { "xy_color": {
"name": "[%key:component::light::services::turn_on::fields::xy_color::name%]", "name": "[%key:component::light::common::field_xy_color_name%]",
"description": "[%key:component::light::services::turn_on::fields::xy_color::description%]" "description": "[%key:component::light::common::field_xy_color_description%]"
}, },
"color_temp": { "color_temp": {
"name": "[%key:component::light::services::turn_on::fields::color_temp::name%]", "name": "[%key:component::light::common::field_color_temp_name%]",
"description": "[%key:component::light::services::turn_on::fields::color_temp::description%]" "description": "[%key:component::light::common::field_color_temp_description%]"
}, },
"kelvin": { "kelvin": {
"name": "[%key:component::light::services::turn_on::fields::kelvin::name%]", "name": "[%key:component::light::common::field_kelvin_name%]",
"description": "[%key:component::light::services::turn_on::fields::kelvin::description%]" "description": "[%key:component::light::common::field_kelvin_description%]"
}, },
"brightness": { "brightness": {
"name": "[%key:component::light::services::turn_on::fields::brightness::name%]", "name": "[%key:component::light::common::field_brightness_name%]",
"description": "[%key:component::light::services::turn_on::fields::brightness::description%]" "description": "[%key:component::light::common::field_brightness_description%]"
}, },
"brightness_pct": { "brightness_pct": {
"name": "[%key:component::light::services::turn_on::fields::brightness_pct::name%]", "name": "[%key:component::light::common::field_brightness_pct_name%]",
"description": "[%key:component::light::services::turn_on::fields::brightness_pct::description%]" "description": "[%key:component::light::common::field_brightness_pct_description%]"
}, },
"white": { "white": {
"name": "[%key:component::light::services::turn_on::fields::white::name%]", "name": "[%key:component::light::common::field_white_name%]",
"description": "[%key:component::light::services::turn_on::fields::white::description%]" "description": "[%key:component::light::common::field_white_description%]"
}, },
"profile": { "profile": {
"name": "[%key:component::light::services::turn_on::fields::profile::name%]", "name": "[%key:component::light::common::field_profile_name%]",
"description": "[%key:component::light::services::turn_on::fields::profile::description%]" "description": "[%key:component::light::common::field_profile_description%]"
}, },
"flash": { "flash": {
"name": "[%key:component::light::services::turn_on::fields::flash::name%]", "name": "[%key:component::light::common::field_flash_name%]",
"description": "[%key:component::light::services::turn_on::fields::flash::description%]" "description": "[%key:component::light::common::field_flash_description%]"
}, },
"effect": { "effect": {
"name": "[%key:component::light::services::turn_on::fields::effect::name%]", "name": "[%key:component::light::common::field_effect_name%]",
"description": "[%key:component::light::services::turn_on::fields::effect::description%]" "description": "[%key:component::light::common::field_effect_description%]"
} }
} }
} }

View File

@ -375,6 +375,7 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
vol.Required("done"): translation_value_validator, vol.Required("done"): translation_value_validator,
}, },
}, },
vol.Optional("common"): vol.Schema({cv.slug: translation_value_validator}),
} }
) )

View File

@ -426,10 +426,10 @@ async def test_caching(hass: HomeAssistant) -> None:
side_effect=translation.build_resources, side_effect=translation.build_resources,
) as mock_build_resources: ) as mock_build_resources:
load1 = await translation.async_get_translations(hass, "en", "entity_component") load1 = await translation.async_get_translations(hass, "en", "entity_component")
assert len(mock_build_resources.mock_calls) == 5 assert len(mock_build_resources.mock_calls) == 6
load2 = await translation.async_get_translations(hass, "en", "entity_component") load2 = await translation.async_get_translations(hass, "en", "entity_component")
assert len(mock_build_resources.mock_calls) == 5 assert len(mock_build_resources.mock_calls) == 6
assert load1 == load2 assert load1 == load2