Fix double reload of UniFi entry after reconfigure and reauth (#186049)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Paulus Schoutsen
2026-10-13 00:01:37 -04:00
committed by GitHub
co-authored by Claude
parent 1ab6184ef4
commit 600e5d675d
2 changed files with 5 additions and 31 deletions
+2 -31
View File
@@ -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)
@@ -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"