1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add qr code selector (#109214)

This commit is contained in:
Bram Kragten
2024-01-31 19:27:03 +01:00
committed by GitHub
parent bbdb9b61c4
commit d361d47516
2 changed files with 72 additions and 0 deletions

View File

@@ -565,6 +565,49 @@ class ConstantSelector(Selector[ConstantSelectorConfig]):
return self.config["value"]
class QrErrorCorrectionLevel(StrEnum):
"""Possible error correction levels for QR code selector."""
LOW = "low"
MEDIUM = "medium"
QUARTILE = "quartile"
HIGH = "high"
class QrCodeSelectorConfig(TypedDict, total=False):
"""Class to represent a QR code selector config."""
data: str
scale: int
error_correction_level: QrErrorCorrectionLevel
@SELECTORS.register("qr_code")
class QrCodeSelector(Selector[QrCodeSelectorConfig]):
"""QR code selector."""
selector_type = "qr_code"
CONFIG_SCHEMA = vol.Schema(
{
vol.Required("data"): str,
vol.Optional("scale"): int,
vol.Optional("error_correction_level"): vol.All(
vol.Coerce(QrErrorCorrectionLevel), lambda val: val.value
),
}
)
def __init__(self, config: QrCodeSelectorConfig | None = None) -> None:
"""Instantiate a selector."""
super().__init__(config)
def __call__(self, data: Any) -> Any:
"""Validate the passed selection."""
vol.Schema(vol.Any(str, None))(data)
return self.config["data"]
class ConversationAgentSelectorConfig(TypedDict, total=False):
"""Class to represent a conversation agent selector config."""