* 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
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
"""Configure py.test."""
|
|
import json
|
|
from unittest.mock import PropertyMock, patch
|
|
|
|
import pytest
|
|
|
|
from tests.common import load_fixture
|
|
|
|
|
|
@pytest.fixture(name="tomorrowio_config_flow_connect", autouse=True)
|
|
def tomorrowio_config_flow_connect():
|
|
"""Mock valid tomorrowio config flow setup."""
|
|
with patch(
|
|
"homeassistant.components.tomorrowio.config_flow.TomorrowioV4.realtime",
|
|
return_value={},
|
|
):
|
|
yield
|
|
|
|
|
|
@pytest.fixture(name="tomorrowio_config_entry_update", autouse=True)
|
|
def tomorrowio_config_entry_update_fixture():
|
|
"""Mock valid tomorrowio config entry setup."""
|
|
with patch(
|
|
"homeassistant.components.tomorrowio.TomorrowioV4.realtime_and_all_forecasts",
|
|
return_value=json.loads(load_fixture("v4.json", "tomorrowio")),
|
|
) 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")
|
|
def climacell_config_entry_update_fixture():
|
|
"""Mock valid climacell config entry setup."""
|
|
with patch(
|
|
"homeassistant.components.climacell.ClimaCellV3.realtime",
|
|
return_value={},
|
|
), patch(
|
|
"homeassistant.components.climacell.ClimaCellV3.forecast_hourly",
|
|
return_value={},
|
|
), patch(
|
|
"homeassistant.components.climacell.ClimaCellV3.forecast_daily",
|
|
return_value={},
|
|
), patch(
|
|
"homeassistant.components.climacell.ClimaCellV3.forecast_nowcast",
|
|
return_value={},
|
|
):
|
|
yield
|