mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Make PEGELONLINE recoverable (#134199)
This commit is contained in:
parent
291dd6dc66
commit
394b2be40a
@ -5,10 +5,12 @@ from __future__ import annotations
|
||||
import logging
|
||||
|
||||
from aiopegelonline import PegelOnline
|
||||
from aiopegelonline.const import CONNECT_ERRORS
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import CONF_STATION
|
||||
@ -28,7 +30,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: PegelOnlineConfigEntry)
|
||||
_LOGGER.debug("Setting up station with uuid %s", station_uuid)
|
||||
|
||||
api = PegelOnline(async_get_clientsession(hass))
|
||||
station = await api.async_get_station_details(station_uuid)
|
||||
try:
|
||||
station = await api.async_get_station_details(station_uuid)
|
||||
except CONNECT_ERRORS as err:
|
||||
raise ConfigEntryNotReady("Failed to connect") from err
|
||||
|
||||
coordinator = PegelOnlineDataUpdateCoordinator(hass, entry.title, api, station)
|
||||
|
||||
|
@ -10,6 +10,7 @@ from homeassistant.components.pegel_online.const import (
|
||||
DOMAIN,
|
||||
MIN_TIME_BETWEEN_UPDATES,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import utcnow
|
||||
@ -24,6 +25,27 @@ from .const import (
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_setup_error(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Tests error during config entry setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=MOCK_CONFIG_ENTRY_DATA_DRESDEN,
|
||||
unique_id=MOCK_CONFIG_ENTRY_DATA_DRESDEN[CONF_STATION],
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
with patch("homeassistant.components.pegel_online.PegelOnline") as pegelonline:
|
||||
pegelonline.return_value = PegelOnlineMock(
|
||||
station_details=MOCK_STATION_DETAILS_DRESDEN,
|
||||
station_measurements=MOCK_STATION_MEASUREMENT_DRESDEN,
|
||||
)
|
||||
pegelonline().override_side_effect(ClientError("Boom"))
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_update_error(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user