mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Use new reauth helpers in thethingsnetwork (#128761)
This commit is contained in:
parent
5d5355bc41
commit
f592c64c6a
@ -7,7 +7,7 @@ from typing import Any
|
|||||||
from ttn_client import TTNAuthError, TTNClient
|
from ttn_client import TTNAuthError, TTNClient
|
||||||
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_HOST
|
from homeassistant.const import CONF_API_KEY, CONF_HOST
|
||||||
from homeassistant.helpers.selector import (
|
from homeassistant.helpers.selector import (
|
||||||
TextSelector,
|
TextSelector,
|
||||||
@ -25,8 +25,6 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
_reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: Mapping[str, Any] | None = None
|
self, user_input: Mapping[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
@ -51,11 +49,9 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
# Create entry
|
# Create entry
|
||||||
if self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._reauth_entry,
|
self._get_reauth_entry(), data=user_input
|
||||||
data=user_input,
|
|
||||||
reason="reauth_successful",
|
|
||||||
)
|
)
|
||||||
await self.async_set_unique_id(user_input[CONF_APP_ID])
|
await self.async_set_unique_id(user_input[CONF_APP_ID])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
@ -67,8 +63,8 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
# Show form for user to provide settings
|
# Show form for user to provide settings
|
||||||
if not user_input:
|
if not user_input:
|
||||||
if self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
user_input = self._reauth_entry.data
|
user_input = self._get_reauth_entry().data
|
||||||
else:
|
else:
|
||||||
user_input = {CONF_HOST: TTN_API_HOST}
|
user_input = {CONF_HOST: TTN_API_HOST}
|
||||||
|
|
||||||
@ -92,11 +88,6 @@ class TTNFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a flow initialized by a reauth event."""
|
"""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()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user