From 875219ccb551108feaed31f9725d54dde82665fe Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 21 Jul 2025 14:02:04 +0200 Subject: [PATCH] Adds support for hide_states options in state selector (#148959) --- homeassistant/helpers/selector.py | 6 ++++-- tests/helpers/test_selector.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 9eaedc6f5ef..2429b4b23e8 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -1338,7 +1338,8 @@ class TargetSelectorConfig(BaseSelectorConfig, total=False): class StateSelectorConfig(BaseSelectorConfig, total=False): """Class to represent an state selector config.""" - entity_id: Required[str] + entity_id: str + hide_states: list[str] @SELECTORS.register("state") @@ -1349,7 +1350,8 @@ class StateSelector(Selector[StateSelectorConfig]): CONFIG_SCHEMA = BASE_SELECTOR_CONFIG_SCHEMA.extend( { - vol.Required("entity_id"): cv.entity_id, + vol.Optional("entity_id"): cv.entity_id, + vol.Optional("hide_states"): [str], # The attribute to filter on, is currently deliberately not # configurable/exposed. We are considering separating state # selectors into two types: one for state and one for attribute. diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 9e8f1b15311..50d9da501c5 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -565,6 +565,11 @@ def test_time_selector_schema(schema, valid_selections, invalid_selections) -> N ("on", "armed"), (None, True, 1), ), + ( + {"hide_states": ["unknown", "unavailable"]}, + (), + (), + ), ], ) def test_state_selector_schema(schema, valid_selections, invalid_selections) -> None: