mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Refactor duplicate host check in homeworks config flow (#128627)
This commit is contained in:
parent
a7b5e4323e
commit
8a4d72e3b1
@ -558,21 +558,17 @@ class HomeworksConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Config flow for Lutron Homeworks."""
|
"""Config flow for Lutron Homeworks."""
|
||||||
|
|
||||||
async def _validate_edit_controller(
|
async def _validate_edit_controller(
|
||||||
self, user_input: dict[str, Any]
|
self, user_input: dict[str, Any], reconfigure_entry: ConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Validate controller setup."""
|
"""Validate controller setup."""
|
||||||
_validate_credentials(user_input)
|
_validate_credentials(user_input)
|
||||||
user_input[CONF_PORT] = int(user_input[CONF_PORT])
|
user_input[CONF_PORT] = int(user_input[CONF_PORT])
|
||||||
|
|
||||||
our_entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
if any(
|
||||||
assert our_entry
|
entry.entry_id != reconfigure_entry.entry_id
|
||||||
other_entries = self._async_current_entries()
|
and user_input[CONF_HOST] == entry.options[CONF_HOST]
|
||||||
for entry in other_entries:
|
|
||||||
if entry.entry_id == our_entry.entry_id:
|
|
||||||
continue
|
|
||||||
if (
|
|
||||||
user_input[CONF_HOST] == entry.options[CONF_HOST]
|
|
||||||
and user_input[CONF_PORT] == entry.options[CONF_PORT]
|
and user_input[CONF_PORT] == entry.options[CONF_PORT]
|
||||||
|
for entry in self._async_current_entries()
|
||||||
):
|
):
|
||||||
raise SchemaFlowError("duplicated_host_port")
|
raise SchemaFlowError("duplicated_host_port")
|
||||||
|
|
||||||
@ -600,7 +596,7 @@ class HomeworksConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
CONF_PASSWORD: user_input.get(CONF_PASSWORD),
|
CONF_PASSWORD: user_input.get(CONF_PASSWORD),
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
await self._validate_edit_controller(user_input)
|
await self._validate_edit_controller(user_input, reconfigure_entry)
|
||||||
except SchemaFlowError as err:
|
except SchemaFlowError as err:
|
||||||
errors["base"] = str(err)
|
errors["base"] = str(err)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user