Use reauth helpers in system_bridge (#130422)

This commit is contained in:
epenet 2024-11-15 12:33:03 +01:00 committed by GitHub
parent 20b1e38d24
commit de1905a529
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 10 deletions

View File

@ -17,7 +17,7 @@ from systembridgemodels.modules import GetData, Module
import voluptuous as vol import voluptuous as vol
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
@ -124,7 +124,6 @@ class SystemBridgeConfigFlow(
"""Initialize flow.""" """Initialize flow."""
self._name: str | None = None self._name: str | None = None
self._input: dict[str, Any] = {} self._input: dict[str, Any] = {}
self._reauth = False
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
@ -157,15 +156,13 @@ class SystemBridgeConfigFlow(
user_input = {**self._input, **user_input} user_input = {**self._input, **user_input}
errors, info = await _async_get_info(self.hass, user_input) errors, info = await _async_get_info(self.hass, user_input)
if not errors and info is not None: if not errors and info is not None:
# Check if already configured await self.async_set_unique_id(info["uuid"])
existing_entry = await self.async_set_unique_id(info["uuid"])
if self._reauth and existing_entry: if self.source == SOURCE_REAUTH:
self.hass.config_entries.async_update_entry( self._abort_if_unique_id_mismatch()
existing_entry, data=user_input return self.async_update_reload_and_abort(
self._get_reauth_entry(), data=user_input
) )
await self.hass.config_entries.async_reload(existing_entry.entry_id)
return self.async_abort(reason="reauth_successful")
self._abort_if_unique_id_configured( self._abort_if_unique_id_configured(
updates={CONF_HOST: info["hostname"]} updates={CONF_HOST: info["hostname"]}
@ -212,7 +209,6 @@ class SystemBridgeConfigFlow(
CONF_HOST: entry_data[CONF_HOST], CONF_HOST: entry_data[CONF_HOST],
CONF_PORT: entry_data[CONF_PORT], CONF_PORT: entry_data[CONF_PORT],
} }
self._reauth = True
return await self.async_step_authenticate() return await self.async_step_authenticate()

View File

@ -3,6 +3,7 @@
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
"unique_id_mismatch": "The identifier does not match the previous identifier",
"unsupported_version": "Your version of System Bridge is not supported. Please upgrade to the latest version.", "unsupported_version": "Your version of System Bridge is not supported. Please upgrade to the latest version.",
"unknown": "[%key:common::config_flow::error::unknown%]" "unknown": "[%key:common::config_flow::error::unknown%]"
}, },