From 3764f36c363abe6a976de745df902afd051a8795 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 2 Dec 2026 02:58:35 -0500 Subject: [PATCH] Use the MIME type as the Google Photos media content type (#195930) Co-authored-by: Claude Opus 5.5 --- homeassistant/components/google_photos/media_source.py | 4 +++- tests/components/google_photos/test_media_source.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/google_photos/media_source.py b/homeassistant/components/google_photos/media_source.py index 46aba88091b8..99f021dabcfb 100644 --- a/homeassistant/components/google_photos/media_source.py +++ b/homeassistant/components/google_photos/media_source.py @@ -276,7 +276,9 @@ def _build_media_item( domain=DOMAIN, identifier=identifier.as_string(), media_class=MediaClass.IMAGE if not is_video else MediaClass.VIDEO, - media_content_type=MediaType.IMAGE if not is_video else MediaType.VIDEO, + # Media pickers filter on MIME types, such as image/*. + media_content_type=media_item.mime_type + or (MediaType.IMAGE if not is_video else MediaType.VIDEO), title=media_item.filename, can_play=is_video, can_expand=False, diff --git a/tests/components/google_photos/test_media_source.py b/tests/components/google_photos/test_media_source.py index 31da43ddc5ab..16328ac2efb1 100644 --- a/tests/components/google_photos/test_media_source.py +++ b/tests/components/google_photos/test_media_source.py @@ -75,8 +75,8 @@ async def test_no_read_scopes( ( "list_mediaitems.json", [ - (f"{CONFIG_ENTRY_ID}/p/id1", "example1.jpg"), - (f"{CONFIG_ENTRY_ID}/p/id2", "example2.mp4"), + (f"{CONFIG_ENTRY_ID}/p/id1", "example1.jpg", "image/jpeg"), + (f"{CONFIG_ENTRY_ID}/p/id2", "example2.mp4", "video/mp4"), ], [ ("http://img.example.com/id1=h2160", "image/jpeg"), @@ -89,7 +89,7 @@ async def test_browse_albums( hass: HomeAssistant, album_path: str, expected_album_title: str, - expected_results: list[tuple[str, str]], + expected_results: list[tuple[str, str, str]], expected_medias: list[tuple[str, str]], ) -> None: """Test a media source with no eligible camera devices.""" @@ -114,7 +114,8 @@ async def test_browse_albums( assert browse.identifier == album_path assert browse.title == "Account Name" assert [ - (child.identifier, child.title) for child in browse.children + (child.identifier, child.title, child.media_content_type) + for child in browse.children ] == expected_results media = [