diff --git a/README.md b/README.md index 5a5c58d..352b4ec 100644 --- a/README.md +++ b/README.md @@ -121,8 +121,8 @@ data: limit: 10 # Maximum number of assets (1-100) favorite_only: false # true = favorites only, false = all assets filter_min_rating: 4 # Min rating (1-5) - order_by: "date" # Options: "date", "rating", "name" - order: "descending" # Options: "ascending", "descending", "random" + order_by: "date" # Options: "date", "rating", "name", "random" + order: "descending" # Options: "ascending", "descending" asset_type: "all" # Options: "all", "photo", "video" min_date: "2024-01-01" # Optional: assets created on or after this date max_date: "2024-12-31" # Optional: assets created on or before this date @@ -137,10 +137,10 @@ data: - `"date"`: Sort by creation date - `"rating"`: Sort by rating (assets without rating are placed last) - `"name"`: Sort by filename + - `"random"`: Random order (ignores `order`) - `order` (optional, default: "descending"): Sort direction - `"ascending"`: Ascending order - `"descending"`: Descending order - - `"random"`: Random order (ignores `order_by`) - `asset_type` (optional, default: "all"): Filter by asset type - `"all"`: No type filtering, return both photos and videos - `"photo"`: Return only photos @@ -172,7 +172,7 @@ target: data: limit: 10 filter_min_rating: 3 - order: "random" + order_by: "random" ``` Get 20 most recent photos only: diff --git a/custom_components/immich_album_watcher/coordinator.py b/custom_components/immich_album_watcher/coordinator.py index eb28c00..c41ca9b 100644 --- a/custom_components/immich_album_watcher/coordinator.py +++ b/custom_components/immich_album_watcher/coordinator.py @@ -413,30 +413,28 @@ class ImmichAlbumWatcherCoordinator(DataUpdateCoordinator[AlbumData | None]): assets = [a for a in assets if a.created_at <= max_date] # Apply ordering - if order == "random": + if order_by == "random": import random random.shuffle(assets) - else: - # Determine sort key based on order_by - if order_by == "rating": - # Sort by rating, putting None values last - assets = sorted( - assets, - key=lambda a: (a.rating is None, a.rating if a.rating is not None else 0), - reverse=(order == "descending") - ) - elif order_by == "name": - assets = sorted( - assets, - key=lambda a: a.filename.lower(), - reverse=(order == "descending") - ) - else: # date (default) - assets = sorted( - assets, - key=lambda a: a.created_at, - reverse=(order == "descending") - ) + elif order_by == "rating": + # Sort by rating, putting None values last + assets = sorted( + assets, + key=lambda a: (a.rating is None, a.rating if a.rating is not None else 0), + reverse=(order == "descending") + ) + elif order_by == "name": + assets = sorted( + assets, + key=lambda a: a.filename.lower(), + reverse=(order == "descending") + ) + else: # date (default) + assets = sorted( + assets, + key=lambda a: a.created_at, + reverse=(order == "descending") + ) # Limit results assets = assets[:limit] diff --git a/custom_components/immich_album_watcher/manifest.json b/custom_components/immich_album_watcher/manifest.json index 6e1a2b4..f902de4 100644 --- a/custom_components/immich_album_watcher/manifest.json +++ b/custom_components/immich_album_watcher/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/DolgolyovAlexei/haos-hacs-immich-album-watcher/issues", "requirements": [], - "version": "2.2.0" + "version": "2.2.1" } diff --git a/custom_components/immich_album_watcher/sensor.py b/custom_components/immich_album_watcher/sensor.py index 31875e4..4a501ac 100644 --- a/custom_components/immich_album_watcher/sensor.py +++ b/custom_components/immich_album_watcher/sensor.py @@ -94,14 +94,22 @@ async def async_setup_entry( platform.async_register_entity_service( SERVICE_GET_ASSETS, { - vol.Optional("count", default=10): vol.All( + vol.Optional("limit", default=10): vol.All( vol.Coerce(int), vol.Range(min=1, max=100) ), - vol.Optional("filter", default="none"): vol.In(["none", "favorite", "rating"]), + vol.Optional("favorite_only", default=False): bool, vol.Optional("filter_min_rating", default=1): vol.All( vol.Coerce(int), vol.Range(min=1, max=5) ), - vol.Optional("order", default="descending"): vol.In(["ascending", "descending", "random"]), + vol.Optional("order_by", default="date"): vol.In( + ["date", "rating", "name", "random"] + ), + vol.Optional("order", default="descending"): vol.In( + ["ascending", "descending"] + ), + vol.Optional("asset_type", default="all"): vol.In(["all", "photo", "video"]), + vol.Optional("min_date"): str, + vol.Optional("max_date"): str, }, "async_get_assets", supports_response=SupportsResponse.ONLY, @@ -124,6 +132,10 @@ async def async_setup_entry( vol.Coerce(int), vol.Range(min=0, max=60000) ), vol.Optional("wait_for_response", default=True): bool, + vol.Optional("max_asset_data_size"): vol.All( + vol.Coerce(int), vol.Range(min=1, max=52428800) + ), + vol.Optional("send_large_photos_as_documents", default=False): bool, }, "async_send_telegram_notification", supports_response=SupportsResponse.OPTIONAL, diff --git a/custom_components/immich_album_watcher/services.yaml b/custom_components/immich_album_watcher/services.yaml index bd53df9..24fea99 100644 --- a/custom_components/immich_album_watcher/services.yaml +++ b/custom_components/immich_album_watcher/services.yaml @@ -55,6 +55,8 @@ get_assets: value: "rating" - label: "Name" value: "name" + - label: "Random" + value: "random" order: name: Order description: Sort direction. @@ -67,8 +69,6 @@ get_assets: value: "ascending" - label: "Descending" value: "descending" - - label: "Random" - value: "random" asset_type: name: Asset Type description: Filter assets by type (all, photo, or video). diff --git a/custom_components/immich_album_watcher/translations/en.json b/custom_components/immich_album_watcher/translations/en.json index 6d01d81..22043ac 100644 --- a/custom_components/immich_album_watcher/translations/en.json +++ b/custom_components/immich_album_watcher/translations/en.json @@ -151,11 +151,11 @@ }, "order_by": { "name": "Order By", - "description": "Field to sort assets by (date, rating, or name)." + "description": "Field to sort assets by (date, rating, name, or random)." }, "order": { "name": "Order", - "description": "Sort direction (ascending, descending, or random)." + "description": "Sort direction (ascending or descending)." }, "asset_type": { "name": "Asset Type", diff --git a/custom_components/immich_album_watcher/translations/ru.json b/custom_components/immich_album_watcher/translations/ru.json index b13abad..1babce0 100644 --- a/custom_components/immich_album_watcher/translations/ru.json +++ b/custom_components/immich_album_watcher/translations/ru.json @@ -151,11 +151,11 @@ }, "order_by": { "name": "Сортировать по", - "description": "Поле для сортировки файлов (date - дата, rating - рейтинг, name - имя)." + "description": "Поле для сортировки файлов (date - дата, rating - рейтинг, name - имя, random - случайный)." }, "order": { "name": "Порядок", - "description": "Направление сортировки (ascending - по возрастанию, descending - по убыванию, random - случайный)." + "description": "Направление сортировки (ascending - по возрастанию, descending - по убыванию)." }, "asset_type": { "name": "Тип файла",