Skip to content

Commit

Permalink
Use new reauth helpers in vicare (#128779)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 20, 2024
1 parent 2bc642a commit 7fa3597
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions homeassistant/components/vicare/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import voluptuous as vol

from homeassistant.components import dhcp
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_CLIENT_ID, CONF_PASSWORD, CONF_USERNAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import format_mac
Expand Down Expand Up @@ -50,7 +50,6 @@ class ViCareConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for ViCare."""

VERSION = 1
entry: ConfigEntry | None

async def async_step_user(
self, user_input: dict[str, Any] | None = None
Expand Down Expand Up @@ -81,19 +80,18 @@ async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle re-authentication with ViCare."""
self.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(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Confirm re-authentication with ViCare."""
errors: dict[str, str] = {}
assert self.entry is not None

reauth_entry = self._get_reauth_entry()
if user_input:
data = {
**self.entry.data,
**reauth_entry.data,
**user_input,
}

Expand All @@ -102,17 +100,12 @@ async def async_step_reauth_confirm(
except (PyViCareInvalidConfigurationError, PyViCareInvalidCredentialsError):
errors["base"] = "invalid_auth"
else:
self.hass.config_entries.async_update_entry(
self.entry,
data=data,
)
await self.hass.config_entries.async_reload(self.entry.entry_id)
return self.async_abort(reason="reauth_successful")
return self.async_update_reload_and_abort(reauth_entry, data=data)

return self.async_show_form(
step_id="reauth_confirm",
data_schema=self.add_suggested_values_to_schema(
REAUTH_SCHEMA, self.entry.data
REAUTH_SCHEMA, reauth_entry.data
),
errors=errors,
)
Expand Down

0 comments on commit 7fa3597

Please sign in to comment.