Skip to content

Commit b0d4760

Browse files
author
Arto Jantunen
committed
Retry polling for new data hourly if needed
And this should fix the other side of issue #326 (the lack of retries if data is not available at the usual polling time).
1 parent e2a3429 commit b0d4760

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

custom_components/nordpool/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from .aio_price import AioPrices
1717
from .events import async_track_time_change_in_tz
18+
from .misc import stock
1819

1920
DOMAIN = "nordpool"
2021
_LOGGER = logging.getLogger(__name__)
@@ -153,10 +154,18 @@ async def new_day_cb(_):
153154

154155
async_dispatcher_send(hass, EVENT_NEW_DAY)
155156

156-
async def new_hr(_):
157-
"""Callback to tell the sensors to update on a new hour."""
157+
async def new_hr(tdo):
158+
"""Callback to tell the sensors to update on a new hour.
159+
and poll data if needed.
160+
"""
158161
_LOGGER.debug("Called new_hr callback")
159162
async_dispatcher_send(hass, EVENT_NEW_HOUR)
163+
if not api.tomorrow_valid_all_areas():
164+
now = stock(dt_utils.now())
165+
if now >= now.replace(
166+
hour=13, minute=RANDOM_MINUTE, second=RANDOM_SECOND
167+
):
168+
new_data_cb(tdo)
160169

161170
async def new_data_cb(tdo):
162171
"""Callback to fetch new data for tomorrows prices at 1300ish CET

0 commit comments

Comments
 (0)