Skip to content

Commit

Permalink
Use reconfigure_confirm in google_travel_time config flow (#127220)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored and frenck committed Oct 1, 2024
1 parent e25a54a commit f2c7461
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
20 changes: 14 additions & 6 deletions homeassistant/components/google_travel_time/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any

import voluptuous as vol
Expand Down Expand Up @@ -207,6 +208,8 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

_context_entry: ConfigEntry

@staticmethod
@callback
def async_get_options_flow(
Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion homeassistant/components/google_travel_time/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]",
Expand Down
4 changes: 3 additions & 1 deletion tests/components/google_travel_time/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2c7461

Please sign in to comment.