mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Use reconfigure_confirm in enphase_envoy config flow (#127221)
This commit is contained in:
parent
10c0633af9
commit
3fb7547d4d
@ -54,6 +54,8 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
_reconnect_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize an envoy flow."""
|
"""Initialize an envoy flow."""
|
||||||
self.ip_address: str | None = None
|
self.ip_address: str | None = None
|
||||||
@ -233,17 +235,22 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_reconfigure(
|
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
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Add reconfigure step to allow to manually reconfigure a config entry."""
|
"""Add reconfigure step to allow to manually reconfigure a config entry."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
description_placeholders: 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] = (
|
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)
|
host: Any = suggested_values.get(CONF_HOST)
|
||||||
@ -284,7 +291,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
error="reconfigure_successful",
|
error="reconfigure_successful",
|
||||||
)
|
)
|
||||||
if not self.unique_id:
|
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"] = {
|
self.context["title_placeholders"] = {
|
||||||
CONF_SERIAL: self.unique_id,
|
CONF_SERIAL: self.unique_id,
|
||||||
@ -292,7 +299,7 @@ class EnphaseConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
self._async_generate_schema(), suggested_values
|
self._async_generate_schema(), suggested_values
|
||||||
),
|
),
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"host": "The hostname or IP address of your Enphase Envoy gateway."
|
"host": "The hostname or IP address of your Enphase Envoy gateway."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"reconfigure": {
|
"reconfigure_confirm": {
|
||||||
"description": "[%key:component::enphase_envoy::config::step::user::description%]",
|
"description": "[%key:component::enphase_envoy::config::step::user::description%]",
|
||||||
"data": {
|
"data": {
|
||||||
"host": "[%key:common::config_flow::data::host%]",
|
"host": "[%key:common::config_flow::data::host%]",
|
||||||
|
@ -706,7 +706,7 @@ async def test_reconfigure(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reconfigure"
|
assert result["step_id"] == "reconfigure_confirm"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
# original entry
|
# original entry
|
||||||
@ -748,7 +748,7 @@ async def test_reconfigure_nochange(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reconfigure"
|
assert result["step_id"] == "reconfigure_confirm"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
# original entry
|
# original entry
|
||||||
@ -790,7 +790,7 @@ async def test_reconfigure_otherenvoy(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reconfigure"
|
assert result["step_id"] == "reconfigure_confirm"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
# let mock return different serial from first time, sim it's other one on changed ip
|
# 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["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reconfigure"
|
assert result["step_id"] == "reconfigure_confirm"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
# original entry
|
# original entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user