Skip to content

Commit

Permalink
Use new reauth helpers in rympro (home-assistant#128728)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 19, 2024
1 parent 9622a11 commit 0581d61
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions homeassistant/components/rympro/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyrympro import CannotConnectError, RymPro, UnauthorizedError
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_TOKEN, CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand Down Expand Up @@ -46,10 +46,6 @@ class RymproConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

def __init__(self) -> None:
"""Init the config flow."""
self._reauth_entry: ConfigEntry | None = None

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
Expand All @@ -74,19 +70,17 @@ async def async_step_user(
title = user_input[CONF_EMAIL]
data = {**user_input, **info}

if not self._reauth_entry:
if self.source != SOURCE_REAUTH:
await self.async_set_unique_id(info[CONF_UNIQUE_ID])
self._abort_if_unique_id_configured()
return self.async_create_entry(title=title, data=data)

self.hass.config_entries.async_update_entry(
self._reauth_entry,
return self.async_update_reload_and_abort(
self._get_reauth_entry(),
title=title,
data=data,
unique_id=info[CONF_UNIQUE_ID],
)
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")

return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
Expand All @@ -96,7 +90,4 @@ async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle configuration by re-auth."""
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return await self.async_step_user()

0 comments on commit 0581d61

Please sign in to comment.