Skip to content

Commit 16d5c14

Browse files
Spread the load on the Tibber server (home-assistant#40797)
* Tibber, Spread the load on the server * start hour
1 parent 473afc4 commit 16d5c14

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

homeassistant/components/tibber/sensor.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
from datetime import timedelta
44
import logging
5+
from random import randrange
56

67
import aiohttp
78

@@ -59,6 +60,7 @@ def __init__(self, tibber_home):
5960
self._name = tibber_home.info["viewer"]["home"]["address"].get(
6061
"address1", ""
6162
)
63+
self._spread_load_constant = randrange(3600)
6264

6365
@property
6466
def device_state_attributes(self):
@@ -110,7 +112,8 @@ async def async_update(self):
110112

111113
if (
112114
not self._tibber_home.last_data_timestamp
113-
or (self._tibber_home.last_data_timestamp - now).total_seconds() / 3600 < 12
115+
or (self._tibber_home.last_data_timestamp - now).total_seconds()
116+
< 12 * 3600 + self._spread_load_constant
114117
or not self._is_available
115118
):
116119
_LOGGER.debug("Asking for new data")
@@ -156,6 +159,7 @@ def unique_id(self):
156159

157160
@Throttle(MIN_TIME_BETWEEN_UPDATES)
158161
async def _fetch_data(self):
162+
_LOGGER.debug("Fetching data")
159163
try:
160164
await self._tibber_home.update_info_and_price_info()
161165
except (asyncio.TimeoutError, aiohttp.ClientError):

0 commit comments

Comments
 (0)