Skip to content

Commit

Permalink
Use reauth helpers in fibaro (home-assistant#128567)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 18, 2024
1 parent 5fa6202 commit 275c86a
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions homeassistant/components/fibaro/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from slugify import slugify
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
from homeassistant.core import HomeAssistant

Expand Down Expand Up @@ -63,10 +63,6 @@ class FibaroConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

def __init__(self) -> None:
"""Initialize."""
self._reauth_entry: ConfigEntry | None = None

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
Expand Down Expand Up @@ -94,9 +90,6 @@ async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle reauthentication."""
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return await self.async_step_reauth_confirm()

async def async_step_reauth_confirm(
Expand All @@ -105,29 +98,24 @@ async def async_step_reauth_confirm(
"""Handle a flow initiated by reauthentication."""
errors = {}

assert self._reauth_entry
reauth_entry = self._get_reauth_entry()

if user_input is not None:
new_data = self._reauth_entry.data | user_input
new_data = reauth_entry.data | user_input
try:
await _validate_input(self.hass, new_data)
except FibaroConnectFailed:
errors["base"] = "cannot_connect"
except FibaroAuthFailed:
errors["base"] = "invalid_auth"
else:
self.hass.config_entries.async_update_entry(
self._reauth_entry, data=new_data
)
self.hass.async_create_task(
self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
return self.async_update_reload_and_abort(
reauth_entry, data_updates=user_input
)
return self.async_abort(reason="reauth_successful")

return self.async_show_form(
step_id="reauth_confirm",
data_schema=vol.Schema({vol.Required(CONF_PASSWORD): str}),
errors=errors,
description_placeholders={
CONF_USERNAME: self._reauth_entry.data[CONF_USERNAME]
},
description_placeholders={CONF_USERNAME: reauth_entry.data[CONF_USERNAME]},
)

0 comments on commit 275c86a

Please sign in to comment.