Skip to content

Add search functionality to media source - #175485

Merged
balloob merged 5 commits into
home-assistant:devfrom
zweckj:media_source/search-media
Jul 3, 2026
Merged

Add search functionality to media source#175485
balloob merged 5 commits into
home-assistant:devfrom
zweckj:media_source/search-media

Conversation

@zweckj

@zweckj zweckj commented Jul 3, 2026

Copy link
Copy Markdown
Member

Breaking change

Proposed change

Adding search functionality to the media browser. Re-uses the already existing can_search flag to signaling to the browser whether to show the search bar.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant

home-assistant Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (demo) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of demo can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign demo Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@home-assistant

home-assistant Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Hey there @hunterjm, mind taking a look at this pull request as it has been labeled with an integration (media_source) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of media_source can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign media_source Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 helper media_source.async_search_media(...).
  • Adds a new websocket command media_source/search_media and 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.

Comment thread homeassistant/components/media_source/helper.py
Comment thread homeassistant/components/media_source/local_source.py Outdated
zweckj added 2 commits July 3, 2026 12:25
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.
Copilot AI review requested due to automatic review settings July 3, 2026 19:05
'can_expand': True,
'can_play': False,
'can_search': False,
'can_search': True,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heos references the local media_source, so this flips

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread homeassistant/components/media_source/strings.json Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 19:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Comment thread homeassistant/components/media_source/models.py
@zweckj
zweckj marked this pull request as ready for review July 3, 2026 20:14
Copilot AI review requested due to automatic review settings July 3, 2026 20:14
@zweckj
zweckj requested review from a team, andrewsayre and hunterjm as code owners July 3, 2026 20:14
@balloob
balloob merged commit fe8b145 into home-assistant:dev Jul 3, 2026
44 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

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
Comment on lines +12 to +17
"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}"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an abbreviation, "ID" should be capitalized in these user-facing strings

Suggested change
"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}"
},

@bluetoothbot bluetoothbot mentioned this pull request Jul 4, 2026
21 tasks
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants