From 8a4d72e3b1dd799627286fdd1835f5405e433865 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:49:06 +0200 Subject: [PATCH] Refactor duplicate host check in homeworks config flow (#128627) --- .../components/homeworks/config_flow.py | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/homeworks/config_flow.py b/homeassistant/components/homeworks/config_flow.py index 3af963e3d5c..d1fa7774ef6 100644 --- a/homeassistant/components/homeworks/config_flow.py +++ b/homeassistant/components/homeworks/config_flow.py @@ -558,23 +558,19 @@ class HomeworksConfigFlowHandler(ConfigFlow, domain=DOMAIN): """Config flow for Lutron Homeworks.""" async def _validate_edit_controller( - self, user_input: dict[str, Any] + self, user_input: dict[str, Any], reconfigure_entry: ConfigEntry ) -> dict[str, Any]: """Validate controller setup.""" _validate_credentials(user_input) user_input[CONF_PORT] = int(user_input[CONF_PORT]) - our_entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) - assert our_entry - other_entries = self._async_current_entries() - 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] - ): - raise SchemaFlowError("duplicated_host_port") + if any( + entry.entry_id != reconfigure_entry.entry_id + and user_input[CONF_HOST] == entry.options[CONF_HOST] + and user_input[CONF_PORT] == entry.options[CONF_PORT] + for entry in self._async_current_entries() + ): + raise SchemaFlowError("duplicated_host_port") await _try_connection(user_input) return user_input @@ -600,7 +596,7 @@ class HomeworksConfigFlowHandler(ConfigFlow, domain=DOMAIN): CONF_PASSWORD: user_input.get(CONF_PASSWORD), } try: - await self._validate_edit_controller(user_input) + await self._validate_edit_controller(user_input, reconfigure_entry) except SchemaFlowError as err: errors["base"] = str(err) else: