mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Change multiple and default to inclusive with no defaults
This commit is contained in:
parent
c7741a0885
commit
885749cd91
@ -918,8 +918,8 @@ class section:
|
|||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional("collapsed", default=False): bool,
|
vol.Optional("collapsed", default=False): bool,
|
||||||
vol.Optional("multiple", default=False): bool,
|
vol.Inclusive("multiple", "multiple"): bool,
|
||||||
vol.Optional("default", default=[]): list[Any],
|
vol.Inclusive("default", "multiple"): list[Any],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1145,8 +1145,8 @@ def _custom_serializer(schema: Any, *, allow_section: bool) -> Any:
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
"expanded": not schema.options["collapsed"],
|
"expanded": not schema.options["collapsed"],
|
||||||
"multiple": schema.options["multiple"],
|
"multiple": schema.options.get("multiple"),
|
||||||
"default": schema.options["default"],
|
"default": schema.options.get("default"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if isinstance(schema, multi_select):
|
if isinstance(schema, multi_select):
|
||||||
|
@ -1020,9 +1020,69 @@ def test_section_in_serializer() -> None:
|
|||||||
{"name": "option_2", "required": True, "type": "integer"},
|
{"name": "option_2", "required": True, "type": "integer"},
|
||||||
],
|
],
|
||||||
"type": "expandable",
|
"type": "expandable",
|
||||||
|
"multiple": None,
|
||||||
|
"default": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_section_multiple_in_serializer() -> None:
|
||||||
|
"""Test section with multiple with custom_serializer."""
|
||||||
|
assert cv.custom_serializer(
|
||||||
|
data_entry_flow.section(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional("option_1", default=False): bool,
|
||||||
|
vol.Required("option_2"): int,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
{"collapsed": False, "multiple": True, "default": [{True, 10}]},
|
||||||
|
)
|
||||||
|
) == {
|
||||||
|
"expanded": True,
|
||||||
|
"schema": [
|
||||||
|
{"default": False, "name": "option_1", "optional": True, "type": "boolean"},
|
||||||
|
{"name": "option_2", "required": True, "type": "integer"},
|
||||||
|
],
|
||||||
|
"type": "expandable",
|
||||||
|
"multiple": True,
|
||||||
|
"default": [
|
||||||
|
{
|
||||||
|
True,
|
||||||
|
10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_section_multiple_and_default_inclusive_in_serializer() -> None:
|
||||||
|
"""Test section with multiple missing default in custom_serializer."""
|
||||||
|
with pytest.raises(vol.MultipleInvalid):
|
||||||
|
cv.custom_serializer(
|
||||||
|
data_entry_flow.section(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional("option_1", default=False): bool,
|
||||||
|
vol.Required("option_2"): int,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
{"collapsed": False, "multiple": None},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(vol.MultipleInvalid):
|
||||||
|
cv.custom_serializer(
|
||||||
|
data_entry_flow.section(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional("option_1", default=False): bool,
|
||||||
|
vol.Required("option_2"): int,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
{"collapsed": False, "default": []},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_nested_section_in_serializer() -> None:
|
def test_nested_section_in_serializer() -> None:
|
||||||
"""Test section with custom_serializer."""
|
"""Test section with custom_serializer."""
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user