mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Support translating number selector UoM (#148162)
This commit is contained in:
parent
bb1e263149
commit
0b2db2510f
@ -94,6 +94,7 @@ async def _get_options_dict(handler: SchemaCommonFlowHandler | None) -> dict:
|
||||
max=6,
|
||||
mode=selector.NumberSelectorMode.BOX,
|
||||
unit_of_measurement="decimals",
|
||||
translation_key="round",
|
||||
),
|
||||
),
|
||||
vol.Required(CONF_TIME_WINDOW): selector.DurationSelector(),
|
||||
|
@ -52,6 +52,11 @@
|
||||
"h": "Hours",
|
||||
"d": "Days"
|
||||
}
|
||||
},
|
||||
"round": {
|
||||
"unit_of_measurement": {
|
||||
"decimals": "decimals"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1066,6 +1066,7 @@ class NumberSelectorConfig(BaseSelectorConfig, total=False):
|
||||
step: float | Literal["any"]
|
||||
unit_of_measurement: str
|
||||
mode: NumberSelectorMode
|
||||
translation_key: str
|
||||
|
||||
|
||||
class NumberSelectorMode(StrEnum):
|
||||
@ -1106,6 +1107,7 @@ class NumberSelector(Selector[NumberSelectorConfig]):
|
||||
vol.Optional(CONF_MODE, default=NumberSelectorMode.SLIDER): vol.All(
|
||||
vol.Coerce(NumberSelectorMode), lambda val: val.value
|
||||
),
|
||||
vol.Optional("translation_key"): str,
|
||||
}
|
||||
),
|
||||
validate_slider,
|
||||
|
@ -310,6 +310,10 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
|
||||
translation_value_validator,
|
||||
slug_validator=translation_key_validator,
|
||||
),
|
||||
vol.Optional("unit_of_measurement"): cv.schema_with_slug_keys(
|
||||
translation_value_validator,
|
||||
slug_validator=translation_key_validator,
|
||||
),
|
||||
vol.Optional("fields"): cv.schema_with_slug_keys(str),
|
||||
},
|
||||
slug_validator=vol.Any("_", cv.slug),
|
||||
|
@ -396,7 +396,13 @@ def test_assist_pipeline_selector_schema(
|
||||
({"min": -100, "max": 100, "step": 5}, (), ()),
|
||||
({"min": -20, "max": -10, "mode": "box"}, (), ()),
|
||||
(
|
||||
{"min": 0, "max": 100, "unit_of_measurement": "seconds", "mode": "slider"},
|
||||
{
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"unit_of_measurement": "seconds",
|
||||
"mode": "slider",
|
||||
"translation_key": "foo",
|
||||
},
|
||||
(),
|
||||
(),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user