Create test that shows options not being updated

This commit is contained in:
Tsvi Mostovicz
2024-06-02 08:53:17 +00:00
parent 54a1a4ab41
commit c790d4e486

View File

@@ -1,5 +1,6 @@
"""Test the Jewish calendar config flow."""
from datetime import timedelta
from unittest.mock import AsyncMock
import pytest
@@ -27,8 +28,9 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, async_fire_time_changed
async def test_step_user(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
@@ -137,3 +139,44 @@ async def test_options(hass: HomeAssistant, mock_config_entry: MockConfigEntry)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"][CONF_CANDLE_LIGHT_MINUTES] == 25
assert result["data"][CONF_HAVDALAH_OFFSET_MINUTES] == 34
async def test_options_updates_sensors(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None:
"""Test that updating the options of the Jewish Calendar integration triggers a value update."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
future = dt_util.utcnow() + timedelta(seconds=30)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
# Get the value of the "upcoming_shabbat_candle_lighting" sensor
initial_sensor_value = hass.states.get(
"sensor.jewish_calendar_upcoming_shabbat_candle_lighting"
).state
initial_sensor_value = dt_util.parse_datetime(initial_sensor_value)
# Update the CONF_CANDLE_LIGHT_MINUTES option to a new value
result = await hass.config_entries.options.async_init(mock_config_entry.entry_id)
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
CONF_CANDLE_LIGHT_MINUTES: DEFAULT_CANDLE_LIGHT + 1,
},
)
future = dt_util.utcnow() + timedelta(seconds=30)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
# The sensor value should have changed to be one minute later
new_sensor_value = hass.states.get(
"sensor.jewish_calendar_upcoming_shabbat_candle_lighting"
).state
new_sensor_value = dt_util.parse_datetime(new_sensor_value)
# Verify that the new sensor value is one minute later
assert new_sensor_value - initial_sensor_value == timedelta(minutes=1)