Skip to content
Snippets Groups Projects
Unverified Commit fac3d575 authored by epenet's avatar epenet Committed by GitHub
Browse files

Use _get_reauth/reconfigure_entry in tedee (#127312)

parent db9257f9
Branches
Tags
No related merge requests found
......@@ -14,7 +14,13 @@ from pytedee_async import (
import voluptuous as vol
from homeassistant.components.webhook import async_generate_id as webhook_generate_id
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import (
SOURCE_REAUTH,
SOURCE_RECONFIGURE,
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
)
from homeassistant.const import CONF_HOST, CONF_WEBHOOK_ID
from homeassistant.helpers.aiohttp_client import async_get_clientsession
......@@ -29,8 +35,8 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
MINOR_VERSION = 2
reauth_entry: ConfigEntry | None = None
reconfigure_entry: ConfigEntry | None = None
reauth_entry: ConfigEntry
reconfigure_entry: ConfigEntry
async def async_step_user(
self, user_input: dict[str, Any] | None = None
......@@ -39,7 +45,7 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
errors: dict[str, str] = {}
if user_input is not None:
if self.reauth_entry:
if self.source == SOURCE_REAUTH:
host = self.reauth_entry.data[CONF_HOST]
else:
host = user_input[CONF_HOST]
......@@ -59,13 +65,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
_LOGGER.error("Error during local bridge discovery: %s", exc)
errors["base"] = "cannot_connect"
else:
if self.reauth_entry:
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
self.reauth_entry,
data={**self.reauth_entry.data, **user_input},
reason="reauth_successful",
)
if self.reconfigure_entry:
if self.source == SOURCE_RECONFIGURE:
return self.async_update_reload_and_abort(
self.reconfigure_entry,
data={**self.reconfigure_entry.data, **user_input},
......@@ -97,17 +103,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Perform reauth upon an API authentication error."""
self.reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
self.reauth_entry = self._get_reauth_entry()
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Dialog that informs the user that reauth is required."""
assert self.reauth_entry
if not user_input:
return self.async_show_form(
step_id="reauth_confirm",
......@@ -126,17 +128,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Perform a reconfiguration."""
self.reconfigure_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
self.reconfigure_entry = self._get_reconfigure_entry()
return await self.async_step_reconfigure_confirm()
async def async_step_reconfigure_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Add reconfigure step to allow to reconfigure a config entry."""
assert self.reconfigure_entry
if not user_input:
return self.async_show_form(
step_id="reconfigure_confirm",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment