mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 03:35:09 +02:00
Add re-authentication for transmission
(#73124)
* Add reauth flow to transmission * fix async_setup * add strings * fix test coverage
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
"""Config flow for Transmission Bittorent Client."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
@@ -13,6 +16,7 @@ from homeassistant.const import (
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from . import get_api
|
||||
from .const import (
|
||||
@@ -43,6 +47,7 @@ class TransmissionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle Tansmission config flow."""
|
||||
|
||||
VERSION = 1
|
||||
_reauth_entry: config_entries.ConfigEntry | None
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
@@ -87,6 +92,48 @@ class TransmissionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_reauth(self, data: Mapping[str, Any]) -> FlowResult:
|
||||
"""Perform reauth upon an API authentication error."""
|
||||
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(
|
||||
self, user_input: dict[str, str] | None = None
|
||||
) -> FlowResult:
|
||||
"""Confirm reauth dialog."""
|
||||
errors = {}
|
||||
assert self._reauth_entry
|
||||
if user_input is not None:
|
||||
user_input = {**self._reauth_entry.data, **user_input}
|
||||
try:
|
||||
await get_api(self.hass, user_input)
|
||||
|
||||
except AuthenticationError:
|
||||
errors[CONF_PASSWORD] = "invalid_auth"
|
||||
except (CannotConnect, UnknownError):
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self._reauth_entry, data=user_input
|
||||
)
|
||||
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
return self.async_show_form(
|
||||
description_placeholders={
|
||||
CONF_USERNAME: self._reauth_entry.data[CONF_USERNAME]
|
||||
},
|
||||
step_id="reauth_confirm",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_PASSWORD): str,
|
||||
}
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
|
||||
class TransmissionOptionsFlowHandler(config_entries.OptionsFlow):
|
||||
"""Handle Transmission client options."""
|
||||
|
Reference in New Issue
Block a user