mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use new reauth_helpers in openexchangerates (#128706)
Use reauth_confirm in openexchangerates
This commit is contained in:
parent
2324bccbe7
commit
0d90d6586e
@ -13,7 +13,7 @@ from aioopenexchangerates import (
|
|||||||
)
|
)
|
||||||
import voluptuous as vol
|
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_API_KEY, CONF_BASE
|
from homeassistant.const import CONF_API_KEY, CONF_BASE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import AbortFlow
|
from homeassistant.data_entry_flow import AbortFlow
|
||||||
@ -54,7 +54,6 @@ class OpenExchangeRatesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize the config flow."""
|
"""Initialize the config flow."""
|
||||||
self.currencies: dict[str, str] = {}
|
self.currencies: dict[str, str] = {}
|
||||||
self._reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
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
|
||||||
@ -63,9 +62,9 @@ class OpenExchangeRatesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
currencies = await self.async_get_currencies()
|
currencies = await self.async_get_currencies()
|
||||||
|
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
existing_data: Mapping[str, str] | dict[str, str] = (
|
existing_data: Mapping[str, Any] = {}
|
||||||
self._reauth_entry.data if self._reauth_entry else {}
|
if self.source == SOURCE_REAUTH:
|
||||||
)
|
existing_data = self._get_reauth_entry().data
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=get_data_schema(currencies, existing_data),
|
data_schema=get_data_schema(currencies, existing_data),
|
||||||
@ -95,12 +94,10 @@ class OpenExchangeRatesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._reauth_entry is not None:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self._reauth_entry, data=self._reauth_entry.data | user_input
|
self._get_reauth_entry(), data_updates=user_input
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
return self.async_create_entry(title=info["title"], data=user_input)
|
return self.async_create_entry(title=info["title"], data=user_input)
|
||||||
|
|
||||||
@ -115,9 +112,6 @@ class OpenExchangeRatesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reauth."""
|
"""Handle reauth."""
|
||||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
async def async_get_currencies(self) -> dict[str, str]:
|
async def async_get_currencies(self) -> dict[str, str]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user