mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Increase update interval in AccuWeather integration (#44984)
This commit is contained in:
parent
e46f1c0a10
commit
14f5eb7305
@ -100,13 +100,13 @@ class AccuWeatherDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
self.accuweather = AccuWeather(api_key, session, location_key=self.location_key)
|
self.accuweather = AccuWeather(api_key, session, location_key=self.location_key)
|
||||||
|
|
||||||
# Enabling the forecast download increases the number of requests per data
|
# Enabling the forecast download increases the number of requests per data
|
||||||
# update, we use 32 minutes for current condition only and 64 minutes for
|
# update, we use 40 minutes for current condition only and 80 minutes for
|
||||||
# current condition and forecast as update interval to not exceed allowed number
|
# current condition and forecast as update interval to not exceed allowed number
|
||||||
# of requests. We have 50 requests allowed per day, so we use 45 and leave 5 as
|
# of requests. We have 50 requests allowed per day, so we use 36 and leave 14 as
|
||||||
# a reserve for restarting HA.
|
# a reserve for restarting HA.
|
||||||
update_interval = (
|
update_interval = timedelta(minutes=40)
|
||||||
timedelta(minutes=64) if self.forecast else timedelta(minutes=32)
|
if self.forecast:
|
||||||
)
|
update_interval *= 2
|
||||||
_LOGGER.debug("Data will be update every %s", update_interval)
|
_LOGGER.debug("Data will be update every %s", update_interval)
|
||||||
|
|
||||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)
|
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "AccuWeather Options",
|
"title": "AccuWeather Options",
|
||||||
"description": "Due to the limitations of the free version of the AccuWeather API key, when you enable weather forecast, data updates will be performed every 64 minutes instead of every 32 minutes.",
|
"description": "Due to the limitations of the free version of the AccuWeather API key, when you enable weather forecast, data updates will be performed every 80 minutes instead of every 40 minutes.",
|
||||||
"data": {
|
"data": {
|
||||||
"forecast": "Weather forecast"
|
"forecast": "Weather forecast"
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
"""Test init of AccuWeather integration."""
|
"""Test init of AccuWeather integration."""
|
||||||
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.accuweather.const import DOMAIN
|
from accuweather import ApiError
|
||||||
|
|
||||||
|
from homeassistant.components.accuweather.const import COORDINATOR, DOMAIN
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
ENTRY_STATE_LOADED,
|
ENTRY_STATE_LOADED,
|
||||||
ENTRY_STATE_NOT_LOADED,
|
ENTRY_STATE_NOT_LOADED,
|
||||||
@ -39,7 +42,7 @@ async def test_config_not_ready(hass):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.accuweather.AccuWeather._async_get_data",
|
"homeassistant.components.accuweather.AccuWeather._async_get_data",
|
||||||
side_effect=ConnectionError(),
|
side_effect=ApiError("API Error"),
|
||||||
):
|
):
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
@ -58,3 +61,23 @@ async def test_unload_entry(hass):
|
|||||||
|
|
||||||
assert entry.state == ENTRY_STATE_NOT_LOADED
|
assert entry.state == ENTRY_STATE_NOT_LOADED
|
||||||
assert not hass.data.get(DOMAIN)
|
assert not hass.data.get(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_interval(hass):
|
||||||
|
"""Test correct update interval."""
|
||||||
|
entry = await init_integration(hass)
|
||||||
|
|
||||||
|
assert entry.state == ENTRY_STATE_LOADED
|
||||||
|
assert hass.data[DOMAIN][entry.entry_id][COORDINATOR].update_interval == timedelta(
|
||||||
|
minutes=40
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_interval_forecast(hass):
|
||||||
|
"""Test correct update interval when forecast is True."""
|
||||||
|
entry = await init_integration(hass, forecast=True)
|
||||||
|
|
||||||
|
assert entry.state == ENTRY_STATE_LOADED
|
||||||
|
assert hass.data[DOMAIN][entry.entry_id][COORDINATOR].update_interval == timedelta(
|
||||||
|
minutes=80
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user