diff --git a/custom_components/nordpool/aio_price.py b/custom_components/nordpool/aio_price.py index fc0ec8f..39d84d2 100644 --- a/custom_components/nordpool/aio_price.py +++ b/custom_components/nordpool/aio_price.py @@ -5,6 +5,8 @@ from dateutil import tz from dateutil.parser import parse as parse_dt +import backoff +import aiohttp from nordpool.elspot import Prices from .misc import add_junk @@ -177,6 +179,7 @@ async def _fetch_json(self, data_type, end_date=None): endDate=end_date.strftime("%d-%m-%Y"), ) + @backoff.on_exception(backoff.expo, (aiohttp.ClientError, KeyError), logger=_LOGGER) async def fetch(self, data_type, end_date=None, areas=None): """ Fetch data from API. @@ -201,6 +204,8 @@ async def fetch(self, data_type, end_date=None, areas=None): if areas is None: areas = [] + raise KeyError + # now = datetime.utcnow() # timezone_for_data = now.astimezone(tz.gettz(ts)) # stock = datetime.utcnow().astimezone(tz.gettz("Europe/Stockholm")) diff --git a/custom_components/nordpool/manifest.json b/custom_components/nordpool/manifest.json index c148264..350b7ca 100644 --- a/custom_components/nordpool/manifest.json +++ b/custom_components/nordpool/manifest.json @@ -13,7 +13,8 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/custom-components/nordpool/issues", "requirements": [ - "nordpool>=0.2" + "nordpool>=0.2", + "backoff" ], "version": "0.0.11" -} +} \ No newline at end of file