Use reauth_confirm in discovergy (#124782)

pull/124821/head
epenet 2024-08-28 20:42:50 +02:00 committed by GitHub
parent af8131e68f
commit 7d61dd13d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 12 deletions

View File

@ -70,8 +70,16 @@ class DiscovergyConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle the initial step."""
self._existing_entry = await self.async_set_unique_id(self.context["unique_id"])
return await self._validate_and_save(entry_data, step_id="reauth")
self._existing_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the reauth step."""
return await self._validate_and_save(user_input, step_id="reauth_confirm")
async def _validate_and_save(
self, user_input: Mapping[str, Any] | None = None, step_id: str = "user"

View File

@ -7,7 +7,7 @@
"password": "[%key:common::config_flow::data::password%]"
}
},
"reauth": {
"reauth_confirm": {
"data": {
"email": "[%key:common::config_flow::data::email%]",
"password": "[%key:common::config_flow::data::password%]"

View File

@ -6,7 +6,7 @@ from pydiscovergy.error import DiscovergyClientError, HTTPError, InvalidLogin
import pytest
from homeassistant.components.discovergy.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -49,15 +49,9 @@ async def test_reauth(
) -> None:
"""Test reauth flow."""
config_entry.add_to_hass(hass)
init_result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "unique_id": config_entry.unique_id},
data=None,
)
init_result = await config_entry.start_reauth_flow(hass)
assert init_result["type"] is FlowResultType.FORM
assert init_result["step_id"] == "reauth"
assert init_result["step_id"] == "reauth_confirm"
with patch(
"homeassistant.components.discovergy.async_setup_entry",