From 600e5d675d9d0e58d3f43ec445cd54a33647efe2 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 13 Oct 2026 00:01:37 -0400 Subject: [PATCH] Fix double reload of UniFi entry after reconfigure and reauth (#186049) Co-authored-by: Claude --- homeassistant/components/unifi/hub/hub.py | 33 ++-------------------- tests/components/unifi/test_config_flow.py | 3 ++ 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/unifi/hub/hub.py b/homeassistant/components/unifi/hub/hub.py index ee130ac4d995..9e71e1901074 100644 --- a/homeassistant/components/unifi/hub/hub.py +++ b/homeassistant/components/unifi/hub/hub.py @@ -5,13 +5,6 @@ from typing import TYPE_CHECKING import aiounifi -from homeassistant.const import ( - CONF_HOST, - CONF_PASSWORD, - CONF_PORT, - CONF_USERNAME, - CONF_VERIFY_SSL, -) from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import device_registry as dr from homeassistant.helpers.device_registry import ( @@ -130,33 +123,11 @@ class UnifiHub: async def async_config_entry_updated( hass: HomeAssistant, config_entry: UnifiConfigEntry ) -> None: - """Handle signals of config entry being updated. + """Apply updated options to the hub. - If config entry is updated due to reauth flow - the entry might already have been reset and thus is not available. + Config flows reload the entry after they change its data. """ hub = config_entry.runtime_data - check_keys = { - CONF_HOST: "host", - CONF_PORT: "port", - CONF_USERNAME: "username", - CONF_PASSWORD: "password", - CONF_SITE_ID: "site", - CONF_VERIFY_SSL: "ssl_context", - } - for key, value in check_keys.items(): - if key == CONF_VERIFY_SSL: - # ssl_context is either False or a SSLContext - # object, so we need to compare it differently - if config_entry.data[CONF_VERIFY_SSL] != bool( - getattr(hub.config, value) - ): - hass.config_entries.async_schedule_reload(config_entry.entry_id) - return - if config_entry.data[key] != getattr(hub.config, value): - hass.config_entries.async_schedule_reload(config_entry.entry_id) - return - hub.config = UnifiConfig.from_config_entry(config_entry) async_dispatcher_send(hass, hub.signal_options_update) diff --git a/tests/components/unifi/test_config_flow.py b/tests/components/unifi/test_config_flow.py index f09b2b21d9a7..26d4807c8bf1 100644 --- a/tests/components/unifi/test_config_flow.py +++ b/tests/components/unifi/test_config_flow.py @@ -311,6 +311,7 @@ async def test_reauth_flow_update_configuration( CONF_VERIFY_SSL: True, }, ) + await hass.async_block_till_done() assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reauth_successful" @@ -377,6 +378,7 @@ async def test_reconfigure_flow_update_configuration( CONF_VERIFY_SSL: True, }, ) + await hass.async_block_till_done() assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reconfigure_successful" @@ -437,6 +439,7 @@ async def test_reconfigure_flow_retains_user_input_on_error( result["flow_id"], user_input={**user_input, CONF_HOST: "1.2.3.4", CONF_PORT: 1234}, ) + await hass.async_block_till_done() assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reconfigure_successful"