mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Fix bad access to UniFi runtime_data when not assigned (#121725)
* Fix bad access to runtime_data when not assigned * Fix review comment * Clean up if statements
This commit is contained in:
parent
70f05e5f13
commit
61111f5d71
@ -164,13 +164,12 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN):
|
||||
config_entry = self.reauth_config_entry
|
||||
abort_reason = "reauth_successful"
|
||||
|
||||
if (
|
||||
config_entry is not None
|
||||
and config_entry.state is not ConfigEntryState.NOT_LOADED
|
||||
):
|
||||
hub = config_entry.runtime_data
|
||||
|
||||
if hub and hub.available:
|
||||
if config_entry:
|
||||
if (
|
||||
config_entry.state is ConfigEntryState.LOADED
|
||||
and (hub := config_entry.runtime_data)
|
||||
and hub.available
|
||||
):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
return self.async_update_reload_and_abort(
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Test UniFi Network config flow."""
|
||||
|
||||
from collections.abc import Callable
|
||||
import socket
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
@ -338,6 +339,44 @@ async def test_reauth_flow_update_configuration(
|
||||
assert config_entry.data[CONF_PASSWORD] == "new_pass"
|
||||
|
||||
|
||||
async def test_reauth_flow_update_configuration_on_not_loaded_entry(
|
||||
hass: HomeAssistant, config_entry_factory: Callable[[], ConfigEntry]
|
||||
) -> None:
|
||||
"""Verify reauth flow can update hub configuration on a not loaded entry."""
|
||||
with patch("aiounifi.Controller.login", side_effect=aiounifi.errors.RequestError):
|
||||
config_entry = await config_entry_factory()
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
UNIFI_DOMAIN,
|
||||
context={
|
||||
"source": SOURCE_REAUTH,
|
||||
"unique_id": config_entry.unique_id,
|
||||
"entry_id": config_entry.entry_id,
|
||||
},
|
||||
data=config_entry.data,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_USERNAME: "new_name",
|
||||
CONF_PASSWORD: "new_pass",
|
||||
CONF_PORT: 1234,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert config_entry.data[CONF_HOST] == "1.2.3.4"
|
||||
assert config_entry.data[CONF_USERNAME] == "new_name"
|
||||
assert config_entry.data[CONF_PASSWORD] == "new_pass"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("client_payload", [CLIENTS])
|
||||
@pytest.mark.parametrize("device_payload", [DEVICES])
|
||||
@pytest.mark.parametrize("wlan_payload", [WLANS])
|
||||
|
Loading…
x
Reference in New Issue
Block a user