From 51b12cbf960bffc4ee9eced9a58bdd45da67e617 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Mon, 20 Mar 2023 15:52:54 +0100 Subject: [PATCH] Add user_input as suggested value in imap config flow (#89982) Add user_input as suggested value to config_schema --- homeassistant/components/imap/config_flow.py | 5 ++--- tests/components/imap/test_config_flow.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/imap/config_flow.py b/homeassistant/components/imap/config_flow.py index 36528ae6ed9..de1ac1e5d65 100644 --- a/homeassistant/components/imap/config_flow.py +++ b/homeassistant/components/imap/config_flow.py @@ -91,9 +91,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_create_entry(title=title, data=user_input) - return self.async_show_form( - step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors - ) + schema = self.add_suggested_values_to_schema(STEP_USER_DATA_SCHEMA, user_input) + return self.async_show_form(step_id="user", data_schema=schema, errors=errors) async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult: """Perform reauth upon an API authentication error.""" diff --git a/tests/components/imap/test_config_flow.py b/tests/components/imap/test_config_flow.py index ad8e63fa617..663637ff0ba 100644 --- a/tests/components/imap/test_config_flow.py +++ b/tests/components/imap/test_config_flow.py @@ -129,6 +129,12 @@ async def test_form_cannot_connect(hass: HomeAssistant, exc: Exception) -> None: assert result2["type"] == FlowResultType.FORM assert result2["errors"] == {"base": "cannot_connect"} + # make sure we do not lose the user input if somethings gets wrong + assert { + key: key.description.get("suggested_value") + for key in result2["data_schema"].schema + } == MOCK_CONFIG + async def test_form_invalid_charset(hass: HomeAssistant) -> None: """Test we handle invalid charset."""