Use reauth helpers in braviatv config flow (#127437)

This commit is contained in:
epenet 2024-10-03 19:49:28 +02:00 committed by GitHub
parent 09014e3390
commit 0bbca596a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,12 +11,7 @@ from pybravia import BraviaAuthError, BraviaClient, BraviaError, BraviaNotSuppor
import voluptuous as vol import voluptuous as vol
from homeassistant.components import ssdp from homeassistant.components import ssdp
from homeassistant.config_entries import ( from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
SOURCE_REAUTH,
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
)
from homeassistant.const import CONF_CLIENT_ID, CONF_HOST, CONF_MAC, CONF_NAME, CONF_PIN from homeassistant.const import CONF_CLIENT_ID, CONF_HOST, CONF_MAC, CONF_NAME, CONF_PIN
from homeassistant.helpers import instance_id from homeassistant.helpers import instance_id
from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.aiohttp_client import async_create_clientsession
@ -38,8 +33,6 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
entry: ConfigEntry
def __init__(self) -> None: def __init__(self) -> None:
"""Initialize config flow.""" """Initialize config flow."""
self.client: BraviaClient | None = None self.client: BraviaClient | None = None
@ -95,9 +88,9 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN):
assert self.client assert self.client
await self.async_connect_device() await self.async_connect_device()
self.hass.config_entries.async_update_entry(self.entry, data=self.device_config) return self.async_update_reload_and_abort(
await self.hass.config_entries.async_reload(self.entry.entry_id) self._get_reauth_entry(), data=self.device_config
return self.async_abort(reason="reauth_successful") )
async def async_step_user( async def async_step_user(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
@ -252,6 +245,5 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle configuration by re-auth.""" """Handle configuration by re-auth."""
self.entry = self._get_reauth_entry()
self.device_config = {**entry_data} self.device_config = {**entry_data}
return await self.async_step_authorize() return await self.async_step_authorize()