mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Allow translating select selector options (#85531)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
096ef5da47
commit
25392655e7
@ -137,6 +137,7 @@ BROKER_VERIFICATION_SELECTOR = SelectSelector(
|
||||
SelectSelectorConfig(
|
||||
options=CA_VERIFICATION_MODES,
|
||||
mode=SelectSelectorMode.DROPDOWN,
|
||||
translation_key=SET_CA_CERT,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -136,5 +136,14 @@
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_inclusion": "[%key:component::mqtt::config::error::invalid_inclusion%]"
|
||||
}
|
||||
},
|
||||
"selector": {
|
||||
"set_ca_cert": {
|
||||
"options": {
|
||||
"off": "Off",
|
||||
"auto": "Auto",
|
||||
"custom": "Custom"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,5 +136,14 @@
|
||||
"title": "MQTT options"
|
||||
}
|
||||
}
|
||||
},
|
||||
"selector": {
|
||||
"set_ca_cert": {
|
||||
"options": {
|
||||
"off": "Off",
|
||||
"auto": "Auto",
|
||||
"custom": "Custom"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -733,6 +733,7 @@ class SelectSelectorConfig(TypedDict, total=False):
|
||||
multiple: bool
|
||||
custom_value: bool
|
||||
mode: SelectSelectorMode
|
||||
translation_key: str
|
||||
|
||||
|
||||
@SELECTORS.register("select")
|
||||
@ -749,6 +750,7 @@ class SelectSelector(Selector[SelectSelectorConfig]):
|
||||
vol.Optional("mode"): vol.All(
|
||||
vol.Coerce(SelectSelectorMode), lambda val: val.value
|
||||
),
|
||||
vol.Optional("translation_key"): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -216,6 +216,14 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
|
||||
flow_title=UNDEFINED,
|
||||
require_step_title=False,
|
||||
),
|
||||
vol.Optional("selector"): cv.schema_with_slug_keys(
|
||||
{
|
||||
"options": cv.schema_with_slug_keys(
|
||||
cv.string_with_no_html, slug_validator=translation_key_validator
|
||||
)
|
||||
},
|
||||
slug_validator=vol.Any("_", cv.slug),
|
||||
),
|
||||
vol.Optional("device_automation"): {
|
||||
vol.Optional("action_type"): {str: cv.string_with_no_html},
|
||||
vol.Optional("condition_type"): {str: cv.string_with_no_html},
|
||||
|
@ -419,6 +419,25 @@ def test_text_selector_schema(schema, valid_selections, invalid_selections):
|
||||
("red", "green"),
|
||||
("cat", 0, None, ["red"]),
|
||||
),
|
||||
(
|
||||
{
|
||||
"options": ["red", "green", "blue"],
|
||||
"translation_key": "color",
|
||||
},
|
||||
("red", "green", "blue"),
|
||||
("cat", 0, None, ["red"]),
|
||||
),
|
||||
(
|
||||
{
|
||||
"options": [
|
||||
{"value": "red", "label": "Ruby Red"},
|
||||
{"value": "green", "label": "Emerald Green"},
|
||||
],
|
||||
"translation_key": "color",
|
||||
},
|
||||
("red", "green"),
|
||||
("cat", 0, None, ["red"]),
|
||||
),
|
||||
(
|
||||
{"options": ["red", "green", "blue"], "multiple": True},
|
||||
(["red"], ["green", "blue"], []),
|
||||
|
Loading…
x
Reference in New Issue
Block a user