mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Use reconfigure helpers in lcn config flow (#128011)
This commit is contained in:
parent
78f4b28697
commit
fcaec2c3f4
@ -9,7 +9,7 @@ import pypck
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlowResult
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_BASE,
|
CONF_BASE,
|
||||||
CONF_DEVICES,
|
CONF_DEVICES,
|
||||||
@ -113,8 +113,6 @@ class LcnFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
VERSION = 1
|
VERSION = 1
|
||||||
MINOR_VERSION = 2
|
MINOR_VERSION = 2
|
||||||
|
|
||||||
_context_entry: ConfigEntry
|
|
||||||
|
|
||||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
||||||
"""Import existing configuration from LCN."""
|
"""Import existing configuration from LCN."""
|
||||||
# validate the imported connection parameters
|
# validate the imported connection parameters
|
||||||
@ -198,36 +196,32 @@ class LcnFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> config_entries.ConfigFlowResult:
|
) -> config_entries.ConfigFlowResult:
|
||||||
"""Reconfigure LCN configuration."""
|
"""Reconfigure LCN configuration."""
|
||||||
self._context_entry = self._get_reconfigure_entry()
|
|
||||||
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
|
||||||
) -> config_entries.ConfigFlowResult:
|
) -> config_entries.ConfigFlowResult:
|
||||||
"""Reconfigure LCN configuration."""
|
"""Reconfigure LCN configuration."""
|
||||||
|
reconfigure_entry = self._get_reconfigure_entry()
|
||||||
errors = None
|
errors = None
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
user_input[CONF_HOST] = self._context_entry.data[CONF_HOST]
|
user_input[CONF_HOST] = reconfigure_entry.data[CONF_HOST]
|
||||||
|
|
||||||
await self.hass.config_entries.async_unload(self._context_entry.entry_id)
|
await self.hass.config_entries.async_unload(reconfigure_entry.entry_id)
|
||||||
if (error := await validate_connection(user_input)) is not None:
|
if (error := await validate_connection(user_input)) is not None:
|
||||||
errors = {CONF_BASE: error}
|
errors = {CONF_BASE: error}
|
||||||
|
|
||||||
if errors is None:
|
if errors is None:
|
||||||
data = self._context_entry.data.copy()
|
return self.async_update_reload_and_abort(
|
||||||
data.update(user_input)
|
reconfigure_entry, data_updates=user_input
|
||||||
self.hass.config_entries.async_update_entry(
|
|
||||||
self._context_entry, data=data
|
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_setup(self._context_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reconfigure_successful")
|
|
||||||
|
|
||||||
await self.hass.config_entries.async_setup(self._context_entry.entry_id)
|
await self.hass.config_entries.async_setup(reconfigure_entry.entry_id)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure_confirm",
|
step_id="reconfigure_confirm",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
CONFIG_SCHEMA, self._context_entry.data
|
CONFIG_SCHEMA, reconfigure_entry.data
|
||||||
),
|
),
|
||||||
errors=errors or {},
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user