55from datetime import timedelta
66from unittest .mock import patch
77
8+ import aiohttp
89from freezegun .api import FrozenDateTimeFactory
910from pynordpool import (
1011 NordPoolAuthenticationError ,
@@ -90,6 +91,36 @@ async def test_coordinator(
9091 assert state .state == STATE_UNAVAILABLE
9192 assert "Empty response" in caplog .text
9293
94+ with (
95+ patch (
96+ "homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period" ,
97+ side_effect = aiohttp .ClientError ("error" ),
98+ ) as mock_data ,
99+ ):
100+ assert "Response error" not in caplog .text
101+ freezer .tick (timedelta (hours = 1 ))
102+ async_fire_time_changed (hass )
103+ await hass .async_block_till_done (wait_background_tasks = True )
104+ assert mock_data .call_count == 1
105+ state = hass .states .get ("sensor.nord_pool_se3_current_price" )
106+ assert state .state == STATE_UNAVAILABLE
107+ assert "error" in caplog .text
108+
109+ with (
110+ patch (
111+ "homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period" ,
112+ side_effect = TimeoutError ("error" ),
113+ ) as mock_data ,
114+ ):
115+ assert "Response error" not in caplog .text
116+ freezer .tick (timedelta (hours = 1 ))
117+ async_fire_time_changed (hass )
118+ await hass .async_block_till_done (wait_background_tasks = True )
119+ assert mock_data .call_count == 1
120+ state = hass .states .get ("sensor.nord_pool_se3_current_price" )
121+ assert state .state == STATE_UNAVAILABLE
122+ assert "error" in caplog .text
123+
93124 with (
94125 patch (
95126 "homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period" ,
@@ -109,4 +140,4 @@ async def test_coordinator(
109140 async_fire_time_changed (hass )
110141 await hass .async_block_till_done ()
111142 state = hass .states .get ("sensor.nord_pool_se3_current_price" )
112- assert state .state == "1.81645 "
143+ assert state .state == "1.81983 "
0 commit comments