mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use reconfigure helpers in brother config flow (#127975)
* Use reconfigure helpers in brother config flow * Don't abort on unique_id mismatch
This commit is contained in:
parent
c22bbc5b91
commit
413a4cd7bd
@ -9,7 +9,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.snmp import async_get_snmp_engine
|
from homeassistant.components.snmp import async_get_snmp_engine
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_TYPE
|
from homeassistant.const import CONF_HOST, CONF_TYPE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -49,8 +49,6 @@ class BrotherConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
entry: ConfigEntry
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.brother: Brother
|
self.brother: Brother
|
||||||
@ -145,18 +143,18 @@ class BrotherConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a reconfiguration flow initialized by the user."""
|
"""Handle a reconfiguration flow initialized by the user."""
|
||||||
self.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
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a reconfiguration flow initialized by the user."""
|
"""Handle a reconfiguration flow initialized by the user."""
|
||||||
|
entry = self._get_reconfigure_entry()
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
try:
|
try:
|
||||||
await validate_input(self.hass, user_input, self.entry.unique_id)
|
await validate_input(self.hass, user_input, entry.unique_id)
|
||||||
except InvalidHost:
|
except InvalidHost:
|
||||||
errors[CONF_HOST] = "wrong_host"
|
errors[CONF_HOST] = "wrong_host"
|
||||||
except (ConnectionError, TimeoutError):
|
except (ConnectionError, TimeoutError):
|
||||||
@ -166,20 +164,18 @@ class BrotherConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
except AnotherDevice:
|
except AnotherDevice:
|
||||||
errors["base"] = "another_device"
|
errors["base"] = "another_device"
|
||||||
else:
|
else:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self.entry,
|
entry,
|
||||||
data=self.entry.data | {CONF_HOST: user_input[CONF_HOST]},
|
data_updates={CONF_HOST: user_input[CONF_HOST]},
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_reload(self.entry.entry_id)
|
|
||||||
return self.async_abort(reason="reconfigure_successful")
|
|
||||||
|
|
||||||
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(
|
||||||
data_schema=RECONFIGURE_SCHEMA,
|
data_schema=RECONFIGURE_SCHEMA,
|
||||||
suggested_values=self.entry.data | (user_input or {}),
|
suggested_values=entry.data | (user_input or {}),
|
||||||
),
|
),
|
||||||
description_placeholders={"printer_name": self.entry.title},
|
description_placeholders={"printer_name": entry.title},
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user