Catch invalid settings error in geocaching (#139944)

Refactoring and preparation for other sensor types
This commit is contained in:
marc7s 2025-05-22 11:22:33 +02:00 committed by GitHub
parent d35802a996
commit 6e74b56649
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -2,7 +2,7 @@
from __future__ import annotations
from geocachingapi.exceptions import GeocachingApiError
from geocachingapi.exceptions import GeocachingApiError, GeocachingInvalidSettingsError
from geocachingapi.geocachingapi import GeocachingApi
from geocachingapi.models import GeocachingStatus
@ -39,6 +39,7 @@ class GeocachingDataUpdateCoordinator(DataUpdateCoordinator[GeocachingStatus]):
return str(token)
client_session = async_get_clientsession(hass)
self.geocaching = GeocachingApi(
environment=ENVIRONMENT,
token=session.token["access_token"],
@ -55,7 +56,10 @@ class GeocachingDataUpdateCoordinator(DataUpdateCoordinator[GeocachingStatus]):
)
async def _async_update_data(self) -> GeocachingStatus:
"""Fetch the latest Geocaching status."""
try:
return await self.geocaching.update()
except GeocachingInvalidSettingsError as error:
raise UpdateFailed(f"Invalid integration configuration: {error}") from error
except GeocachingApiError as error:
raise UpdateFailed(f"Invalid response from API: {error}") from error

View File

@ -93,6 +93,7 @@ class GeocachingSensor(
self._attr_unique_id = (
f"{coordinator.data.user.reference_code}_{description.key}"
)
self._attr_device_info = DeviceInfo(
name=f"Geocaching {coordinator.data.user.username}",
identifiers={(DOMAIN, cast(str, coordinator.data.user.reference_code))},