Fix suggested values in openuv config flow (#82479)
* Fix suggested values in openuv config flow * Don't use new helper
This commit is contained in:
parent
4b0b2ecc0e
commit
13c03d022b
2 changed files with 27 additions and 1 deletions
|
@ -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),
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Add table
Reference in a new issue