Use reauth_confirm in weatherflow_cloud (#124761)

This commit is contained in:
epenet 2024-08-28 13:09:45 +02:00 committed by GitHub
parent 45eebf3285
commit 163795e73a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 8 deletions

View File

@ -33,9 +33,15 @@ class WeatherFlowCloudConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
async def async_step_reauth(
self, user_input: Mapping[str, Any]
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle a flow for reauth."""
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a flow initiated by reauthentication."""
errors = {}
if user_input is not None:
@ -54,7 +60,7 @@ class WeatherFlowCloudConfigFlow(ConfigFlow, domain=DOMAIN):
)
return self.async_show_form(
step_id="reauth",
step_id="reauth_confirm",
data_schema=vol.Schema({vol.Required(CONF_API_TOKEN): str}),
errors=errors,
)

View File

@ -7,7 +7,7 @@
"api_token": "Personal api token"
}
},
"reauth": {
"reauth_confirm": {
"description": "Reauthenticate with WeatherFlow",
"data": {
"api_token": "[%key:component::weatherflow_cloud::config::step::user::data::api_token%]"

View File

@ -111,15 +111,18 @@ async def test_reauth(hass: HomeAssistant, mock_get_stations_401_error) -> None:
assert not await hass.config_entries.async_setup(entry.entry_id)
assert entry.state is ConfigEntryState.SETUP_ERROR
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_REAUTH, "entry_id": entry.entry_id}, data=None
)
assert result["type"] is FlowResultType.FORM
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": entry.entry_id},
data={CONF_API_TOKEN: "SAME_SAME"},
data=entry.data,
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_API_TOKEN: "SAME_SAME"}
)
assert result["reason"] == "reauth_successful"
assert result["type"] is FlowResultType.ABORT
assert entry.data[CONF_API_TOKEN] == "SAME_SAME"