diff --git a/homeassistant/components/osoenergy/config_flow.py b/homeassistant/components/osoenergy/config_flow.py index 0642250e9ed..a47f90e3c04 100644 --- a/homeassistant/components/osoenergy/config_flow.py +++ b/homeassistant/components/osoenergy/config_flow.py @@ -7,12 +7,7 @@ from typing import Any from apyosoenergyapi import OSOEnergy import voluptuous as vol -from homeassistant.config_entries import ( - SOURCE_REAUTH, - ConfigEntry, - ConfigFlow, - ConfigFlowResult, -) +from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_API_KEY from homeassistant.helpers import aiohttp_client @@ -27,10 +22,6 @@ class OSOEnergyFlowHandler(ConfigFlow, domain=DOMAIN): VERSION = 1 - def __init__(self) -> None: - """Initialize.""" - self.entry: ConfigEntry | None = None - async def async_step_user(self, user_input=None) -> ConfigFlowResult: """Handle a flow initialized by the user.""" errors = {} @@ -40,12 +31,10 @@ class OSOEnergyFlowHandler(ConfigFlow, domain=DOMAIN): if user_email := await self.get_user_email(user_input[CONF_API_KEY]): await self.async_set_unique_id(user_email) - if self.context["source"] == SOURCE_REAUTH and self.entry: - self.hass.config_entries.async_update_entry( - self.entry, title=user_email, data=user_input + if self.source == SOURCE_REAUTH: + return self.async_update_reload_and_abort( + self._get_reauth_entry(), title=user_email, data=user_input ) - await self.hass.config_entries.async_reload(self.entry.entry_id) - return self.async_abort(reason="reauth_successful") self._abort_if_unique_id_configured() return self.async_create_entry(title=user_email, data=user_input) @@ -72,6 +61,9 @@ class OSOEnergyFlowHandler(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Re Authenticate a user.""" - self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) - data = {CONF_API_KEY: entry_data[CONF_API_KEY]} - return await self.async_step_user(data) + return self.async_show_form( + step_id="user", + data_schema=self.add_suggested_values_to_schema( + _SCHEMA_STEP_USER, self._get_reauth_entry().data + ), + ) diff --git a/tests/components/osoenergy/test_config_flow.py b/tests/components/osoenergy/test_config_flow.py index 0b7a3c30cf2..0d77781a538 100644 --- a/tests/components/osoenergy/test_config_flow.py +++ b/tests/components/osoenergy/test_config_flow.py @@ -68,7 +68,8 @@ async def test_reauth_flow(hass: HomeAssistant) -> None: result = await mock_config.start_reauth_flow(hass) assert result["type"] is FlowResultType.FORM - assert result["errors"] == {"base": "invalid_auth"} + assert result["step_id"] == "user" + assert result["errors"] is None with patch( "homeassistant.components.osoenergy.config_flow.OSOEnergy.get_user_email",