mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17: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
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from random import randrange
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ class TibberSensor(Entity):
|
|||||||
self._name = tibber_home.info["viewer"]["home"]["address"].get(
|
self._name = tibber_home.info["viewer"]["home"]["address"].get(
|
||||||
"address1", ""
|
"address1", ""
|
||||||
)
|
)
|
||||||
|
self._spread_load_constant = randrange(3600)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
@ -110,7 +112,8 @@ class TibberSensorElPrice(TibberSensor):
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
not self._tibber_home.last_data_timestamp
|
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
|
or not self._is_available
|
||||||
):
|
):
|
||||||
_LOGGER.debug("Asking for new data")
|
_LOGGER.debug("Asking for new data")
|
||||||
@ -156,6 +159,7 @@ class TibberSensorElPrice(TibberSensor):
|
|||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
async def _fetch_data(self):
|
async def _fetch_data(self):
|
||||||
|
_LOGGER.debug("Fetching data")
|
||||||
try:
|
try:
|
||||||
await self._tibber_home.update_info_and_price_info()
|
await self._tibber_home.update_info_and_price_info()
|
||||||
except (asyncio.TimeoutError, aiohttp.ClientError):
|
except (asyncio.TimeoutError, aiohttp.ClientError):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user