Skip to content

Commit 944b434

Browse files
author
Arto Jantunen
committed
Retry new_data_cb() if data isn't available upstream
Using the already-used-elsewhere backoff library. Retry every 10 minutes for a maximum of two hours.
1 parent 72d3e16 commit 944b434

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

custom_components/nordpool/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22
from collections import defaultdict
3-
from datetime import datetime, timedelta
4-
from functools import partial
3+
from datetime import timedelta
54
from random import randint
65

6+
import backoff
77
import voluptuous as vol
88
from homeassistant.config_entries import ConfigEntry
99
from homeassistant.core import Config, HomeAssistant
@@ -143,6 +143,10 @@ async def new_hr(_):
143143
_LOGGER.debug("Called new_hr callback")
144144
async_dispatcher_send(hass, EVENT_NEW_HOUR)
145145

146+
@backoff.on_exception(
147+
backoff.constant,
148+
(InvalidValueException),
149+
logger=_LOGGER, interval=600, max_time=7200, jitter=None)
146150
async def new_data_cb(_):
147151
"""Callback to fetch new data for tomorrows prices at 1300ish CET
148152
and notify any sensors, about the new data

0 commit comments

Comments
 (0)