File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 1111_HEADER_API_KEY = "x-api-key"
1212_LOGGER = logging .getLogger (__name__ )
1313
14+ _ALLOWED_MIME_TYPES = ["image/png" , "image/jpeg" ]
15+
1416
1517class ImmichHub :
1618 """Immich API hub."""
@@ -65,7 +67,7 @@ async def get_my_user_info(self) -> dict:
6567 _LOGGER .error ("Error connecting to the API: %s" , exception )
6668 raise CannotConnect from exception
6769
68- async def download_asset (self , asset_id : str ) -> bytes :
70+ async def download_asset (self , asset_id : str ) -> bytes | None :
6971 """Download the asset."""
7072 try :
7173 async with aiohttp .ClientSession () as session :
@@ -75,7 +77,13 @@ async def download_asset(self, asset_id: str) -> bytes:
7577 async with session .get (url = url , headers = headers ) as response :
7678 if response .status != 200 :
7779 _LOGGER .error ("Error from API: status=%d" , response .status )
78- raise ApiError ()
80+ return None
81+
82+ if response .content_type not in _ALLOWED_MIME_TYPES :
83+ _LOGGER .error (
84+ "MIME type is not supported: %s" , response .content_type
85+ )
86+ return None
7987
8088 return await response .read ()
8189 except aiohttp .ClientError as exception :
Original file line number Diff line number Diff line change 11"""Image device for Immich integration."""
22from __future__ import annotations
33
4+ import asyncio
45from datetime import datetime , timedelta
56import logging
67import random
@@ -113,10 +114,20 @@ async def _get_next_asset_id(self) -> str | None:
113114
114115 async def _load_and_cache_next_image (self ) -> None :
115116 """Download and cache the image."""
116- asset_id = await self ._get_next_asset_id ()
117+ asset_bytes = None
118+
119+ while not asset_bytes :
120+ asset_id = await self ._get_next_asset_id ()
121+
122+ if not asset_id :
123+ return
117124
118- if asset_id :
119125 asset_bytes = await self .hub .download_asset (asset_id )
126+
127+ if not asset_bytes :
128+ await asyncio .sleep (1 )
129+ continue
130+
120131 self ._current_image_bytes = asset_bytes
121132 self ._attr_image_last_updated = datetime .now ()
122133
Original file line number Diff line number Diff line change 1010 "issue_tracker" : " https://github.com/outadoc/immich-home-assistant/issues" ,
1111 "requirements" : [" url-normalize==1.4.3" ],
1212 "ssdp" : [],
13- "version" : " 0.1 .0" ,
13+ "version" : " 0.2 .0" ,
1414 "zeroconf" : []
1515}
You can’t perform that action at this time.
0 commit comments