mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Use reconfigure_confirm in google_travel_time config flow (#127220)
This commit is contained in:
parent
e25a54aef4
commit
f2c746122e
@ -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 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
|
@ -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%]",
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user