Improve validation for media selector (#147768)

This commit is contained in:
Paulus Schoutsen 2025-06-30 20:26:52 +02:00 committed by GitHub
parent 217fbb2849
commit be6b624081
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1043,9 +1043,18 @@ class MediaSelector(Selector[MediaSelectorConfig]):
"""Instantiate a selector."""
super().__init__(config)
def __call__(self, data: Any) -> dict[str, float]:
def __call__(self, data: Any) -> dict[str, str]:
"""Validate the passed selection."""
media: dict[str, float] = self.DATA_SCHEMA(data)
schema = self.DATA_SCHEMA.schema.copy()
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 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)
return media