Add search functionality to media source - #175485
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Hey there @hunterjm, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Adds media-source search support end-to-end (model API, helper + websocket endpoint, and local media implementation) and expands test coverage to validate the new behavior via helpers and websockets.
Changes:
- Introduces
MediaSourceItem.async_search()/MediaSource.async_search_media()and a helpermedia_source.async_search_media(...). - Adds a new websocket command
media_source/search_mediaand wires demo media player search to delegate into media source search. - Implements filename-based searching for the local media source and adds tests for search behavior, filtering, and limits.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/components/media_source/test_models.py | Adds unit tests for base search behavior and root aggregation across sources. |
| tests/components/media_source/test_local_source.py | Adds integration tests for local source search, filtering, hidden files, and result limits. |
| tests/components/media_source/test_http.py | Adds websocket coverage for the new media_source/search_media command. |
| tests/components/media_source/test_helper.py | Adds helper-level tests for async_search_media success and failure paths. |
| tests/components/demo/test_media_player.py | Verifies media player search websocket delegates into media source search. |
| homeassistant/components/media_source/strings.json | Adds a translated error message key for search failures. |
| homeassistant/components/media_source/models.py | Adds search support on MediaSourceItem and the MediaSource base API. |
| homeassistant/components/media_source/local_source.py | Implements local media directory search and advertises can_search for directories. |
| homeassistant/components/media_source/http.py | Registers and implements the media_source/search_media websocket command. |
| homeassistant/components/media_source/helper.py | Adds the public helper async_search_media(...) for searching via media source URIs. |
| homeassistant/components/media_source/init.py | Exports the new async_search_media helper from the integration package. |
| homeassistant/components/demo/media_player.py | Enables demo browse player search support and delegates to media source search. |
Address Copilot review on media source search: - Convert NotImplementedError from a targeted, non-searchable source into a BrowseError so the websocket search handler responds gracefully. - Traverse local media lazily so MAX_SEARCH_RESULTS short-circuits large libraries, and sort only the collected results for stable ordering.
| 'can_expand': True, | ||
| 'can_play': False, | ||
| 'can_search': False, | ||
| 'can_search': True, |
There was a problem hiding this comment.
heos references the local media_source, so this flips
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| async def async_search(self, query: SearchMediaQuery) -> SearchMedia: | ||
| """Search this item.""" | ||
| # Searching the aggregate root (no specific source) is currently not supported | ||
| # because it would possibly returns 100s of items |
| "search_media_failed": { | ||
| "message": "Failed to search media with content id {media_content_id}: {error}" | ||
| }, | ||
| "search_not_supported": { | ||
| "message": "Search is not supported for media with content id {media_content_id}" | ||
| }, |
There was a problem hiding this comment.
As an abbreviation, "ID" should be capitalized in these user-facing strings
| "search_media_failed": { | |
| "message": "Failed to search media with content id {media_content_id}: {error}" | |
| }, | |
| "search_not_supported": { | |
| "message": "Search is not supported for media with content id {media_content_id}" | |
| }, | |
| "search_media_failed": { | |
| "message": "Failed to search media with content ID {media_content_id}: {error}" | |
| }, | |
| "search_not_supported": { | |
| "message": "Search is not supported for media with content ID {media_content_id}" | |
| }, |
Breaking change
Proposed change
Adding search functionality to the media browser. Re-uses the already existing
can_searchflag to signaling to the browser whether to show the search bar.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: