From 6e74b56649fd5b87701937d1802ea67c63ef4f6a Mon Sep 17 00:00:00 2001 From: marc7s <34547876+marc7s@users.noreply.github.com> Date: Thu, 22 May 2025 11:22:33 +0200 Subject: [PATCH] Catch invalid settings error in geocaching (#139944) Refactoring and preparation for other sensor types --- homeassistant/components/geocaching/coordinator.py | 6 +++++- homeassistant/components/geocaching/sensor.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/geocaching/coordinator.py b/homeassistant/components/geocaching/coordinator.py index fdf8f1340da..bfe82069650 100644 --- a/homeassistant/components/geocaching/coordinator.py +++ b/homeassistant/components/geocaching/coordinator.py @@ -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 diff --git a/homeassistant/components/geocaching/sensor.py b/homeassistant/components/geocaching/sensor.py index a8008229c91..5ceef21dfbf 100644 --- a/homeassistant/components/geocaching/sensor.py +++ b/homeassistant/components/geocaching/sensor.py @@ -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))},