Skip to content

Commit

Permalink
Use reconfigure_confirm in enphase_envoy config flow (#127221)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 1, 2024
1 parent 10c0633 commit 3fb7547
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
21 changes: 14 additions & 7 deletions homeassistant/components/enphase_envoy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -284,15 +291,15 @@ 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,
CONF_HOST: host,
}

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

0 comments on commit 3fb7547

Please sign in to comment.