Use new reauth helpers in sfr_box (#128739)

This commit is contained in:
epenet 2024-10-19 14:37:40 +02:00 committed by GitHub
parent 38e7dcfd12
commit e43bf3b05a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,7 @@ from sfrbox_api.bridge import SFRBox
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
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.helpers import selector
from homeassistant.helpers.httpx_client import get_async_client
@ -37,7 +37,6 @@ class SFRBoxFlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1
_box: SFRBox
_config: dict[str, Any] = {}
_reauth_entry: ConfigEntry | None = None
async def async_step_user(
self, user_input: dict[str, str] | None = None
@ -88,19 +87,16 @@ class SFRBoxFlowHandler(ConfigFlow, domain=DOMAIN):
except SFRBoxAuthenticationError:
errors["base"] = "invalid_auth"
else:
if reauth_entry := self._reauth_entry:
data = {**reauth_entry.data, **user_input}
self.hass.config_entries.async_update_entry(reauth_entry, data=data)
self.hass.async_create_task(
self.hass.config_entries.async_reload(reauth_entry.entry_id)
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
self._get_reauth_entry(), data_updates=user_input
)
return self.async_abort(reason="reauth_successful")
self._config.update(user_input)
return self.async_create_entry(title="SFR Box", data=self._config)
suggested_values: Mapping[str, Any] | None = user_input
if self._reauth_entry and not suggested_values:
suggested_values = self._reauth_entry.data
if self.source == SOURCE_REAUTH and not suggested_values:
suggested_values = self._get_reauth_entry().data
data_schema = self.add_suggested_values_to_schema(AUTH_SCHEMA, suggested_values)
return self.async_show_form(
@ -117,8 +113,5 @@ class SFRBoxFlowHandler(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""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))
return await self.async_step_auth()