mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix media selector validation (#147855)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
470baa782e
commit
6a7f4953cd
@ -1045,16 +1045,17 @@ class MediaSelector(Selector[MediaSelectorConfig]):
|
||||
|
||||
def __call__(self, data: Any) -> dict[str, str]:
|
||||
"""Validate the passed selection."""
|
||||
schema = self.DATA_SCHEMA.schema.copy()
|
||||
schema = {
|
||||
key: value
|
||||
for key, value in self.DATA_SCHEMA.schema.items()
|
||||
if key != "entity_id"
|
||||
}
|
||||
|
||||
if "accept" in self.config:
|
||||
# If accept is set, the entity_id field will not be present
|
||||
schema.pop("entity_id", None)
|
||||
else:
|
||||
if "accept" not in self.config:
|
||||
# If accept is not set, the entity_id field is required
|
||||
schema[vol.Required("entity_id")] = cv.entity_id_or_uuid
|
||||
|
||||
media: dict[str, str] = self.DATA_SCHEMA(data)
|
||||
media: dict[str, str] = vol.Schema(schema)(data)
|
||||
return media
|
||||
|
||||
|
||||
|
@ -842,7 +842,16 @@ def test_theme_selector_schema(schema, valid_selections, invalid_selections) ->
|
||||
"metadata": {},
|
||||
},
|
||||
),
|
||||
(None, "abc", {}),
|
||||
(
|
||||
None,
|
||||
"abc",
|
||||
{},
|
||||
# We require entity_id when accept is not set
|
||||
{
|
||||
"media_content_id": "abc",
|
||||
"media_content_type": "def",
|
||||
},
|
||||
),
|
||||
),
|
||||
(
|
||||
{
|
||||
@ -859,7 +868,18 @@ def test_theme_selector_schema(schema, valid_selections, invalid_selections) ->
|
||||
"metadata": {},
|
||||
},
|
||||
),
|
||||
(None, "abc", {}),
|
||||
(
|
||||
None,
|
||||
"abc",
|
||||
{},
|
||||
{
|
||||
# We do not allow entity_id when accept is set
|
||||
"entity_id": "sensor.abc",
|
||||
"media_content_id": "abc",
|
||||
"media_content_type": "def",
|
||||
"metadata": {},
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user