Use reauth helpers in lacrosse_view (#128655)

This commit is contained in:
epenet 2024-10-18 17:16:38 +02:00 committed by GitHub
parent d6703b20d3
commit f3f6cb03e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,7 @@ from typing import Any
from lacrosse_view import LaCrosse, Location, LoginError
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -54,7 +54,6 @@ class LaCrosseViewConfigFlow(ConfigFlow, domain=DOMAIN):
"""Initialize the config flow."""
self.data: dict[str, str] = {}
self.locations: list[Location] = []
self._reauth_entry: ConfigEntry | None = None
async def async_step_user(
self, user_input: dict[str, Any] | None = None
@ -83,12 +82,10 @@ class LaCrosseViewConfigFlow(ConfigFlow, domain=DOMAIN):
self.locations = info
# Check if we are reauthenticating
if self._reauth_entry is not None:
self.hass.config_entries.async_update_entry(
self._reauth_entry, data=self._reauth_entry.data | self.data
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
self._get_reauth_entry(), data_updates=self.data
)
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")
_LOGGER.debug("Moving on to location step")
return await self.async_step_location()
@ -139,9 +136,6 @@ class LaCrosseViewConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Reauth in case of a password change or other error."""
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return await self.async_step_user()