mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +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 __future__ import annotations
|
||||||
|
|
||||||
from geocachingapi.exceptions import GeocachingApiError
|
from geocachingapi.exceptions import GeocachingApiError, GeocachingInvalidSettingsError
|
||||||
from geocachingapi.geocachingapi import GeocachingApi
|
from geocachingapi.geocachingapi import GeocachingApi
|
||||||
from geocachingapi.models import GeocachingStatus
|
from geocachingapi.models import GeocachingStatus
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ class GeocachingDataUpdateCoordinator(DataUpdateCoordinator[GeocachingStatus]):
|
|||||||
return str(token)
|
return str(token)
|
||||||
|
|
||||||
client_session = async_get_clientsession(hass)
|
client_session = async_get_clientsession(hass)
|
||||||
|
|
||||||
self.geocaching = GeocachingApi(
|
self.geocaching = GeocachingApi(
|
||||||
environment=ENVIRONMENT,
|
environment=ENVIRONMENT,
|
||||||
token=session.token["access_token"],
|
token=session.token["access_token"],
|
||||||
@ -55,7 +56,10 @@ class GeocachingDataUpdateCoordinator(DataUpdateCoordinator[GeocachingStatus]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def _async_update_data(self) -> GeocachingStatus:
|
async def _async_update_data(self) -> GeocachingStatus:
|
||||||
|
"""Fetch the latest Geocaching status."""
|
||||||
try:
|
try:
|
||||||
return await self.geocaching.update()
|
return await self.geocaching.update()
|
||||||
|
except GeocachingInvalidSettingsError as error:
|
||||||
|
raise UpdateFailed(f"Invalid integration configuration: {error}") from error
|
||||||
except GeocachingApiError as error:
|
except GeocachingApiError as error:
|
||||||
raise UpdateFailed(f"Invalid response from API: {error}") from error
|
raise UpdateFailed(f"Invalid response from API: {error}") from error
|
||||||
|
@ -93,6 +93,7 @@ class GeocachingSensor(
|
|||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
f"{coordinator.data.user.reference_code}_{description.key}"
|
f"{coordinator.data.user.reference_code}_{description.key}"
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
name=f"Geocaching {coordinator.data.user.username}",
|
name=f"Geocaching {coordinator.data.user.username}",
|
||||||
identifiers={(DOMAIN, cast(str, coordinator.data.user.reference_code))},
|
identifiers={(DOMAIN, cast(str, coordinator.data.user.reference_code))},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user