Use reconfigure_confirm in enphase_envoy config flow (#127221)

This commit is contained in:
epenet 2024-10-01 15:11:37 +02:00 committed by Franck Nijhof
parent 03553b8bb9
commit 067b81a60b
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
3 changed files with 19 additions and 12 deletions

View file

@ -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 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
)
async def async_step_reconfigure(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Add reconfigure step to allow to manually reconfigure a config entry."""
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] = {}
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
assert entry
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 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
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 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
}
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
),

View file

@ -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%]",

View file

@ -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