mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add support for constant selector (#89573)
* Add support for constant selector * Adapt to frontend PR changes
This commit is contained in:
@@ -358,6 +358,38 @@ class ConfigEntrySelector(Selector[ConfigEntrySelectorConfig]):
|
||||
return config
|
||||
|
||||
|
||||
class ConstantSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent a constant selector config."""
|
||||
|
||||
label: str
|
||||
translation_key: str
|
||||
value: str | int | bool
|
||||
|
||||
|
||||
@SELECTORS.register("constant")
|
||||
class ConstantSelector(Selector[ConstantSelectorConfig]):
|
||||
"""Constant selector."""
|
||||
|
||||
selector_type = "constant"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional("label"): str,
|
||||
vol.Optional("translation_key"): cv.string,
|
||||
vol.Required("value"): vol.Any(str, int, bool),
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(self, config: ConstantSelectorConfig | None = None) -> None:
|
||||
"""Instantiate a selector."""
|
||||
super().__init__(config)
|
||||
|
||||
def __call__(self, data: Any) -> Any:
|
||||
"""Validate the passed selection."""
|
||||
vol.Schema(self.config["value"])(data)
|
||||
return self.config["value"]
|
||||
|
||||
|
||||
class DateSelectorConfig(TypedDict):
|
||||
"""Class to represent a date selector config."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user