mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Catch exception before retrying in AirGradient (#146460)
This commit is contained in:
parent
014010acbd
commit
db8a6f8583
@ -51,9 +51,16 @@ class AirGradientCoordinator(DataUpdateCoordinator[AirGradientData]):
|
|||||||
|
|
||||||
async def _async_setup(self) -> None:
|
async def _async_setup(self) -> None:
|
||||||
"""Set up the coordinator."""
|
"""Set up the coordinator."""
|
||||||
|
try:
|
||||||
self._current_version = (
|
self._current_version = (
|
||||||
await self.client.get_current_measures()
|
await self.client.get_current_measures()
|
||||||
).firmware_version
|
).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:
|
async def _async_update_data(self) -> AirGradientData:
|
||||||
try:
|
try:
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from airgradient import AirGradientError
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.airgradient.const import DOMAIN
|
from homeassistant.components.airgradient.const import DOMAIN
|
||||||
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
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 is not None
|
||||||
assert device_entry.sw_version == "3.1.2"
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user