Allow number selector selection to be None

This commit is contained in:
Erik 2022-03-16 21:52:23 +01:00
parent 6f425c6c06
commit b6f52c1e83
2 changed files with 6 additions and 2 deletions

View file

@ -207,8 +207,11 @@ class NumberSelector(Selector):
has_min_max_if_slider,
)
def __call__(self, data: Any) -> float:
def __call__(self, data: Any) -> float | None:
"""Validate the passed selection."""
if data is None:
return data
value: float = vol.Coerce(float)(data)
if "min" in self.config and value < self.config["min"]:

View file

@ -208,7 +208,8 @@ def test_area_selector_schema(schema, valid_selections, invalid_selections):
(),
),
({"min": 10, "max": 1000, "mode": "slider", "step": 0.5}, (), ()),
({"mode": "box"}, (10,), ()),
({"mode": "box"}, (10, None), ("cat")),
({"mode": "slider", "min": -100, "max": 100}, (10, None), ("cat")),
),
)
def test_number_selector_schema(schema, valid_selections, invalid_selections):