Update format

This commit is contained in:
Paul Bottein
2025-06-20 14:53:01 +02:00
parent 272837205c
commit d61cf0f805
2 changed files with 26 additions and 17 deletions

View File

@@ -1113,20 +1113,22 @@ class NumberSelector(Selector[NumberSelectorConfig]):
return value
class ObjectSchemaDict(TypedDict):
class ObjectSelectorField(TypedDict):
"""Class to represent a select option dict."""
name: str
label: str
required: bool
selector: dict[str, Any]
class ObjectSelectorConfig(BaseSelectorConfig):
"""Class to represent an object selector config."""
schema: list[ObjectSchemaDict]
fields: dict[str, ObjectSelectorField]
multiple: bool
label_key: str
description: bool
label_field: str
description_field: bool
translation_key: str
@SELECTORS.register("object")
@@ -1137,15 +1139,17 @@ class ObjectSelector(Selector[ObjectSelectorConfig]):
CONFIG_SCHEMA = BASE_SELECTOR_CONFIG_SCHEMA.extend(
{
vol.Optional("schema"): [
{
vol.Required("name"): str,
vol.Optional("fields"): {
str: {
vol.Required("selector"): dict,
vol.Optional("required"): bool,
vol.Optional("label"): str,
}
],
vol.Optional("label_key"): str,
vol.Optional("description_key"): str,
},
vol.Optional("multiple", default=False): bool,
vol.Optional("label_field"): str,
vol.Optional("description_field"): str,
vol.Optional("translation_key"): str,
}
)

View File

@@ -594,13 +594,18 @@ def test_action_selector_schema(schema, valid_selections, invalid_selections) ->
({}, ("abc123",), ()),
(
{
"schema": [
{"name": "name", "selector": {"text": {}}},
{"name": "percentage", "selector": {"number": {}}},
],
"fields": {
"name": {
"required": True,
"selector": {"text": {}},
},
"percentage": {
"selector": {"number": {}},
},
},
"multiple": True,
"label_key": "name",
"description_key": "percentage",
"label_field": "name",
"description_field": "percentage",
},
(),
(),