From b6f52c1e83dc287a30c8ef4c2e417dc20b26a1d6 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 16 Mar 2022 21:52:23 +0100 Subject: [PATCH] Allow number selector selection to be None --- homeassistant/helpers/selector.py | 5 ++++- tests/helpers/test_selector.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index e529cac096c..93f771d5bd6 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -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"]: diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 88820de9eef..fdd2e0cf112 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -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):