From 409d7b365285ab37aa88f723f4d0fd3e19b73db1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:16:06 +0200 Subject: [PATCH] Use _get_reauth_entry in braviatv config flow (#127326) --- .../components/braviatv/config_flow.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/braviatv/config_flow.py b/homeassistant/components/braviatv/config_flow.py index d3b6dc60f2b..14cabc305c3 100644 --- a/homeassistant/components/braviatv/config_flow.py +++ b/homeassistant/components/braviatv/config_flow.py @@ -11,7 +11,12 @@ from pybravia import BraviaAuthError, BraviaClient, BraviaError, BraviaNotSuppor import voluptuous as vol from homeassistant.components import ssdp -from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import ( + SOURCE_REAUTH, + ConfigEntry, + ConfigFlow, + ConfigFlowResult, +) from homeassistant.const import CONF_CLIENT_ID, CONF_HOST, CONF_MAC, CONF_NAME, CONF_PIN from homeassistant.helpers import instance_id from homeassistant.helpers.aiohttp_client import async_create_clientsession @@ -33,11 +38,12 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 + entry: ConfigEntry + def __init__(self) -> None: """Initialize config flow.""" self.client: BraviaClient | None = None self.device_config: dict[str, Any] = {} - self.entry: ConfigEntry | None = None def create_client(self) -> None: """Create Bravia TV client from config.""" @@ -86,7 +92,6 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN): async def async_reauth_device(self) -> ConfigFlowResult: """Reauthorize Bravia TV device from config.""" - assert self.entry assert self.client await self.async_connect_device() @@ -147,7 +152,7 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN): self.device_config[CONF_CLIENT_ID] = client_id self.device_config[CONF_NICKNAME] = nickname try: - if self.entry: + if self.source == SOURCE_REAUTH: return await self.async_reauth_device() return await self.async_create_device() except BraviaAuthError: @@ -183,7 +188,7 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN): if user_input is not None: self.device_config[CONF_PIN] = user_input[CONF_PIN] try: - if self.entry: + if self.source == SOURCE_REAUTH: return await self.async_reauth_device() return await self.async_create_device() except BraviaAuthError: @@ -247,6 +252,6 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle configuration by re-auth.""" - self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) + self.entry = self._get_reauth_entry() self.device_config = {**entry_data} return await self.async_step_authorize()