From 7d61dd13d9f94a98914fdacbd3c593dc04830476 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:42:50 +0200 Subject: [PATCH] Use reauth_confirm in discovergy (#124782) --- homeassistant/components/discovergy/config_flow.py | 12 ++++++++++-- homeassistant/components/discovergy/strings.json | 2 +- tests/components/discovergy/test_config_flow.py | 12 +++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/discovergy/config_flow.py b/homeassistant/components/discovergy/config_flow.py index 5e17f0764b7..47a78ff4308 100644 --- a/homeassistant/components/discovergy/config_flow.py +++ b/homeassistant/components/discovergy/config_flow.py @@ -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" diff --git a/homeassistant/components/discovergy/strings.json b/homeassistant/components/discovergy/strings.json index 34c21bc1cfe..9a91fa92dc4 100644 --- a/homeassistant/components/discovergy/strings.json +++ b/homeassistant/components/discovergy/strings.json @@ -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%]" diff --git a/tests/components/discovergy/test_config_flow.py b/tests/components/discovergy/test_config_flow.py index 2464ba3846f..470ef65fccd 100644 --- a/tests/components/discovergy/test_config_flow.py +++ b/tests/components/discovergy/test_config_flow.py @@ -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",