From 3fb7547d4dd482a9f5b3aa59a2eae8f9371fe3b0 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:11:37 +0200 Subject: [PATCH] Use reconfigure_confirm in enphase_envoy config flow (#127221) --- .../components/enphase_envoy/config_flow.py | 21 ++++++++++++------- .../components/enphase_envoy/strings.json | 2 +- .../enphase_envoy/test_config_flow.py | 8 +++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/enphase_envoy/config_flow.py b/homeassistant/components/enphase_envoy/config_flow.py index dd3b9e2d3fa77..dca537497c244 100644 --- a/homeassistant/components/enphase_envoy/config_flow.py +++ b/homeassistant/components/enphase_envoy/config_flow.py @@ -54,6 +54,8 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 + _reconnect_entry: ConfigEntry + def __init__(self) -> None: """Initialize an envoy flow.""" self.ip_address: str | None = None @@ -233,17 +235,22 @@ async def async_step_user( ) async def async_step_reconfigure( - self, user_input: dict[str, Any] | None = None + self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Add reconfigure step to allow to manually reconfigure a config entry.""" - errors: dict[str, str] = {} - description_placeholders: dict[str, str] = {} - entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) assert entry + self._reconnect_entry = entry + return await self.async_step_reconfigure_confirm() + async def async_step_reconfigure_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Add reconfigure step to allow to manually reconfigure a config entry.""" + errors: dict[str, str] = {} + description_placeholders: dict[str, str] = {} suggested_values: dict[str, Any] | MappingProxyType[str, Any] = ( - user_input or entry.data + user_input or self._reconnect_entry.data ) host: Any = suggested_values.get(CONF_HOST) @@ -284,7 +291,7 @@ async def async_step_reconfigure( error="reconfigure_successful", ) if not self.unique_id: - await self.async_set_unique_id(entry.unique_id) + await self.async_set_unique_id(self._reconnect_entry.unique_id) self.context["title_placeholders"] = { CONF_SERIAL: self.unique_id, @@ -292,7 +299,7 @@ async def async_step_reconfigure( } return self.async_show_form( - step_id="reconfigure", + step_id="reconfigure_confirm", data_schema=self.add_suggested_values_to_schema( self._async_generate_schema(), suggested_values ), diff --git a/homeassistant/components/enphase_envoy/strings.json b/homeassistant/components/enphase_envoy/strings.json index 2e7ce831efca8..c08a6c53a0f81 100644 --- a/homeassistant/components/enphase_envoy/strings.json +++ b/homeassistant/components/enphase_envoy/strings.json @@ -13,7 +13,7 @@ "host": "The hostname or IP address of your Enphase Envoy gateway." } }, - "reconfigure": { + "reconfigure_confirm": { "description": "[%key:component::enphase_envoy::config::step::user::description%]", "data": { "host": "[%key:common::config_flow::data::host%]", diff --git a/tests/components/enphase_envoy/test_config_flow.py b/tests/components/enphase_envoy/test_config_flow.py index f61a0054ed976..42e41051e0a10 100644 --- a/tests/components/enphase_envoy/test_config_flow.py +++ b/tests/components/enphase_envoy/test_config_flow.py @@ -706,7 +706,7 @@ async def test_reconfigure( }, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "reconfigure" + assert result["step_id"] == "reconfigure_confirm" assert result["errors"] == {} # original entry @@ -748,7 +748,7 @@ async def test_reconfigure_nochange( }, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "reconfigure" + assert result["step_id"] == "reconfigure_confirm" assert result["errors"] == {} # original entry @@ -790,7 +790,7 @@ async def test_reconfigure_otherenvoy( }, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "reconfigure" + assert result["step_id"] == "reconfigure_confirm" assert result["errors"] == {} # let mock return different serial from first time, sim it's other one on changed ip @@ -936,7 +936,7 @@ async def test_reconfigure_change_ip_to_existing( }, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "reconfigure" + assert result["step_id"] == "reconfigure_confirm" assert result["errors"] == {} # original entry