1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-14 23:28:42 +00:00

Add missing exception translations in immich (#162889)

This commit is contained in:
Michael
2026-02-12 22:32:22 +01:00
committed by GitHub
parent acf739df81
commit fdf02cf657
6 changed files with 49 additions and 12 deletions

View File

@@ -51,9 +51,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ImmichConfigEntry) -> bo
try:
user_info = await immich.users.async_get_my_user()
except ImmichUnauthorizedError as err:
raise ConfigEntryAuthFailed from err
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_error",
) from err
except CONNECT_ERRORS as err:
raise ConfigEntryNotReady from err
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="cannot_connect",
) from err
coordinator = ImmichDataUpdateCoordinator(hass, entry, immich, user_info.is_admin)
await coordinator.async_config_entry_first_refresh()

View File

@@ -80,9 +80,16 @@ class ImmichDataUpdateCoordinator(DataUpdateCoordinator[ImmichData]):
else None
)
except ImmichUnauthorizedError as err:
raise ConfigEntryAuthFailed from err
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_error",
) from err
except CONNECT_ERRORS as err:
raise UpdateFailed from err
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="update_error",
translation_placeholders={"error": repr(err)},
) from err
return ImmichData(
server_about, server_storage, server_usage, server_version_check

View File

@@ -64,7 +64,9 @@ class ImmichMediaSource(MediaSource):
) -> BrowseMediaSource:
"""Return media."""
if not (entries := self.hass.config_entries.async_loaded_entries(DOMAIN)):
raise BrowseError("Immich is not configured")
raise BrowseError(
translation_domain=DOMAIN, translation_key="not_configured"
)
return BrowseMediaSource(
domain=DOMAIN,
identifier=None,
@@ -282,12 +284,16 @@ class ImmichMediaSource(MediaSource):
identifier = ImmichMediaSourceIdentifier(item.identifier)
except IndexError as err:
raise Unresolvable(
f"Could not parse identifier: {item.identifier}"
translation_domain=DOMAIN,
translation_key="identifier_unresolvable",
translation_placeholders={"identifier": item.identifier},
) from err
if identifier.mime_type is None:
raise Unresolvable(
f"Could not resolve identifier that has no mime-type: {item.identifier}"
translation_domain=DOMAIN,
translation_key="identifier_no_mime_type_unresolvable",
translation_placeholders={"identifier": item.identifier},
)
return PlayMedia(

View File

@@ -60,7 +60,7 @@ rules:
entity-device-class: done
entity-disabled-by-default: done
entity-translations: done
exception-translations: todo
exception-translations: done
icon-translations: done
reconfiguration-flow: todo
repair-issues:

View File

@@ -79,9 +79,27 @@
"album_not_found": {
"message": "Album with ID `{album_id}` not found ({error})."
},
"auth_error": {
"message": "Authentication failed, please update your API key"
},
"cannot_connect": {
"message": "Cannot connect to your Immich instance."
},
"identifier_no_mime_type_unresolvable": {
"message": "Could not resolve identifier that has no mime-type: {identifier}"
},
"identifier_unresolvable": {
"message": "Could not parse identifier: {identifier}"
},
"not_configured": {
"message": "Immich is not configured."
},
"only_local_media_supported": {
"message": "Only local media files are currently supported."
},
"update_error": {
"message": "An error occurred while retrieving data from your Immich instance: {error}"
},
"upload_failed": {
"message": "Upload of file `{file}` failed ({error})."
}

View File

@@ -37,14 +37,14 @@ async def test_get_media_source(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
("identifier", "exception_msg"),
[
("unique_id", "Could not resolve identifier that has no mime-type"),
("unique_id", "identifier_no_mime_type_unresolvable"),
(
"unique_id|albums|album_id",
"Could not resolve identifier that has no mime-type",
"identifier_no_mime_type_unresolvable",
),
(
"unique_id|albums|album_id|asset_id|filename",
"Could not parse identifier",
"identifier_unresolvable",
),
],
)
@@ -102,7 +102,7 @@ async def test_browse_media_unconfigured(hass: HomeAssistant) -> None:
item = MediaSourceItem(
hass, DOMAIN, "unique_id/albums/album_id/asset_id/filename.png", None
)
with pytest.raises(BrowseError, match="Immich is not configured"):
with pytest.raises(BrowseError, match="not_configured"):
await source.async_browse_media(item)