Make tomorrowio API rate limit handling more robust (#70412)
* Use the max request limit when setting tomorrowio update interval * tests * reduce lines * simplify * refactor * Make Coordinator.async_setup_entry more efficient at determining when to refresh data and schedule refresh * clean up * clean up * Remove unnecessary type definition * typo * fix logic ot be more deterministic * Another fix * Comment * Reduce wasted API calls by doing partial updates when new entries get added with a new key * Simplify and use asyncio event so that config entries only load after initial coordinator refresh * Remove commented out piece * Comment * Remove unnecessary variable * More cleanup * Make future merge easier * remove dupe * switch order * add comment * Remove unnecessary error handling * make code easier to read * review feedback for code * Fix logic * Update test based on review * Tweak comments * reset mock so asertions are more clear * Remove update interval check
This commit is contained in:
parent
237ef6419b
commit
92be8b4f8e
5 changed files with 231 additions and 107 deletions
|
@ -1,6 +1,6 @@
|
|||
"""Configure py.test."""
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -23,8 +23,16 @@ def tomorrowio_config_entry_update_fixture():
|
|||
with patch(
|
||||
"homeassistant.components.tomorrowio.TomorrowioV4.realtime_and_all_forecasts",
|
||||
return_value=json.loads(load_fixture("v4.json", "tomorrowio")),
|
||||
):
|
||||
yield
|
||||
) as mock_update, patch(
|
||||
"homeassistant.components.tomorrowio.TomorrowioV4.max_requests_per_day",
|
||||
new_callable=PropertyMock,
|
||||
) as mock_max_requests_per_day, patch(
|
||||
"homeassistant.components.tomorrowio.TomorrowioV4.num_api_requests",
|
||||
new_callable=PropertyMock,
|
||||
) as mock_num_api_requests:
|
||||
mock_max_requests_per_day.return_value = 100
|
||||
mock_num_api_requests.return_value = 2
|
||||
yield mock_update
|
||||
|
||||
|
||||
@pytest.fixture(name="climacell_config_entry_update")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue