From ff6261ccc87a1a4a4ed9f52d0732dcd5047f7452 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 19 Oct 2024 08:54:29 +0200 Subject: [PATCH] Use reauth_confirm in nanoleaf (#128698) --- .../components/nanoleaf/config_flow.py | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/nanoleaf/config_flow.py b/homeassistant/components/nanoleaf/config_flow.py index cc34e30eb59..27ef9a887fe 100644 --- a/homeassistant/components/nanoleaf/config_flow.py +++ b/homeassistant/components/nanoleaf/config_flow.py @@ -11,7 +11,7 @@ from aionanoleaf import InvalidToken, Nanoleaf, Unauthorized, Unavailable import voluptuous as vol from homeassistant.components import ssdp, zeroconf -from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_HOST, CONF_TOKEN from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.json import save_json @@ -34,8 +34,6 @@ USER_SCHEMA: Final = vol.Schema( class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN): """Nanoleaf config flow.""" - reauth_entry: ConfigEntry | None = None - nanoleaf: Nanoleaf # For discovery integration import @@ -81,14 +79,10 @@ class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle Nanoleaf reauth flow if token is invalid.""" - self.reauth_entry = cast( - ConfigEntry, - self.hass.config_entries.async_get_entry(self.context["entry_id"]), - ) self.nanoleaf = Nanoleaf( async_get_clientsession(self.hass), entry_data[CONF_HOST] ) - self.context["title_placeholders"] = {"name": self.reauth_entry.title} + self.context["title_placeholders"] = {"name": self._get_reauth_entry().title} return await self.async_step_link() async def async_step_zeroconf( @@ -177,16 +171,11 @@ class NanoleafConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unknown error authorizing Nanoleaf") return self.async_show_form(step_id="link", errors={"base": "unknown"}) - if self.reauth_entry is not None: - self.hass.config_entries.async_update_entry( - self.reauth_entry, - data={ - **self.reauth_entry.data, - CONF_TOKEN: self.nanoleaf.auth_token, - }, + if self.source == SOURCE_REAUTH: + return self.async_update_reload_and_abort( + self._get_reauth_entry(), + data_updates={CONF_TOKEN: self.nanoleaf.auth_token}, ) - await self.hass.config_entries.async_reload(self.reauth_entry.entry_id) - return self.async_abort(reason="reauth_successful") return await self.async_setup_finish()