Use new reauth helpers in thethingsnetwork (#128761)
This commit is contained in:
parent
5d5355bc41
commit
f592c64c6a
1 changed files with 5 additions and 14 deletions
|
@ -7,7 +7,7 @@ from typing import Any
|
|||
from ttn_client import TTNAuthError, TTNClient
|
||||
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_HOST
|
||||
from homeassistant.helpers.selector import (
|
||||
TextSelector,
|
||||
|
@ -25,8 +25,6 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
_reauth_entry: ConfigEntry | None = None
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: Mapping[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
|
@ -51,11 +49,9 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
if not errors:
|
||||
# Create entry
|
||||
if self._reauth_entry:
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return self.async_update_reload_and_abort(
|
||||
self._reauth_entry,
|
||||
data=user_input,
|
||||
reason="reauth_successful",
|
||||
self._get_reauth_entry(), data=user_input
|
||||
)
|
||||
await self.async_set_unique_id(user_input[CONF_APP_ID])
|
||||
self._abort_if_unique_id_configured()
|
||||
|
@ -67,8 +63,8 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
# Show form for user to provide settings
|
||||
if not user_input:
|
||||
if self._reauth_entry:
|
||||
user_input = self._reauth_entry.data
|
||||
if self.source == SOURCE_REAUTH:
|
||||
user_input = self._get_reauth_entry().data
|
||||
else:
|
||||
user_input = {CONF_HOST: TTN_API_HOST}
|
||||
|
||||
|
@ -92,11 +88,6 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle a flow initialized by a reauth event."""
|
||||
|
||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
|
|
Loading…
Add table
Reference in a new issue