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