mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use _get_reauth_entry in discovergy config flow (#127390)
This commit is contained in:
parent
cef56bd7ef
commit
7878d2804f
@ -11,7 +11,12 @@ from pydiscovergy.authentication import BasicAuth
|
|||||||
import pydiscovergy.error as discovergyError
|
import pydiscovergy.error as discovergyError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_REAUTH,
|
||||||
|
ConfigEntry,
|
||||||
|
ConfigFlow,
|
||||||
|
ConfigFlowResult,
|
||||||
|
)
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
from homeassistant.helpers.selector import (
|
from homeassistant.helpers.selector import (
|
||||||
@ -52,7 +57,7 @@ class DiscovergyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
_existing_entry: ConfigEntry | None = None
|
_existing_entry: ConfigEntry
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
@ -70,9 +75,7 @@ class DiscovergyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
self._existing_entry = self.hass.config_entries.async_get_entry(
|
self._existing_entry = self._get_reauth_entry()
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -103,7 +106,7 @@ class DiscovergyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unexpected error occurred while getting meters")
|
_LOGGER.exception("Unexpected error occurred while getting meters")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
if self._existing_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
entry=self._existing_entry,
|
entry=self._existing_entry,
|
||||||
data={
|
data={
|
||||||
@ -124,7 +127,9 @@ class DiscovergyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
step_id=step_id,
|
step_id=step_id,
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
CONFIG_SCHEMA,
|
CONFIG_SCHEMA,
|
||||||
self._existing_entry.data if self._existing_entry else user_input,
|
self._existing_entry.data
|
||||||
|
if self.source == SOURCE_REAUTH
|
||||||
|
else user_input,
|
||||||
),
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user