mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Use new reauth helpers in volvooncall (#128782)
This commit is contained in:
parent
990987ac92
commit
6af6b73c89
@ -9,7 +9,7 @@ from typing import Any
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from volvooncall import Connection
|
from volvooncall import Connection
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_REGION,
|
CONF_REGION,
|
||||||
@ -35,7 +35,6 @@ class VolvoOnCallConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""VolvoOnCall config flow."""
|
"""VolvoOnCall config flow."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
_reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
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
|
||||||
@ -53,7 +52,7 @@ class VolvoOnCallConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
await self.async_set_unique_id(user_input[CONF_USERNAME])
|
await self.async_set_unique_id(user_input[CONF_USERNAME])
|
||||||
|
|
||||||
if not self._reauth_entry:
|
if self.source != SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -64,21 +63,18 @@ class VolvoOnCallConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unhandled exception in user step")
|
_LOGGER.exception("Unhandled exception in user step")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
if not errors:
|
if not errors:
|
||||||
if self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self._reauth_entry, data=self._reauth_entry.data | user_input
|
self._get_reauth_entry(), data_updates=user_input
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_reload(
|
|
||||||
self._reauth_entry.entry_id
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_USERNAME], data=user_input
|
title=user_input[CONF_USERNAME], data=user_input
|
||||||
)
|
)
|
||||||
elif self._reauth_entry:
|
elif self.source == SOURCE_REAUTH:
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
for key in defaults:
|
for key in defaults:
|
||||||
defaults[key] = self._reauth_entry.data.get(key)
|
defaults[key] = reauth_entry.data.get(key)
|
||||||
|
|
||||||
user_schema = vol.Schema(
|
user_schema = vol.Schema(
|
||||||
{
|
{
|
||||||
@ -110,9 +106,6 @@ class VolvoOnCallConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
async def is_valid(self, user_input):
|
async def is_valid(self, user_input):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user