diff --git a/homeassistant/components/immich/coordinator.py b/homeassistant/components/immich/coordinator.py index ada6315b1acb..6c8f9053254c 100644 --- a/homeassistant/components/immich/coordinator.py +++ b/homeassistant/components/immich/coordinator.py @@ -81,6 +81,7 @@ class ImmichDataUpdateCoordinator(DataUpdateCoordinator[ImmichData]): async def _async_setup(self) -> None: """Handle setup of the coordinator.""" try: + await self.api.async_setup() user_info = await self.api.users.async_get_my_user() except ImmichUnauthorizedError as err: raise ConfigEntryAuthFailed( diff --git a/homeassistant/components/immich/manifest.json b/homeassistant/components/immich/manifest.json index 7cc16c1979a2..82ad297c0b57 100644 --- a/homeassistant/components/immich/manifest.json +++ b/homeassistant/components/immich/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_polling", "loggers": ["aioimmich"], "quality_scale": "platinum", - "requirements": ["aioimmich==0.14.1"] + "requirements": ["aioimmich==0.15.0"] } diff --git a/homeassistant/components/immich/media_source.py b/homeassistant/components/immich/media_source.py index aab6df65c5ba..c6ab04332841 100644 --- a/homeassistant/components/immich/media_source.py +++ b/homeassistant/components/immich/media_source.py @@ -225,10 +225,9 @@ class ImmichMediaSource(MediaSource): entry.title, ) try: - album_info = await immich_api.albums.async_get_album_info( - identifier.collection_id + assets = await immich_api.search.async_get_all_by_album_ids( + [identifier.collection_id] ) - assets = album_info.assets except ImmichForbiddenError as err: raise BrowseError( translation_domain=DOMAIN, diff --git a/homeassistant/components/immich/services.py b/homeassistant/components/immich/services.py index 60c98d1e76f2..9ca476a27271 100644 --- a/homeassistant/components/immich/services.py +++ b/homeassistant/components/immich/services.py @@ -53,7 +53,7 @@ async def _async_upload_file(service_call: ServiceCall) -> None: if target_album := service_call.data.get(CONF_ALBUM_ID): try: - await coordinator.api.albums.async_get_album_info(target_album, True) + await coordinator.api.albums.async_get_album_info(target_album) except ImmichError as ex: raise ServiceValidationError( translation_domain=DOMAIN, diff --git a/requirements_all.txt b/requirements_all.txt index 24fb5f3095f4..3ed270a4dd5d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -303,7 +303,7 @@ aiohue==4.8.1 aioimaplib==2.0.1 # homeassistant.components.immich -aioimmich==0.14.1 +aioimmich==0.15.0 # homeassistant.components.apache_kafka aiokafka==0.10.0 diff --git a/tests/components/immich/conftest.py b/tests/components/immich/conftest.py index 86106a181fbd..214e4325407e 100644 --- a/tests/components/immich/conftest.py +++ b/tests/components/immich/conftest.py @@ -40,8 +40,8 @@ from homeassistant.setup import async_setup_component from homeassistant.util.aiohttp import MockStreamReaderChunked from .const import ( - MOCK_ALBUM_WITH_ASSETS, - MOCK_ALBUM_WITHOUT_ASSETS, + ALBUM_DATA, + MOCK_ALBUM_ASSETS, MOCK_FAVORITE_ASSETS, MOCK_PEOPLE_ASSETS, MOCK_TAGS_ASSETS, @@ -80,8 +80,7 @@ def mock_config_entry() -> MockConfigEntry: def mock_immich_albums() -> AsyncMock: """Mock the Immich server.""" mock = AsyncMock(spec=ImmichAlbums) - mock.async_get_all_albums.return_value = [MOCK_ALBUM_WITHOUT_ASSETS] - mock.async_get_album_info.return_value = MOCK_ALBUM_WITH_ASSETS + mock.async_get_all_albums.return_value = [ALBUM_DATA] mock.async_add_assets_to_album.return_value = [ ImmichAddAssetsToAlbumResponse.from_dict( {"id": "abcdef-0123456789", "success": True} @@ -160,6 +159,7 @@ def mock_immich_search() -> AsyncMock: """Mock the Immich server.""" mock = AsyncMock(spec=ImmichSearch) mock.async_get_all_favorites.return_value = MOCK_FAVORITE_ASSETS + mock.async_get_all_by_album_ids.return_value = MOCK_ALBUM_ASSETS mock.async_get_all_by_person_ids.return_value = MOCK_PEOPLE_ASSETS mock.async_get_all_by_tag_ids.return_value = MOCK_TAGS_ASSETS return mock diff --git a/tests/components/immich/const.py b/tests/components/immich/const.py index 8febb32bf5e6..3938db333737 100644 --- a/tests/components/immich/const.py +++ b/tests/components/immich/const.py @@ -26,103 +26,101 @@ MOCK_CONFIG_ENTRY_DATA = { CONF_VERIFY_SSL: False, } -ALBUM_DATA = { - "id": "721e1a4b-aa12-441e-8d3b-5ac7ab283bb6", - "albumName": "My Album", - "albumThumbnailAssetId": "0d03a7ad-ddc7-45a6-adee-68d322a6d2f5", - "albumUsers": [], - "assetCount": 1, - "assets": [], - "createdAt": "2025-05-11T10:13:22.799Z", - "hasSharedLink": False, - "isActivityEnabled": False, - "ownerId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", - "owner": { - "id": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", - "email": "admin@immich.local", - "name": "admin", - "profileImagePath": "", - "avatarColor": "primary", - "profileChangedAt": "2025-05-11T10:07:46.866Z", - }, - "shared": False, - "updatedAt": "2025-05-17T11:26:03.696Z", -} - -MOCK_ALBUM_WITHOUT_ASSETS = ImmichAlbum.from_dict(ALBUM_DATA) - -MOCK_ALBUM_WITH_ASSETS = ImmichAlbum.from_dict( +ALBUM_DATA = ImmichAlbum.from_dict( { - **ALBUM_DATA, - "assets": [ - { - "id": "2e94c203-50aa-4ad2-8e29-56dd74e0eff4", - "deviceAssetId": "web-filename.jpg-1675185639000", - "ownerId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", - "deviceId": "WEB", - "libraryId": None, - "type": "IMAGE", - "originalPath": ( - "upload/upload/e7ef5713-9dab-4bd4-b899" - "-715b0ca4379e/b4/b8/" - "b4b8ef00-8a6d-4056-91ff-7f86dc66e427.jpg" - ), - "originalFileName": "filename.jpg", - "originalMimeType": "image/jpeg", - "thumbhash": "1igGFALX8mVGdHc5aChJf5nxNg==", - "fileCreatedAt": "2023-01-31T17:20:37.085+00:00", - "fileModifiedAt": "2023-01-31T17:20:39+00:00", - "localDateTime": "2023-01-31T18:20:37.085+00:00", - "updatedAt": "2025-05-11T10:13:49.590401+00:00", - "isFavorite": False, - "isArchived": False, - "isTrashed": False, - "duration": "0:00:00.00000", - "exifInfo": {}, - "livePhotoVideoId": None, - "people": [], - "checksum": "HJm7TVOP80S+eiYZnAhWyRaB/Yc=", - "isOffline": False, - "hasMetadata": True, - "duplicateId": None, - "resized": True, - }, - { - "id": "2e65a5f2-db83-44c4-81ab-f5ff20c9bd7b", - "deviceAssetId": "web-filename.mp4-1675185639000", - "ownerId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", - "deviceId": "WEB", - "libraryId": None, - "type": "IMAGE", - "originalPath": ( - "upload/upload/e7ef5713-9dab-4bd4-b899" - "-715b0ca4379e/b4/b8/" - "b4b8ef00-8a6d-4056-eeff-7f86dc66e427.mp4" - ), - "originalFileName": "filename.mp4", - "originalMimeType": "video/mp4", - "thumbhash": "1igGFALX8mVGdHc5aChJf5nxNg==", - "fileCreatedAt": "2023-01-31T17:20:37.085+00:00", - "fileModifiedAt": "2023-01-31T17:20:39+00:00", - "localDateTime": "2023-01-31T18:20:37.085+00:00", - "updatedAt": "2025-05-11T10:13:49.590401+00:00", - "isFavorite": False, - "isArchived": False, - "isTrashed": False, - "duration": "0:00:00.00000", - "exifInfo": {}, - "livePhotoVideoId": None, - "people": [], - "checksum": "HJm7TVOP80S+eiYZnAhWyRaB/Yc=", - "isOffline": False, - "hasMetadata": True, - "duplicateId": None, - "resized": True, - }, - ], + "id": "721e1a4b-aa12-441e-8d3b-5ac7ab283bb6", + "albumName": "My Album", + "albumThumbnailAssetId": "0d03a7ad-ddc7-45a6-adee-68d322a6d2f5", + "albumUsers": [], + "assetCount": 1, + "createdAt": "2025-05-11T10:13:22.799Z", + "hasSharedLink": False, + "isActivityEnabled": False, + "ownerId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", + "owner": { + "id": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", + "email": "admin@immich.local", + "name": "admin", + "profileImagePath": "", + "avatarColor": "primary", + "profileChangedAt": "2025-05-11T10:07:46.866Z", + }, + "shared": False, + "updatedAt": "2025-05-17T11:26:03.696Z", } ) + +MOCK_ALBUM_ASSETS = [ + ImmichAsset.from_dict( + { + "id": "2e94c203-50aa-4ad2-8e29-56dd74e0eff4", + "deviceAssetId": "web-filename.jpg-1675185639000", + "ownerId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", + "deviceId": "WEB", + "libraryId": None, + "type": "IMAGE", + "originalPath": ( + "upload/upload/e7ef5713-9dab-4bd4-b899" + "-715b0ca4379e/b4/b8/" + "b4b8ef00-8a6d-4056-91ff-7f86dc66e427.jpg" + ), + "originalFileName": "filename.jpg", + "originalMimeType": "image/jpeg", + "thumbhash": "1igGFALX8mVGdHc5aChJf5nxNg==", + "fileCreatedAt": "2023-01-31T17:20:37.085+00:00", + "fileModifiedAt": "2023-01-31T17:20:39+00:00", + "localDateTime": "2023-01-31T18:20:37.085+00:00", + "updatedAt": "2025-05-11T10:13:49.590401+00:00", + "isFavorite": False, + "isArchived": False, + "isTrashed": False, + "duration": "0:00:00.00000", + "exifInfo": {}, + "livePhotoVideoId": None, + "people": [], + "checksum": "HJm7TVOP80S+eiYZnAhWyRaB/Yc=", + "isOffline": False, + "hasMetadata": True, + "duplicateId": None, + "resized": True, + } + ), + ImmichAsset.from_dict( + { + "id": "2e65a5f2-db83-44c4-81ab-f5ff20c9bd7b", + "deviceAssetId": "web-filename.mp4-1675185639000", + "ownerId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e", + "deviceId": "WEB", + "libraryId": None, + "type": "IMAGE", + "originalPath": ( + "upload/upload/e7ef5713-9dab-4bd4-b899" + "-715b0ca4379e/b4/b8/" + "b4b8ef00-8a6d-4056-eeff-7f86dc66e427.mp4" + ), + "originalFileName": "filename.mp4", + "originalMimeType": "video/mp4", + "thumbhash": "1igGFALX8mVGdHc5aChJf5nxNg==", + "fileCreatedAt": "2023-01-31T17:20:37.085+00:00", + "fileModifiedAt": "2023-01-31T17:20:39+00:00", + "localDateTime": "2023-01-31T18:20:37.085+00:00", + "updatedAt": "2025-05-11T10:13:49.590401+00:00", + "isFavorite": False, + "isArchived": False, + "isTrashed": False, + "duration": "0:00:00.00000", + "exifInfo": {}, + "livePhotoVideoId": None, + "people": [], + "checksum": "HJm7TVOP80S+eiYZnAhWyRaB/Yc=", + "isOffline": False, + "hasMetadata": True, + "duplicateId": None, + "resized": True, + } + ), +] MOCK_PEOPLE_ASSETS = [ ImmichAsset.from_dict( { diff --git a/tests/components/immich/test_media_source.py b/tests/components/immich/test_media_source.py index faad3c5ee8e4..3dc3856e237c 100644 --- a/tests/components/immich/test_media_source.py +++ b/tests/components/immich/test_media_source.py @@ -293,7 +293,7 @@ async def test_browse_media_collections_error( @pytest.mark.parametrize( ("collection", "mocked_get_fn"), [ - ("albums", ("albums", "async_get_album_info")), + ("albums", ("search", "async_get_all_by_album_ids")), ("favorites", ("search", "async_get_all_favorites")), ("people", ("search", "async_get_all_by_person_ids")), ("tags", ("search", "async_get_all_by_tag_ids")), diff --git a/tests/components/immich/test_services.py b/tests/components/immich/test_services.py index 4bfb43db8193..7f68792ac8f2 100644 --- a/tests/components/immich/test_services.py +++ b/tests/components/immich/test_services.py @@ -82,7 +82,7 @@ async def test_upload_file_to_album( mock_immich.assets.async_upload_asset.assert_called_with("/media/screenshot.jpg") mock_immich.albums.async_get_album_info.assert_called_with( - "721e1a4b-aa12-441e-8d3b-5ac7ab283bb6", True + "721e1a4b-aa12-441e-8d3b-5ac7ab283bb6" ) mock_immich.albums.async_add_assets_to_album.assert_called_with( "721e1a4b-aa12-441e-8d3b-5ac7ab283bb6", ["abcdef-0123456789"]