From b679295373d821e5b4e11f82f9cf604821213f34 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Wed, 13 May 2026 21:28:46 +0000 Subject: [PATCH] Restore options flow test --- tests/components/min_max/test_config_flow.py | 73 ++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/components/min_max/test_config_flow.py b/tests/components/min_max/test_config_flow.py index 76af3adcf2c2..2a8518653144 100644 --- a/tests/components/min_max/test_config_flow.py +++ b/tests/components/min_max/test_config_flow.py @@ -1,10 +1,14 @@ """Test the Min/Max config flow.""" +import pytest + from homeassistant import config_entries from homeassistant.components.min_max.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from tests.common import MockConfigEntry, get_schema_suggested_value + async def test_config_flow_aborts(hass: HomeAssistant) -> None: """Test the config flow aborts.""" @@ -14,3 +18,72 @@ async def test_config_flow_aborts(hass: HomeAssistant) -> None: ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "migrated_to_groups" + + +@pytest.mark.parametrize("platform", ["sensor"]) +async def test_options(hass: HomeAssistant, platform: str) -> None: + """Test reconfiguring.""" + hass.states.async_set("sensor.input_one", "10") + hass.states.async_set("sensor.input_two", "20") + hass.states.async_set("sensor.input_three", "33.33") + + input_sensors1 = ["sensor.input_one", "sensor.input_two"] + input_sensors2 = ["sensor.input_one", "sensor.input_two", "sensor.input_three"] + + # Setup the config entry + config_entry = MockConfigEntry( + data={}, + domain=DOMAIN, + options={ + "entity_ids": input_sensors1, + "name": "My min_max", + "round_digits": 0, + "type": "min", + }, + title="My min_max", + ) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + result = await hass.config_entries.options.async_init(config_entry.entry_id) + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "init" + schema = result["data_schema"].schema + assert get_schema_suggested_value(schema, "entity_ids") == input_sensors1 + assert get_schema_suggested_value(schema, "round_digits") == 0 + assert get_schema_suggested_value(schema, "type") == "min" + + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={ + "entity_ids": input_sensors2, + "round_digits": 1, + "type": "mean", + }, + ) + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["data"] == { + "entity_ids": input_sensors2, + "name": "My min_max", + "round_digits": 1, + "type": "mean", + } + assert config_entry.data == {} + assert config_entry.options == { + "entity_ids": input_sensors2, + "name": "My min_max", + "round_digits": 1, + "type": "mean", + } + assert config_entry.title == "My min_max" + + # Check config entry is reloaded with new options + await hass.async_block_till_done() + + # Check the entity was updated, no new entity was created + assert len(hass.states.async_all()) == 4 + + # Check the state of the entity has changed as expected + state = hass.states.get(f"{platform}.my_min_max") + assert state.state == "21.1"