mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Use reconfigure helpers in fronius config flow (#128001)
* Use reconfigure helpers in fronius * Drop _async_abort_entries_match
This commit is contained in:
parent
f6188949f3
commit
7c6b517672
@ -10,7 +10,7 @@ from pyfronius import Fronius, FroniusError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.dhcp import DhcpServiceInfo
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@ -72,7 +72,6 @@ class FroniusConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
def __init__(self) -> None:
|
||||
"""Initialize flow."""
|
||||
self.info: FroniusConfigEntryData
|
||||
self._entry: ConfigEntry | None = None
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
@ -145,6 +144,7 @@ class FroniusConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Add reconfigure step to allow to reconfigure a config entry."""
|
||||
errors = {}
|
||||
reconfigure_entry = self._get_reconfigure_entry()
|
||||
|
||||
if user_input is not None:
|
||||
try:
|
||||
@ -155,33 +155,16 @@ class FroniusConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
# Config didn't change or is already configured in another entry
|
||||
self._async_abort_entries_match(dict(info))
|
||||
await self.async_set_unique_id(unique_id)
|
||||
self._abort_if_unique_id_mismatch()
|
||||
|
||||
existing_entry = await self.async_set_unique_id(
|
||||
unique_id, raise_on_progress=False
|
||||
)
|
||||
assert self._entry is not None
|
||||
if existing_entry and existing_entry.entry_id != self._entry.entry_id:
|
||||
# Uid of device is already configured in another entry (but with different host)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_update_reload_and_abort(reconfigure_entry, data=info)
|
||||
|
||||
return self.async_update_reload_and_abort(
|
||||
self._entry,
|
||||
data=info,
|
||||
reason="reconfigure_successful",
|
||||
)
|
||||
|
||||
if self._entry is None:
|
||||
self._entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
assert self._entry is not None
|
||||
host = self._entry.data[CONF_HOST]
|
||||
host = reconfigure_entry.data[CONF_HOST]
|
||||
return self.async_show_form(
|
||||
step_id="reconfigure",
|
||||
data_schema=vol.Schema({vol.Required(CONF_HOST, default=host): str}),
|
||||
description_placeholders={"device": self._entry.title},
|
||||
description_placeholders={"device": reconfigure_entry.title},
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,8 @@
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"invalid_host": "[%key:common::config_flow::error::invalid_host%]",
|
||||
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
||||
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]",
|
||||
"unique_id_mismatch": "The identifier does not match the previous identifier"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
|
@ -344,7 +344,7 @@ async def test_reconfigure(hass: HomeAssistant) -> None:
|
||||
"""Test reconfiguring an entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="123.4567890",
|
||||
unique_id="1234567",
|
||||
data={
|
||||
CONF_HOST: "10.1.2.3",
|
||||
"is_logger": True,
|
||||
@ -490,7 +490,7 @@ async def test_reconfigure_already_configured(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert result["reason"] == "unique_id_mismatch"
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
|
||||
@ -531,4 +531,4 @@ async def test_reconfigure_already_existing(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.ABORT
|
||||
assert result2["reason"] == "already_configured"
|
||||
assert result2["reason"] == "unique_id_mismatch"
|
||||
|
Loading…
x
Reference in New Issue
Block a user