Use _get_reauth_entry in devolo_home_control config flow (#127387)

Use _get_reauth_entry in devolo_home_network config flow
This commit is contained in:
epenet 2024-10-03 12:21:42 +02:00 committed by GitHub
parent 7878d2804f
commit 14c2778558
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,12 @@ from typing import Any
import voluptuous as vol import voluptuous as vol
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
)
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback from homeassistant.core import callback
@ -22,13 +27,14 @@ class DevoloHomeControlFlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
_reauth_entry: ConfigEntry
def __init__(self) -> None: def __init__(self) -> None:
"""Initialize devolo Home Control flow.""" """Initialize devolo Home Control flow."""
self.data_schema = { self.data_schema = {
vol.Required(CONF_USERNAME): str, vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str, vol.Required(CONF_PASSWORD): str,
} }
self._reauth_entry: ConfigEntry | None = None
self._url = DEFAULT_MYDEVOLO self._url = DEFAULT_MYDEVOLO
async def async_step_user( async def async_step_user(
@ -71,9 +77,7 @@ class DevoloHomeControlFlowHandler(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle reauthentication.""" """Handle reauthentication."""
self._reauth_entry = self.hass.config_entries.async_get_entry( self._reauth_entry = self._get_reauth_entry()
self.context["entry_id"]
)
self._url = entry_data[CONF_MYDEVOLO] self._url = entry_data[CONF_MYDEVOLO]
self.data_schema = { self.data_schema = {
vol.Required(CONF_USERNAME, default=entry_data[CONF_USERNAME]): str, vol.Required(CONF_USERNAME, default=entry_data[CONF_USERNAME]): str,
@ -109,7 +113,7 @@ class DevoloHomeControlFlowHandler(ConfigFlow, domain=DOMAIN):
raise CredentialsInvalid raise CredentialsInvalid
uuid = await self.hass.async_add_executor_job(mydevolo.uuid) uuid = await self.hass.async_add_executor_job(mydevolo.uuid)
if not self._reauth_entry: if self.source != SOURCE_REAUTH:
await self.async_set_unique_id(uuid) await self.async_set_unique_id(uuid)
self._abort_if_unique_id_configured() self._abort_if_unique_id_configured()
return self.async_create_entry( return self.async_create_entry(