From dce819f57b3d160165027496b72fa911755c1ee9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 19 Oct 2024 14:33:47 +0200 Subject: [PATCH] Use new reauth helpers in trafikverket_ferry (#128763) --- .../trafikverket_ferry/config_flow.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/trafikverket_ferry/config_flow.py b/homeassistant/components/trafikverket_ferry/config_flow.py index 1f82a535f16..002dc421273 100644 --- a/homeassistant/components/trafikverket_ferry/config_flow.py +++ b/homeassistant/components/trafikverket_ferry/config_flow.py @@ -9,7 +9,7 @@ from pytrafikverket import TrafikverketFerry from pytrafikverket.exceptions import InvalidAuthentication, NoFerryFound 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, CONF_NAME, CONF_WEEKDAY, WEEKDAYS from homeassistant.helpers import selector from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -49,8 +49,6 @@ class TVFerryConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 - entry: ConfigEntry | None - async def validate_input( self, api_key: str, ferry_from: str, ferry_to: str ) -> None: @@ -63,8 +61,6 @@ class TVFerryConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle re-authentication with Trafikverket.""" - - self.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( @@ -76,10 +72,10 @@ class TVFerryConfigFlow(ConfigFlow, domain=DOMAIN): if user_input: api_key = user_input[CONF_API_KEY] - assert self.entry is not None + reauth_entry = self._get_reauth_entry() try: await self.validate_input( - api_key, self.entry.data[CONF_FROM], self.entry.data[CONF_TO] + api_key, reauth_entry.data[CONF_FROM], reauth_entry.data[CONF_TO] ) except InvalidAuthentication: errors["base"] = "invalid_auth" @@ -88,15 +84,10 @@ class TVFerryConfigFlow(ConfigFlow, domain=DOMAIN): except Exception: # noqa: BLE001 errors["base"] = "cannot_connect" else: - self.hass.config_entries.async_update_entry( - self.entry, - data={ - **self.entry.data, - CONF_API_KEY: api_key, - }, + return self.async_update_reload_and_abort( + reauth_entry, + data_updates={CONF_API_KEY: api_key}, ) - await self.hass.config_entries.async_reload(self.entry.entry_id) - return self.async_abort(reason="reauth_successful") return self.async_show_form( step_id="reauth_confirm",