mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use _get_reauth/reconfigure_entry in tedee (#127312)
This commit is contained in:
parent
db9257f9fa
commit
fac3d575c9
@ -14,7 +14,13 @@ from pytedee_async import (
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.webhook import async_generate_id as webhook_generate_id
|
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.const import CONF_HOST, CONF_WEBHOOK_ID
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
@ -29,8 +35,8 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
VERSION = 1
|
VERSION = 1
|
||||||
MINOR_VERSION = 2
|
MINOR_VERSION = 2
|
||||||
|
|
||||||
reauth_entry: ConfigEntry | None = None
|
reauth_entry: ConfigEntry
|
||||||
reconfigure_entry: ConfigEntry | None = None
|
reconfigure_entry: ConfigEntry
|
||||||
|
|
||||||
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
|
||||||
@ -39,7 +45,7 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
if self.reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
host = self.reauth_entry.data[CONF_HOST]
|
host = self.reauth_entry.data[CONF_HOST]
|
||||||
else:
|
else:
|
||||||
host = user_input[CONF_HOST]
|
host = user_input[CONF_HOST]
|
||||||
@ -59,13 +65,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.error("Error during local bridge discovery: %s", exc)
|
_LOGGER.error("Error during local bridge discovery: %s", exc)
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
else:
|
else:
|
||||||
if self.reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self.reauth_entry,
|
self.reauth_entry,
|
||||||
data={**self.reauth_entry.data, **user_input},
|
data={**self.reauth_entry.data, **user_input},
|
||||||
reason="reauth_successful",
|
reason="reauth_successful",
|
||||||
)
|
)
|
||||||
if self.reconfigure_entry:
|
if self.source == SOURCE_RECONFIGURE:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self.reconfigure_entry,
|
self.reconfigure_entry,
|
||||||
data={**self.reconfigure_entry.data, **user_input},
|
data={**self.reconfigure_entry.data, **user_input},
|
||||||
@ -97,17 +103,13 @@ class TedeeConfigFlow(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.reauth_entry = self._get_reauth_entry()
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Dialog that informs the user that reauth is required."""
|
"""Dialog that informs the user that reauth is required."""
|
||||||
assert self.reauth_entry
|
|
||||||
|
|
||||||
if not user_input:
|
if not user_input:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
@ -126,17 +128,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform a reconfiguration."""
|
"""Perform a reconfiguration."""
|
||||||
self.reconfigure_entry = self.hass.config_entries.async_get_entry(
|
self.reconfigure_entry = self._get_reconfigure_entry()
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_reconfigure_confirm()
|
return await self.async_step_reconfigure_confirm()
|
||||||
|
|
||||||
async def async_step_reconfigure_confirm(
|
async def async_step_reconfigure_confirm(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Add reconfigure step to allow to reconfigure a config entry."""
|
"""Add reconfigure step to allow to reconfigure a config entry."""
|
||||||
assert self.reconfigure_entry
|
|
||||||
|
|
||||||
if not user_input:
|
if not user_input:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure_confirm",
|
step_id="reconfigure_confirm",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user