mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Catch invalid settings error in geocaching (#139944)
Refactoring and preparation for other sensor types
This commit is contained in:
parent
d35802a996
commit
6e74b56649
@ -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
|
||||
|
@ -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))},
|
||||
|
Loading…
x
Reference in New Issue
Block a user