mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Handle additional errors in Nord Pool (#147937)
This commit is contained in:
parent
7ff90ca49d
commit
73251fbb1c
@ -6,6 +6,7 @@ from collections.abc import Callable
|
||||
from datetime import datetime, timedelta
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import aiohttp
|
||||
from pynordpool import (
|
||||
Currency,
|
||||
DeliveryPeriodData,
|
||||
@ -91,6 +92,8 @@ class NordPoolDataUpdateCoordinator(DataUpdateCoordinator[DeliveryPeriodsData]):
|
||||
except (
|
||||
NordPoolResponseError,
|
||||
NordPoolError,
|
||||
TimeoutError,
|
||||
aiohttp.ClientError,
|
||||
) as error:
|
||||
LOGGER.debug("Connection error: %s", error)
|
||||
self.async_set_update_error(error)
|
||||
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
import aiohttp
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from pynordpool import (
|
||||
NordPoolAuthenticationError,
|
||||
@ -90,6 +91,36 @@ async def test_coordinator(
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
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 (
|
||||
patch(
|
||||
"homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period",
|
||||
@ -109,4 +140,4 @@ async def test_coordinator(
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
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