Use reconfigure_confirm in solarlog config flow (#127215)

* Use reconfigure_confirm in solarlog config flow

* Fix test
This commit is contained in:
epenet 2024-10-01 14:24:44 +02:00 committed by Franck Nijhof
parent 9d059fcfaa
commit c8b92bc858
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
3 changed files with 20 additions and 13 deletions

View File

@ -138,40 +138,47 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
)
async def async_step_reconfigure(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle a reconfiguration flow initialized by the user."""
self._entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
return await self.async_step_reconfigure_confirm()
async def async_step_reconfigure_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a reconfiguration flow initialized by the user."""
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
if TYPE_CHECKING:
assert entry is not None
assert self._entry is not None
if user_input is not None:
if not user_input[CONF_HAS_PWD] or user_input.get(CONF_PASSWORD, "") == "":
user_input[CONF_PASSWORD] = ""
user_input[CONF_HAS_PWD] = False
return self.async_update_reload_and_abort(
entry,
self._entry,
reason="reconfigure_successful",
data={**entry.data, **user_input},
data={**self._entry.data, **user_input},
)
if await self._test_extended_data(
entry.data[CONF_HOST], user_input.get(CONF_PASSWORD, "")
self._entry.data[CONF_HOST], user_input.get(CONF_PASSWORD, "")
):
# if password has been provided, only save if extended data is available
return self.async_update_reload_and_abort(
entry,
self._entry,
reason="reconfigure_successful",
data={**entry.data, **user_input},
data={**self._entry.data, **user_input},
)
return self.async_show_form(
step_id="reconfigure",
step_id="reconfigure_confirm",
data_schema=vol.Schema(
{
vol.Optional(CONF_HAS_PWD, default=entry.data[CONF_HAS_PWD]): bool,
vol.Optional(
CONF_HAS_PWD, default=self._entry.data[CONF_HAS_PWD]
): bool,
vol.Optional(CONF_PASSWORD): str,
}
),

View File

@ -29,7 +29,7 @@
"password": "[%key:common::config_flow::data::password%]"
}
},
"reconfigure": {
"reconfigure_confirm": {
"title": "Configure SolarLog",
"data": {
"has_password": "[%key:component::solarlog::config::step::user::data::has_password%]"

View File

@ -213,7 +213,7 @@ async def test_reconfigure_flow(
},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure"
assert result["step_id"] == "reconfigure_confirm"
# test with all data provided
result = await hass.config_entries.flow.async_configure(