diff --git a/homeassistant/components/openuv/config_flow.py b/homeassistant/components/openuv/config_flow.py index 2e96ce7c292..8852ed677cd 100644 --- a/homeassistant/components/openuv/config_flow.py +++ b/homeassistant/components/openuv/config_flow.py @@ -200,7 +200,7 @@ class OpenUvOptionsFlowHandler(config_entries.OptionsFlow): CONF_TO_WINDOW, description={ "suggested_value": self.entry.options.get( - CONF_FROM_WINDOW, DEFAULT_TO_WINDOW + CONF_TO_WINDOW, DEFAULT_TO_WINDOW ) }, ): vol.Coerce(float), diff --git a/tests/components/openuv/test_config_flow.py b/tests/components/openuv/test_config_flow.py index eeafd82a20f..555d01e2624 100644 --- a/tests/components/openuv/test_config_flow.py +++ b/tests/components/openuv/test_config_flow.py @@ -2,6 +2,7 @@ from unittest.mock import patch from pyopenuv.errors import InvalidApiKeyError +import voluptuous as vol from homeassistant import data_entry_flow from homeassistant.components.openuv import CONF_FROM_WINDOW, CONF_TO_WINDOW, DOMAIN @@ -36,6 +37,13 @@ async def test_invalid_api_key(hass, config): assert result["errors"] == {CONF_API_KEY: "invalid_api_key"} +def _get_schema_marker(data_schema: vol.Schema, key: str) -> vol.Marker: + for k in data_schema.schema: + if k == key and isinstance(k, vol.Marker): + return k + return None + + async def test_options_flow(hass, config_entry): """Test config flow options.""" with patch("homeassistant.components.openuv.async_setup_entry", return_value=True): @@ -43,6 +51,13 @@ async def test_options_flow(hass, config_entry): result = await hass.config_entries.options.async_init(config_entry.entry_id) assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["step_id"] == "init" + # Original schema uses defaults for suggested values + assert _get_schema_marker( + result["data_schema"], CONF_FROM_WINDOW + ).description == {"suggested_value": 3.5} + assert _get_schema_marker( + result["data_schema"], CONF_TO_WINDOW + ).description == {"suggested_value": 3.5} result = await hass.config_entries.options.async_configure( result["flow_id"], user_input={CONF_FROM_WINDOW: 3.5, CONF_TO_WINDOW: 2.0} @@ -50,6 +65,17 @@ async def test_options_flow(hass, config_entry): assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY assert config_entry.options == {CONF_FROM_WINDOW: 3.5, CONF_TO_WINDOW: 2.0} + # Subsequent schema uses previous input for suggested values + result = await hass.config_entries.options.async_init(config_entry.entry_id) + assert result["type"] == data_entry_flow.FlowResultType.FORM + assert result["step_id"] == "init" + assert _get_schema_marker( + result["data_schema"], CONF_FROM_WINDOW + ).description == {"suggested_value": 3.5} + assert _get_schema_marker( + result["data_schema"], CONF_TO_WINDOW + ).description == {"suggested_value": 2.0} + async def test_step_reauth(hass, config, config_entry, setup_openuv): """Test that the reauth step works."""