mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use new reauth helpers in sfr_box (#128739)
This commit is contained in:
parent
38e7dcfd12
commit
e43bf3b05a
@ -9,7 +9,7 @@ from sfrbox_api.bridge import SFRBox
|
|||||||
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
|
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
@ -37,7 +37,6 @@ class SFRBoxFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
VERSION = 1
|
VERSION = 1
|
||||||
_box: SFRBox
|
_box: SFRBox
|
||||||
_config: dict[str, Any] = {}
|
_config: dict[str, Any] = {}
|
||||||
_reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, str] | None = None
|
self, user_input: dict[str, str] | None = None
|
||||||
@ -88,19 +87,16 @@ class SFRBoxFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
except SFRBoxAuthenticationError:
|
except SFRBoxAuthenticationError:
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
else:
|
else:
|
||||||
if reauth_entry := self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
data = {**reauth_entry.data, **user_input}
|
return self.async_update_reload_and_abort(
|
||||||
self.hass.config_entries.async_update_entry(reauth_entry, data=data)
|
self._get_reauth_entry(), data_updates=user_input
|
||||||
self.hass.async_create_task(
|
|
||||||
self.hass.config_entries.async_reload(reauth_entry.entry_id)
|
|
||||||
)
|
)
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
self._config.update(user_input)
|
self._config.update(user_input)
|
||||||
return self.async_create_entry(title="SFR Box", data=self._config)
|
return self.async_create_entry(title="SFR Box", data=self._config)
|
||||||
|
|
||||||
suggested_values: Mapping[str, Any] | None = user_input
|
suggested_values: Mapping[str, Any] | None = user_input
|
||||||
if self._reauth_entry and not suggested_values:
|
if self.source == SOURCE_REAUTH and not suggested_values:
|
||||||
suggested_values = self._reauth_entry.data
|
suggested_values = self._get_reauth_entry().data
|
||||||
|
|
||||||
data_schema = self.add_suggested_values_to_schema(AUTH_SCHEMA, suggested_values)
|
data_schema = self.add_suggested_values_to_schema(AUTH_SCHEMA, suggested_values)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
@ -117,8 +113,5 @@ class SFRBoxFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle failed credentials."""
|
"""Handle failed credentials."""
|
||||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
self._box = SFRBox(ip=entry_data[CONF_HOST], client=get_async_client(self.hass))
|
self._box = SFRBox(ip=entry_data[CONF_HOST], client=get_async_client(self.hass))
|
||||||
return await self.async_step_auth()
|
return await self.async_step_auth()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user