From 94e2646c875a539f2c48d40eacf24f93f2e69026 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:56:13 +0100 Subject: [PATCH] Implement reauth_confirm in fireservicerota (#77487) --- .../components/fireservicerota/config_flow.py | 30 +++++++++++-------- .../components/fireservicerota/strings.json | 2 +- .../fireservicerota/translations/en.json | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/fireservicerota/config_flow.py b/homeassistant/components/fireservicerota/config_flow.py index 3fcd3870f6a..d4d2b0763d9 100644 --- a/homeassistant/components/fireservicerota/config_flow.py +++ b/homeassistant/components/fireservicerota/config_flow.py @@ -1,9 +1,15 @@ """Config flow for FireServiceRota.""" +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any + from pyfireservicerota import FireServiceRota, InvalidAuthError import voluptuous as vol from homeassistant import config_entries from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_URL, CONF_USERNAME +from homeassistant.data_entry_flow import FlowResult from .const import DOMAIN, URL_LIST @@ -110,18 +116,18 @@ class FireServiceRotaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): description_placeholders=self._description_placeholders, ) - async def async_step_reauth(self, user_input=None): + async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult: + """Initialise re-authentication.""" + await self.async_set_unique_id(entry_data[CONF_USERNAME]) + self._existing_entry = {**entry_data} + self._description_placeholders = {CONF_USERNAME: entry_data[CONF_USERNAME]} + return await self.async_step_reauth_confirm() + + async def async_step_reauth_confirm( + self, user_input: dict[str, str] | None = None + ) -> FlowResult: """Get new tokens for a config entry that can't authenticate.""" - - if not self._existing_entry: - await self.async_set_unique_id(user_input[CONF_USERNAME]) - self._existing_entry = user_input.copy() - self._description_placeholders = {"username": user_input[CONF_USERNAME]} - user_input = None - if user_input is None: - return self._show_setup_form(step_id=config_entries.SOURCE_REAUTH) + return self._show_setup_form(step_id="reauth_confirm") - return await self._validate_and_create_entry( - user_input, config_entries.SOURCE_REAUTH - ) + return await self._validate_and_create_entry(user_input, "reauth_confirm") diff --git a/homeassistant/components/fireservicerota/strings.json b/homeassistant/components/fireservicerota/strings.json index aef6f1b6849..7c60b438264 100644 --- a/homeassistant/components/fireservicerota/strings.json +++ b/homeassistant/components/fireservicerota/strings.json @@ -8,7 +8,7 @@ "url": "Website" } }, - "reauth": { + "reauth_confirm": { "description": "Authentication tokens became invalid, login to recreate them.", "data": { "password": "[%key:common::config_flow::data::password%]" diff --git a/homeassistant/components/fireservicerota/translations/en.json b/homeassistant/components/fireservicerota/translations/en.json index a059081760d..38762b614f4 100644 --- a/homeassistant/components/fireservicerota/translations/en.json +++ b/homeassistant/components/fireservicerota/translations/en.json @@ -11,7 +11,7 @@ "invalid_auth": "Invalid authentication" }, "step": { - "reauth": { + "reauth_confirm": { "data": { "password": "Password" },