mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Handle additional errors in Nord Pool (#147937)
This commit is contained in:
parent
eb351e6505
commit
b816f1a408
@ -6,6 +6,7 @@ from collections.abc import Callable
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
from pynordpool import (
|
from pynordpool import (
|
||||||
Currency,
|
Currency,
|
||||||
DeliveryPeriodData,
|
DeliveryPeriodData,
|
||||||
@ -91,6 +92,8 @@ class NordPoolDataUpdateCoordinator(DataUpdateCoordinator[DeliveryPeriodsData]):
|
|||||||
except (
|
except (
|
||||||
NordPoolResponseError,
|
NordPoolResponseError,
|
||||||
NordPoolError,
|
NordPoolError,
|
||||||
|
TimeoutError,
|
||||||
|
aiohttp.ClientError,
|
||||||
) as error:
|
) as error:
|
||||||
LOGGER.debug("Connection error: %s", error)
|
LOGGER.debug("Connection error: %s", error)
|
||||||
self.async_set_update_error(error)
|
self.async_set_update_error(error)
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
from pynordpool import (
|
from pynordpool import (
|
||||||
NordPoolAuthenticationError,
|
NordPoolAuthenticationError,
|
||||||
@ -90,6 +91,36 @@ async def test_coordinator(
|
|||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
assert "Empty response" in caplog.text
|
assert "Empty response" in caplog.text
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period",
|
||||||
|
side_effect=aiohttp.ClientError("error"),
|
||||||
|
) as mock_data,
|
||||||
|
):
|
||||||
|
assert "Response error" not in caplog.text
|
||||||
|
freezer.tick(timedelta(hours=1))
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
assert mock_data.call_count == 1
|
||||||
|
state = hass.states.get("sensor.nord_pool_se3_current_price")
|
||||||
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
assert "error" in caplog.text
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period",
|
||||||
|
side_effect=TimeoutError("error"),
|
||||||
|
) as mock_data,
|
||||||
|
):
|
||||||
|
assert "Response error" not in caplog.text
|
||||||
|
freezer.tick(timedelta(hours=1))
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
assert mock_data.call_count == 1
|
||||||
|
state = hass.states.get("sensor.nord_pool_se3_current_price")
|
||||||
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
assert "error" in caplog.text
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period",
|
"homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period",
|
||||||
@ -109,4 +140,4 @@ async def test_coordinator(
|
|||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("sensor.nord_pool_se3_current_price")
|
state = hass.states.get("sensor.nord_pool_se3_current_price")
|
||||||
assert state.state == "1.81645"
|
assert state.state == "1.81983"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user