Allow translating select selector options (#85531)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
096ef5da47
commit
25392655e7
6 changed files with 48 additions and 0 deletions
|
@ -137,6 +137,7 @@ BROKER_VERIFICATION_SELECTOR = SelectSelector(
|
||||||
SelectSelectorConfig(
|
SelectSelectorConfig(
|
||||||
options=CA_VERIFICATION_MODES,
|
options=CA_VERIFICATION_MODES,
|
||||||
mode=SelectSelectorMode.DROPDOWN,
|
mode=SelectSelectorMode.DROPDOWN,
|
||||||
|
translation_key=SET_CA_CERT,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -136,5 +136,14 @@
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
"invalid_inclusion": "[%key:component::mqtt::config::error::invalid_inclusion%]"
|
"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"
|
"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
|
multiple: bool
|
||||||
custom_value: bool
|
custom_value: bool
|
||||||
mode: SelectSelectorMode
|
mode: SelectSelectorMode
|
||||||
|
translation_key: str
|
||||||
|
|
||||||
|
|
||||||
@SELECTORS.register("select")
|
@SELECTORS.register("select")
|
||||||
|
@ -749,6 +750,7 @@ class SelectSelector(Selector[SelectSelectorConfig]):
|
||||||
vol.Optional("mode"): vol.All(
|
vol.Optional("mode"): vol.All(
|
||||||
vol.Coerce(SelectSelectorMode), lambda val: val.value
|
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,
|
flow_title=UNDEFINED,
|
||||||
require_step_title=False,
|
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("device_automation"): {
|
||||||
vol.Optional("action_type"): {str: cv.string_with_no_html},
|
vol.Optional("action_type"): {str: cv.string_with_no_html},
|
||||||
vol.Optional("condition_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"),
|
("red", "green"),
|
||||||
("cat", 0, None, ["red"]),
|
("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},
|
{"options": ["red", "green", "blue"], "multiple": True},
|
||||||
(["red"], ["green", "blue"], []),
|
(["red"], ["green", "blue"], []),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue