Skip to content

Commit be6b624

Browse files
authored
Improve validation for media selector (home-assistant#147768)
1 parent 217fbb2 commit be6b624

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

homeassistant/helpers/selector.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,18 @@ def __init__(self, config: MediaSelectorConfig | None = None) -> None:
10431043
"""Instantiate a selector."""
10441044
super().__init__(config)
10451045

1046-
def __call__(self, data: Any) -> dict[str, float]:
1046+
def __call__(self, data: Any) -> dict[str, str]:
10471047
"""Validate the passed selection."""
1048-
media: dict[str, float] = self.DATA_SCHEMA(data)
1048+
schema = self.DATA_SCHEMA.schema.copy()
1049+
1050+
if "accept" in self.config:
1051+
# If accept is set, the entity_id field will not be present
1052+
schema.pop("entity_id", None)
1053+
else:
1054+
# If accept is not set, the entity_id field is required
1055+
schema[vol.Required("entity_id")] = cv.entity_id_or_uuid
1056+
1057+
media: dict[str, str] = self.DATA_SCHEMA(data)
10491058
return media
10501059

10511060

0 commit comments

Comments
 (0)