mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Translate UpdateFailed exception in PEGELONLINE (#131380)
translate UpdateFailed exception
This commit is contained in:
parent
fa1b7d73d5
commit
7b70f2d83b
@ -7,7 +7,7 @@ from aiopegelonline import CONNECT_ERRORS, PegelOnline, Station, StationMeasurem
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import MIN_TIME_BETWEEN_UPDATES
|
||||
from .const import DOMAIN, MIN_TIME_BETWEEN_UPDATES
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -33,4 +33,8 @@ class PegelOnlineDataUpdateCoordinator(DataUpdateCoordinator[StationMeasurements
|
||||
try:
|
||||
return await self.api.async_get_station_measurements(self.station.uuid)
|
||||
except CONNECT_ERRORS as err:
|
||||
raise UpdateFailed(f"Failed to communicate with API: {err}") from err
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="communication_error",
|
||||
translation_placeholders={"error": str(err)},
|
||||
) from err
|
||||
|
@ -48,5 +48,10 @@
|
||||
"name": "Water temperature"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"communication_error": {
|
||||
"message": "Failed to communicate with API: {error}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.pegel_online.const import (
|
||||
CONF_STATION,
|
||||
@ -23,7 +24,9 @@ from .const import (
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_update_error(hass: HomeAssistant) -> None:
|
||||
async def test_update_error(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Tests error during update entity."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@ -43,9 +46,11 @@ async def test_update_error(hass: HomeAssistant) -> None:
|
||||
state = hass.states.get("sensor.dresden_elbe_water_level")
|
||||
assert state
|
||||
|
||||
pegelonline().override_side_effect(ClientError)
|
||||
pegelonline().override_side_effect(ClientError("Boom"))
|
||||
async_fire_time_changed(hass, utcnow() + MIN_TIME_BETWEEN_UPDATES)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "Failed to communicate with API: Boom" in caplog.text
|
||||
|
||||
state = hass.states.get("sensor.dresden_elbe_water_level")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
Loading…
x
Reference in New Issue
Block a user