1
0
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:
Erik Montnemery
2023-03-16 14:02:26 +01:00
committed by GitHub
parent c6568ffb62
commit 886c2635ad
2 changed files with 86 additions and 0 deletions

View File

@@ -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."""