mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Fix ignorability of AdGuard hassio discovery step (#49276)
This commit is contained in:
parent
2c8b7c56f5
commit
ec5c6e18ec
@ -112,40 +112,11 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
This flow is triggered by the discovery component.
|
||||
"""
|
||||
entries = self._async_current_entries()
|
||||
|
||||
if not entries:
|
||||
self._hassio_discovery = discovery_info
|
||||
await self._async_handle_discovery_without_unique_id()
|
||||
|
||||
self._hassio_discovery = discovery_info
|
||||
return await self.async_step_hassio_confirm()
|
||||
|
||||
cur_entry = entries[0]
|
||||
|
||||
if (
|
||||
cur_entry.data[CONF_HOST] == discovery_info[CONF_HOST]
|
||||
and cur_entry.data[CONF_PORT] == discovery_info[CONF_PORT]
|
||||
):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
is_loaded = cur_entry.state == config_entries.ENTRY_STATE_LOADED
|
||||
|
||||
if is_loaded:
|
||||
await self.hass.config_entries.async_unload(cur_entry.entry_id)
|
||||
|
||||
self.hass.config_entries.async_update_entry(
|
||||
cur_entry,
|
||||
data={
|
||||
**cur_entry.data,
|
||||
CONF_HOST: discovery_info[CONF_HOST],
|
||||
CONF_PORT: discovery_info[CONF_PORT],
|
||||
},
|
||||
)
|
||||
|
||||
if is_loaded:
|
||||
await self.hass.config_entries.async_setup(cur_entry.entry_id)
|
||||
|
||||
return self.async_abort(reason="existing_instance_updated")
|
||||
|
||||
async def async_step_hassio_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResultDict:
|
||||
|
@ -1,7 +1,4 @@
|
||||
"""Tests for the AdGuard Home config flow."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
@ -120,88 +117,22 @@ async def test_hassio_already_configured(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_hassio_update_instance_not_running(hass: HomeAssistant) -> None:
|
||||
"""Test we only allow a single config flow."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={"host": "mock-adguard", "port": "3000"}
|
||||
async def test_hassio_ignored(hass: HomeAssistant) -> None:
|
||||
"""Test we supervisor discovered instance can be ignored."""
|
||||
MockConfigEntry(domain=DOMAIN, source=config_entries.SOURCE_IGNORE).add_to_hass(
|
||||
hass
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
assert entry.state == config_entries.ENTRY_STATE_NOT_LOADED
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
data={
|
||||
"addon": "AdGuard Home Addon",
|
||||
"host": "mock-adguard-updated",
|
||||
"port": "3000",
|
||||
},
|
||||
data={"addon": "AdGuard Home Addon", "host": "mock-adguard", "port": "3000"},
|
||||
context={"source": "hassio"},
|
||||
)
|
||||
|
||||
assert "type" in result
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "existing_instance_updated"
|
||||
|
||||
|
||||
async def test_hassio_update_instance_running(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test we only allow a single config flow."""
|
||||
aioclient_mock.get(
|
||||
"http://mock-adguard-updated:3000/control/status",
|
||||
json={"version": "v0.99.0"},
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
aioclient_mock.get(
|
||||
"http://mock-adguard:3000/control/status",
|
||||
json={"version": "v0.99.0"},
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
"host": "mock-adguard",
|
||||
"port": "3000",
|
||||
"verify_ssl": False,
|
||||
"username": None,
|
||||
"password": None,
|
||||
"ssl": False,
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries,
|
||||
"async_forward_entry_setup",
|
||||
return_value=True,
|
||||
) as mock_load:
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state == config_entries.ENTRY_STATE_LOADED
|
||||
assert len(mock_load.mock_calls) == 2
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries,
|
||||
"async_forward_entry_unload",
|
||||
return_value=True,
|
||||
) as mock_unload, patch.object(
|
||||
hass.config_entries,
|
||||
"async_forward_entry_setup",
|
||||
return_value=True,
|
||||
) as mock_load:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
data={
|
||||
"addon": "AdGuard Home Addon",
|
||||
"host": "mock-adguard-updated",
|
||||
"port": "3000",
|
||||
},
|
||||
context={"source": "hassio"},
|
||||
)
|
||||
assert len(mock_unload.mock_calls) == 2
|
||||
assert len(mock_load.mock_calls) == 2
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "existing_instance_updated"
|
||||
assert entry.data["host"] == "mock-adguard-updated"
|
||||
assert "reason" in result
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_hassio_confirm(
|
||||
|
Loading…
x
Reference in New Issue
Block a user