mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Use freezegun in pvpc_hourly_pricing tests (#99040)
This commit is contained in:
parent
c827af5826
commit
452caee41a
@ -1,7 +1,7 @@
|
||||
"""Tests for the pvpc_hourly_pricing config_flow."""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from freezegun import freeze_time
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.pvpc_hourly_pricing import (
|
||||
@ -25,7 +25,9 @@ _MOCK_TIME_VALID_RESPONSES = datetime(2023, 1, 6, 12, 0, tzinfo=dt_util.UTC)
|
||||
|
||||
|
||||
async def test_config_flow(
|
||||
hass: HomeAssistant, pvpc_aioclient_mock: AiohttpClientMocker
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
pvpc_aioclient_mock: AiohttpClientMocker,
|
||||
) -> None:
|
||||
"""Test config flow for pvpc_hourly_pricing.
|
||||
|
||||
@ -35,6 +37,7 @@ async def test_config_flow(
|
||||
- Check removal and add again to check state restoration
|
||||
- Configure options to change power and tariff to "2.0TD"
|
||||
"""
|
||||
freezer.move_to(_MOCK_TIME_VALID_RESPONSES)
|
||||
hass.config.set_time_zone("Europe/Madrid")
|
||||
tst_config = {
|
||||
CONF_NAME: "test",
|
||||
@ -43,7 +46,6 @@ async def test_config_flow(
|
||||
ATTR_POWER_P3: 5.75,
|
||||
}
|
||||
|
||||
with freeze_time(_MOCK_TIME_VALID_RESPONSES) as mock_time:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
@ -116,9 +118,8 @@ async def test_config_flow(
|
||||
assert state.attributes["available_power"] == 4600
|
||||
|
||||
# check update failed
|
||||
ts_future = _MOCK_TIME_VALID_RESPONSES + timedelta(days=1)
|
||||
mock_time.move_to(ts_future)
|
||||
async_fire_time_changed(hass, ts_future)
|
||||
freezer.tick(timedelta(days=1))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test")
|
||||
check_valid_state(state, tariff=TARIFFS[0], value="unavailable")
|
||||
|
Loading…
x
Reference in New Issue
Block a user