mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Use new reauth helpers in tailscale (#128752)
This commit is contained in:
parent
f592c64c6a
commit
f97d6b552b
@ -8,7 +8,7 @@ from typing import Any
|
|||||||
from tailscale import Tailscale, TailscaleAuthenticationError, TailscaleError
|
from tailscale import Tailscale, TailscaleAuthenticationError, TailscaleError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
@ -34,8 +34,6 @@ class TailscaleFlowHandler(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: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
@ -86,9 +84,6 @@ class TailscaleFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle initiation of re-authentication with Tailscale."""
|
"""Handle initiation of re-authentication with Tailscale."""
|
||||||
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(
|
||||||
@ -97,11 +92,12 @@ class TailscaleFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle re-authentication with Tailscale."""
|
"""Handle re-authentication with Tailscale."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is not None and self.reauth_entry:
|
if user_input is not None:
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
try:
|
try:
|
||||||
await validate_input(
|
await validate_input(
|
||||||
self.hass,
|
self.hass,
|
||||||
tailnet=self.reauth_entry.data[CONF_TAILNET],
|
tailnet=reauth_entry.data[CONF_TAILNET],
|
||||||
api_key=user_input[CONF_API_KEY],
|
api_key=user_input[CONF_API_KEY],
|
||||||
)
|
)
|
||||||
except TailscaleAuthenticationError:
|
except TailscaleAuthenticationError:
|
||||||
@ -109,17 +105,10 @@ class TailscaleFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
except TailscaleError:
|
except TailscaleError:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
else:
|
else:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self.reauth_entry,
|
reauth_entry,
|
||||||
data={
|
data_updates={CONF_API_KEY: user_input[CONF_API_KEY]},
|
||||||
**self.reauth_entry.data,
|
|
||||||
CONF_API_KEY: user_input[CONF_API_KEY],
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
self.hass.async_create_task(
|
|
||||||
self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user