Catch exception before retrying in AirGradient (#146460)

This commit is contained in:
Joost Lekkerkerker 2025-06-10 17:31:30 +02:00 committed by GitHub
parent 014010acbd
commit db8a6f8583
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View File

@ -51,9 +51,16 @@ class AirGradientCoordinator(DataUpdateCoordinator[AirGradientData]):
async def _async_setup(self) -> None:
"""Set up the coordinator."""
self._current_version = (
await self.client.get_current_measures()
).firmware_version
try:
self._current_version = (
await self.client.get_current_measures()
).firmware_version
except AirGradientError as error:
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="update_error",
translation_placeholders={"error": str(error)},
) from error
async def _async_update_data(self) -> AirGradientData:
try:

View File

@ -3,10 +3,12 @@
from datetime import timedelta
from unittest.mock import AsyncMock
from airgradient import AirGradientError
from freezegun.api import FrozenDateTimeFactory
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.airgradient.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -54,3 +56,16 @@ async def test_new_firmware_version(
)
assert device_entry is not None
assert device_entry.sw_version == "3.1.2"
async def test_setup_retry(
hass: HomeAssistant,
mock_airgradient_client: AsyncMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test retrying setup."""
mock_airgradient_client.get_current_measures.side_effect = AirGradientError()
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY