8000 Bump aioimmich to 0.8.0 by mib1185 · Pull Request #145908 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Bump aioimmich to 0.8.0 #145908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/immich/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_polling",
"loggers": ["aioimmich"],
"quality_scale": "silver",
"requirements": ["aioimmich==0.7.0"]
"requirements": ["aioimmich==0.8.0"]
}
28 changes: 15 additions & 13 deletions homeassistant/components/immich/media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ async def _async_build_immich(
identifier=f"{identifier.unique_id}|albums|{album.album_id}",
media_class=MediaClass.DIRECTORY,
media_content_type=MediaClass.IMAGE,
title=album.name,
title=album.album_name,
can_play=False,
can_expand=True,
thumbnail=f"/immich/{identifier.unique_id}/{album.thumbnail_asset_id}/thumbnail/image/jpg",
thumbnail=f"/immich/{identifier.unique_id}/{album.album_thumbnail_asset_id}/thumbnail/image/jpg",
)
for album in albums
]
Expand All @@ -160,18 +160,19 @@ async def _async_build_immich(
f"{identifier.unique_id}|albums|"
f"{identifier.collection_id}|"
f"{asset.asset_id}|"
f"{asset.file_name}|"
f"{asset.mime_type}"
f"{asset.original_file_name}|"
f"{mime_type}"
),
media_class=MediaClass.IMAGE,
media_content_type=asset.mime_type,
title=asset.file_name,
media_content_type=mime_type,
title=asset.original_file_name,
can_play=False,
can_expand=False,
thumbnail=f"/immich/{identifier.unique_id}/{asset.asset_id}/thumbnail/{asset.mime_type}",
thumbnail=f"/immich/{identifier.unique_id}/{asset.asset_id}/thumbnail/{mime_type}",
)
for asset in album_info.assets
if asset.mime_type.startswith("image/")
if (mime_type := asset.original_mime_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that the current standards are that once conditionals become multi line it is preferred to not try to use them inline anymore like this. Can fix in a followup? (given I don't want to rewrite in a dependency bump). Here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this is a side effect, as the new implementation set these attributes correct and they can also be none, so we need to check first if they are a string

Copy link
Member

Choose a reason for hiding this comment

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

+1, rewrite in follow up please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and mime_type.startswith("image/")
]

ret.extend(
Expand All @@ -181,18 +182,19 @@ async def _async_build_immich(
f"{identifier.unique_id}|albums|"
f"{identifier.collection_id}|"
f"{asset.asset_id}|"
f"{asset.file_name}|"
f"{asset.mime_type}"
f"{asset.original_file_name}|"
f"{mime_type}"
),
media_class=MediaClass.VIDEO,
media_content_type=asset.mime_type,
title=asset.file_name,
media_content_type=mime_type,
title=asset.original_file_name,
can_play=True,
can_expand=False,
thumbnail=f"/immich/{identifier.unique_id}/{asset.asset_id}/thumbnail/image/jpeg",
)
for asset in album_info.assets
if asset.mime_type.startswith("video/")
if (mime_type := asset.original_mime_type)
and mime_type.startswith("video/")
)

return ret
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements_test_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 71 additions & 47 deletions tests/components/immich/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Common fixtures for the Immich tests."""

from collections.abc import AsyncGenerator, Generator
from datetime import datetime
from unittest.mock import AsyncMock, patch

from aioimmich import ImmichAlbums, ImmichAssests, ImmichServer, ImmichUsers
Expand All @@ -10,7 +9,7 @@
ImmichServerStatistics,
ImmichServerStorage,
)
from aioimmich.users.models import AvatarColor, ImmichUser, UserStatus
from aioimmich.users.models import ImmichUserObject
import pytest

from homeassistant.components.immich.const import DOMAIN
Expand Down Expand Up @@ -78,36 +77,58 @@ def mock_immich_assets() -> AsyncMock:
def mock_immich_server() -> AsyncMock:
"""Mock the Immich server."""
mock = AsyncMock(spec=ImmichServer)
mock.async_get_about_info.return_value = ImmichServerAbout(
"v1.132.3",
"some_url",
False,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
mock.async_get_about_info.return_value = ImmichServerAbout.from_dict(
{
"version": "v1.132.3",
"versionUrl": "https://github.com/immich-app/immich/releases/tag/v1.132.3",
"licensed": False,
"build": "14709928600",
"buildUrl": "https://github.com/immich-app/immich/actions/runs/14709928600",
"buildImage": "v1.132.3",
"buildImageUrl": "https://github.com/immich-app/immich/pkgs/container/immich-server",
"repository": "immich-app/immich",
"repositoryUrl": "https://github.com/immich-app/immich",
"sourceRef": "v1.132.3",
"sourceCommit": "02994883fe3f3972323bb6759d0170a4062f5236",
"sourceUrl": "https://github.com/immich-app/immich/commit/02994883fe3f3972323bb6759d0170a4062f5236",
"nodejs": "v22.14.0",
"exiftool": "13.00",
"ffmpeg": "7.0.2-7",
"libvips": "8.16.1",
"imagemagick": "7.1.1-47",
}
)
mock.async_get_storage_info.return_value = ImmichServerStorage(
"294.2 GiB",
"142.9 GiB",
"136.3 GiB",
315926315008,
153400434688,
146402975744,
48.56,
mock.async_get_storage_info.return_value = ImmichServerStorage.from_dict(
{
"diskSize": "294.2 GiB",
"diskUse": "142.9 GiB",
"diskAvailable": "136.3 GiB",
"diskSizeRaw": 315926315008,
"diskUseRaw": 153400406016,
"diskAvailableRaw": 146403004416,
"diskUsagePercentage": 48.56,
}
)
mock.async_get_server_statistics.return_value = ImmichServerStatistics(
27038, 1836, 119525451912, 54291170551, 65234281361
mock.async_get_server_statistics.return_value = ImmichServerStatistics.from_dict(
{
"photos": 27038,
"videos": 1836,
"usage": 119525451912,
"usagePhotos": 54291170551,
"usageVideos": 65234281361,
"usageByUser": [
{
D966 "userId": "e7ef5713-9dab-4bd4-b899-715b0ca4379e",
"userName": "admin",
"photos": 27038,
"videos": 1836,
"usage": 119525451912,
"usagePhotos": 54291170551,
"usageVideos": 65234281361,
"quotaSizeInBytes": None,
}
],
}
)
return mock

Expand All @@ -116,23 +137,26 @@ def mock_immich_server() -> AsyncMock:
def mock_immich_user() -> AsyncMock:
"""Mock the Immich server."""
mock = AsyncMock(spec=ImmichUsers)
mock.async_get_my_user.return_value = ImmichUser(
"e7ef5713-9dab-4bd4-b899-715b0ca4379e",
"user@immich.local",
"user",
"",
AvatarColor.PRIMARY,
datetime.fromisoformat("2025-05-11T10:07:46.866Z"),
"user",
False,
True,
datetime.fromisoformat("2025-05-11T10:07:46.866Z"),
None,
None,
"",
None,
None,
UserStatus.ACTIVE,
mock.async_get_my_user.return_value = ImmichUserObject.from_dict(
{
"id": "e7ef5713-9dab-4bd4-b899-715b0ca4379e",
"email": "user@immich.local",
"name": "user",
"profileImagePath": "",
"avatarColor": "primary",
"profileChangedAt": "2025-05-11T10:07:46.866Z",
"storageLabel": "user",
"shouldChangePassword": True,
"isAdmin": True,
"createdAt": "2025-05-11T10:07:46.866Z",
"deletedAt": None,
"updatedAt": "2025-05-18T00:59:55.547Z",
"oauthId": "",
"quotaSizeInBytes": None,
"quotaUsageInBytes": 119526467534,
"status": "active",
"license": None,
}
)
return mock

Expand Down
109 changes: 86 additions & 23 deletions tests/components/immich/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Constants for the Immich integration tests."""

from aioimmich.albums.models import ImmichAlbum
from aioimmich.assets.models import ImmichAsset

from homeassistant.const import (
CONF_API_KEY,
Expand All @@ -26,27 +25,91 @@
CONF_VERIFY_SSL: False,
}

MOCK_ALBUM_WITHOUT_ASSETS = ImmichAlbum(
"721e1a4b-aa12-441e-8d3b-5ac7ab283bb6",
"My Album",
"This is my first great album",
"0d03a7ad-ddc7-45a6-adee-68d322a6d2f5",
1,
[],
)
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(
"721e1a4b-aa12-441e-8d3b-5ac7ab283bb6",
"My Album",
"This is my first great album",
"0d03a7ad-ddc7-45a6-adee-68d322a6d2f5",
1,
[
ImmichAsset(
"2e94c203-50aa-4ad2-8e29-56dd74e0eff4", "filename.jpg", "image/jpeg"
),
ImmichAsset(
"2e65a5f2-db83-44c4-81ab-f5ff20c9bd7b", "filename.mp4", "video/mp4"
),
],
MOCK_ALBUM_WITH_ASSETS = 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,
},
],
}
)
Loading
0