diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index d02a41f5f97..7ddd751753e 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -24,7 +24,7 @@ def validate_selector(config: Any) -> Dict: if selector_class is None: raise vol.Invalid(f"Unknown selector type {selector_type} found") - # Seletors can be empty + # Selectors can be empty if config[selector_type] is None: return {selector_type: {}} @@ -67,10 +67,21 @@ class DeviceSelector(Selector): vol.Optional("manufacturer"): str, # Model of device vol.Optional("model"): str, + # Device has to contain entities matching this selector + vol.Optional( + "entity" + ): EntitySelector.CONFIG_SCHEMA, # pylint: disable=no-member } ) +@SELECTORS.register("area") +class AreaSelector(Selector): + """Selector of a single area.""" + + CONFIG_SCHEMA = vol.Schema({}) + + @SELECTORS.register("number") class NumberSelector(Selector): """Selector of a numeric value.""" @@ -95,13 +106,8 @@ class BooleanSelector(Selector): CONFIG_SCHEMA = vol.Schema({}) -@SELECTORS.register("datetime") -class DateTimeSelector(Selector): - """Selector of a date and or time value.""" +@SELECTORS.register("time") +class TimeSelector(Selector): + """Selector of a time value.""" - CONFIG_SCHEMA = vol.Schema( - { - vol.Optional("has_date", default=False): bool, - vol.Optional("has_time", default=False): bool, - } - ) + CONFIG_SCHEMA = vol.Schema({}) diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index c5b11285e48..9d2d57cd6d0 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -47,6 +47,13 @@ def test_validate_selector(): {"model": "mock-model"}, {"manufacturer": "mock-manuf", "model": "mock-model"}, {"integration": "zha", "manufacturer": "mock-manuf", "model": "mock-model"}, + {"entity": {"device_class": "motion"}}, + { + "integration": "zha", + "manufacturer": "mock-manuf", + "model": "mock-model", + "entity": {"domain": "binary_sensor", "device_class": "motion"}, + }, ), ) def test_device_selector_schema(schema): @@ -60,7 +67,9 @@ def test_device_selector_schema(schema): {}, {"integration": "zha"}, {"domain": "light"}, + {"device_class": "motion"}, {"integration": "zha", "domain": "light"}, + {"integration": "zha", "domain": "binary_sensor", "device_class": "motion"}, ), ) def test_entity_selector_schema(schema): @@ -68,6 +77,15 @@ def test_entity_selector_schema(schema): selector.validate_selector({"entity": schema}) +@pytest.mark.parametrize( + "schema", + ({},), +) +def test_area_selector_schema(schema): + """Test area selector.""" + selector.validate_selector({"area": schema}) + + @pytest.mark.parametrize( "schema", ( @@ -94,14 +112,8 @@ def test_boolean_selector_schema(schema): @pytest.mark.parametrize( "schema", - ( - {}, - {"has_date": True, "has_time": True}, - {"has_date": False, "has_time": False}, - {"has_date": True, "has_time": False}, - {"has_date": False, "has_time": True}, - ), + ({},), ) -def test_datetime_selector_schema(schema): - """Test datetime selector.""" - selector.validate_selector({"datetime": schema}) +def test_time_selector_schema(schema): + """Test time selector.""" + selector.validate_selector({"time": schema})