Use reconfigure_confirm in google_travel_time config flow (#127220)

This commit is contained in:
epenet 2024-10-01 14:41:15 +02:00 committed by GitHub
parent 97bbad7471
commit 44eb4e0c9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 8 deletions

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
import voluptuous as vol import voluptuous as vol
@ -207,6 +208,8 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
_context_entry: ConfigEntry
@staticmethod @staticmethod
@callback @callback
def async_get_options_flow( def async_get_options_flow(
@ -235,28 +238,33 @@ class GoogleTravelTimeConfigFlow(ConfigFlow, domain=DOMAIN):
) )
async def async_step_reconfigure( async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle reconfiguration.""" """Handle reconfiguration."""
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
if TYPE_CHECKING: if TYPE_CHECKING:
assert entry 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 errors: dict[str, str] | None = None
user_input = user_input or {} if user_input is not None:
if user_input:
errors = await validate_input(self.hass, user_input) errors = await validate_input(self.hass, user_input)
if not errors: if not errors:
return self.async_update_reload_and_abort( return self.async_update_reload_and_abort(
entry, self._context_entry,
data=user_input, data=user_input,
reason="reconfigure_successful", reason="reconfigure_successful",
) )
return self.async_show_form( return self.async_show_form(
step_id="reconfigure", step_id="reconfigure_confirm",
data_schema=self.add_suggested_values_to_schema( data_schema=self.add_suggested_values_to_schema(
RECONFIGURE_SCHEMA, entry.data.copy() RECONFIGURE_SCHEMA, self._context_entry.data.copy()
), ),
errors=errors, errors=errors,
) )

View File

@ -11,7 +11,7 @@
"destination": "Destination" "destination": "Destination"
} }
}, },
"reconfigure": { "reconfigure_confirm": {
"description": "[%key:component::google_travel_time::config::step::user::description%]", "description": "[%key:component::google_travel_time::config::step::user::description%]",
"data": { "data": {
"api_key": "[%key:common::config_flow::data::api_key%]", "api_key": "[%key:common::config_flow::data::api_key%]",

View File

@ -204,9 +204,10 @@ async def test_reconfigure(hass: HomeAssistant, mock_config: MockConfigEntry) ->
"source": config_entries.SOURCE_RECONFIGURE, "source": config_entries.SOURCE_RECONFIGURE,
"entry_id": mock_config.entry_id, "entry_id": mock_config.entry_id,
}, },
data=mock_config.data,
) )
assert reconfigure_result["type"] is FlowResultType.FORM 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) await assert_common_reconfigure_steps(hass, reconfigure_result)
@ -234,6 +235,7 @@ async def test_reconfigure_invalid_config_entry(
"source": config_entries.SOURCE_RECONFIGURE, "source": config_entries.SOURCE_RECONFIGURE,
"entry_id": mock_config.entry_id, "entry_id": mock_config.entry_id,
}, },
data=mock_config.data,
) )
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["errors"] is None assert result["errors"] is None