This commit is contained in:
G Johansson
2025-07-02 07:30:58 +00:00
parent 315564a443
commit 5f5eb7f0c1
2 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
# serializer version: 1
# name: test_object_selector_uses_selectors
dict({
'selector': dict({
'object': dict({
'description_field': 'percentage',
'fields': dict({
'name': dict({
'required': True,
'selector': dict({
'text': dict({
'multiline': False,
'multiple': False,
}),
}),
}),
'percentage': dict({
'selector': dict({
'number': dict({
'max': 100.0,
'min': 0.0,
'mode': 'slider',
'step': 1.0,
}),
}),
}),
}),
'label_field': 'name',
'multiple': True,
}),
}),
})
# ---

View File

@@ -4,6 +4,7 @@ from enum import Enum
from typing import Any from typing import Any
import pytest import pytest
from syrupy.assertion import SnapshotAssertion
import voluptuous as vol import voluptuous as vol
from homeassistant.helpers import selector from homeassistant.helpers import selector
@@ -670,6 +671,43 @@ def test_object_selector_schema(schema, valid_selections, invalid_selections) ->
_test_selector("object", schema, valid_selections, invalid_selections) _test_selector("object", schema, valid_selections, invalid_selections)
def test_object_selector_uses_selectors(snapshot: SnapshotAssertion) -> None:
"""Test ObjectSelector custom serializer for using Selector in ObjectSelectorField."""
selector_type = "object"
schema = {
"fields": {
"name": {
"required": True,
"selector": selector.TextSelector(),
},
"percentage": {
"selector": selector.NumberSelector(
selector.NumberSelectorConfig(min=0, max=100)
),
},
},
"multiple": True,
"label_field": "name",
"description_field": "percentage",
}
# Validate selector configuration
config = {selector_type: schema}
selector.validate_selector(config)
selector_instance = selector.selector(config)
# Serialize selector
selector_instance = selector.selector({selector_type: schema})
assert selector_instance.serialize() != {
"selector": {selector_type: selector_instance.config}
}
assert selector_instance.serialize() == snapshot()
# Test serialized selector can be dumped to YAML
yaml_util.dump(selector_instance.serialize())
@pytest.mark.parametrize( @pytest.mark.parametrize(
("schema", "valid_selections", "invalid_selections"), ("schema", "valid_selections", "invalid_selections"),
[ [