mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Spread the load on the Tibber server (#40797)
* Tibber, Spread the load on the server * start hour
This commit is contained in:
parent
473afc4837
commit
16d5c145a9
@ -2,6 +2,7 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from random import randrange
|
||||
|
||||
import aiohttp
|
||||
|
||||
@ -59,6 +60,7 @@ class TibberSensor(Entity):
|
||||
self._name = tibber_home.info["viewer"]["home"]["address"].get(
|
||||
"address1", ""
|
||||
)
|
||||
self._spread_load_constant = randrange(3600)
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
@ -110,7 +112,8 @@ class TibberSensorElPrice(TibberSensor):
|
||||
|
||||
if (
|
||||
not self._tibber_home.last_data_timestamp
|
||||
or (self._tibber_home.last_data_timestamp - now).total_seconds() / 3600 < 12
|
||||
or (self._tibber_home.last_data_timestamp - now).total_seconds()
|
||||
< 12 * 3600 + self._spread_load_constant
|
||||
or not self._is_available
|
||||
):
|
||||
_LOGGER.debug("Asking for new data")
|
||||
@ -156,6 +159,7 @@ class TibberSensorElPrice(TibberSensor):
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
async def _fetch_data(self):
|
||||
_LOGGER.debug("Fetching data")
|
||||
try:
|
||||
await self._tibber_home.update_info_and_price_info()
|
||||
except (asyncio.TimeoutError, aiohttp.ClientError):
|
||||
|
Loading…
x
Reference in New Issue
Block a user