From 48fd22c3d2fd42c352f4cfc079ebd72b8ccdaeb3 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 23 May 2025 13:35:52 -0400 Subject: [PATCH] Add accept keyword to Media selector --- homeassistant/helpers/selector.py | 10 +++++++--- tests/helpers/test_selector.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index 2d7fd51cac7..3c4215fb8c7 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -1020,11 +1020,15 @@ class MediaSelector(Selector[MediaSelectorConfig]): selector_type = "media" - CONFIG_SCHEMA = BASE_SELECTOR_CONFIG_SCHEMA + CONFIG_SCHEMA = BASE_SELECTOR_CONFIG_SCHEMA.extend( + { + vol.Optional("accept"): [str], + } + ) DATA_SCHEMA = vol.Schema( { - # Although marked as optional in frontend, this field is required - vol.Required("entity_id"): cv.entity_id_or_uuid, + # If accept is set, the entity_id field will not be present + vol.Optional("entity_id"): cv.entity_id_or_uuid, # Although marked as optional in frontend, this field is required vol.Required("media_content_id"): str, # Although marked as optional in frontend, this field is required diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index 3ddbecaf48d..3036a934482 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -817,6 +817,23 @@ def test_theme_selector_schema(schema, valid_selections, invalid_selections) -> ), (None, "abc", {}), ), + ( + { + "accept": ["image/*"], + }, + ( + { + "media_content_id": "abc", + "media_content_type": "def", + }, + { + "media_content_id": "abc", + "media_content_type": "def", + "metadata": {}, + }, + ), + (None, "abc", {}), + ), ], ) def test_media_selector_schema(schema, valid_selections, invalid_selections) -> None: