From f2c746122e51e0b77c0a2542d7ef845ea3b7e33b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:41:15 +0200 Subject: [PATCH] Use reconfigure_confirm in google_travel_time config flow (#127220) --- .../google_travel_time/config_flow.py | 20 +++++++++++++------ .../google_travel_time/strings.json | 2 +- .../google_travel_time/test_config_flow.py | 4 +++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/google_travel_time/config_flow.py b/homeassistant/components/google_travel_time/config_flow.py index 0b493d7eeeb9a9..a9f68179fe779d 100644 --- a/homeassistant/components/google_travel_time/config_flow.py +++ b/homeassistant/components/google_travel_time/config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations +from collections.abc import Mapping from typing import TYPE_CHECKING, Any import voluptuous as vol @@ -207,6 +208,8 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 + _context_entry: ConfigEntry + @staticmethod @callback def async_get_options_flow( @@ -235,28 +238,33 @@ async def async_step_user(self, user_input=None) -> ConfigFlowResult: ) async def async_step_reconfigure( - self, user_input: dict[str, Any] | None = None + self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle reconfiguration.""" entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) if TYPE_CHECKING: assert entry + self._context_entry = entry + return await self.async_step_reconfigure_confirm() + async def async_step_reconfigure_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle reconfiguration.""" errors: dict[str, str] | None = None - user_input = user_input or {} - if user_input: + if user_input is not None: errors = await validate_input(self.hass, user_input) if not errors: return self.async_update_reload_and_abort( - entry, + self._context_entry, data=user_input, reason="reconfigure_successful", ) return self.async_show_form( - step_id="reconfigure", + step_id="reconfigure_confirm", data_schema=self.add_suggested_values_to_schema( - RECONFIGURE_SCHEMA, entry.data.copy() + RECONFIGURE_SCHEMA, self._context_entry.data.copy() ), errors=errors, ) diff --git a/homeassistant/components/google_travel_time/strings.json b/homeassistant/components/google_travel_time/strings.json index 765cfc9c4b67d6..6397336d9ac9e6 100644 --- a/homeassistant/components/google_travel_time/strings.json +++ b/homeassistant/components/google_travel_time/strings.json @@ -11,7 +11,7 @@ "destination": "Destination" } }, - "reconfigure": { + "reconfigure_confirm": { "description": "[%key:component::google_travel_time::config::step::user::description%]", "data": { "api_key": "[%key:common::config_flow::data::api_key%]", diff --git a/tests/components/google_travel_time/test_config_flow.py b/tests/components/google_travel_time/test_config_flow.py index d16d1c1ffc9962..b3e6ea0f1fcf06 100644 --- a/tests/components/google_travel_time/test_config_flow.py +++ b/tests/components/google_travel_time/test_config_flow.py @@ -204,9 +204,10 @@ async def test_reconfigure(hass: HomeAssistant, mock_config: MockConfigEntry) -> "source": config_entries.SOURCE_RECONFIGURE, "entry_id": mock_config.entry_id, }, + data=mock_config.data, ) assert reconfigure_result["type"] is FlowResultType.FORM - assert reconfigure_result["step_id"] == "reconfigure" + assert reconfigure_result["step_id"] == "reconfigure_confirm" await assert_common_reconfigure_steps(hass, reconfigure_result) @@ -234,6 +235,7 @@ async def test_reconfigure_invalid_config_entry( "source": config_entries.SOURCE_RECONFIGURE, "entry_id": mock_config.entry_id, }, + data=mock_config.data, ) assert result["type"] is FlowResultType.FORM assert result["errors"] is None