Fix the services API
All checks were successful
Validate / Hassfest (push) Successful in 3s

This commit is contained in:
2026-02-01 02:22:52 +03:00
parent 4b0f3b8b12
commit ee45fdc177
7 changed files with 46 additions and 36 deletions

View File

@@ -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:

View File

@@ -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]

View File

@@ -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"
}

View File

@@ -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,

View File

@@ -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).

View File

@@ -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",

View File

@@ -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": "Тип файла",