Add back resolvers config flow dnsip (#65570)
parent
8c0c4f9bca
commit
24cd63973d
|
@ -33,6 +33,13 @@ DATA_SCHEMA = vol.Schema(
|
||||||
vol.Required(CONF_HOSTNAME, default=DEFAULT_HOSTNAME): cv.string,
|
vol.Required(CONF_HOSTNAME, default=DEFAULT_HOSTNAME): cv.string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
DATA_SCHEMA_ADV = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_HOSTNAME, default=DEFAULT_HOSTNAME): cv.string,
|
||||||
|
vol.Optional(CONF_RESOLVER, default=DEFAULT_RESOLVER): cv.string,
|
||||||
|
vol.Optional(CONF_RESOLVER_IPV6, default=DEFAULT_RESOLVER_IPV6): cv.string,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_validate_hostname(
|
async def async_validate_hostname(
|
||||||
|
@ -94,8 +101,8 @@ class DnsIPConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
hostname = user_input[CONF_HOSTNAME]
|
hostname = user_input[CONF_HOSTNAME]
|
||||||
name = DEFAULT_NAME if hostname == DEFAULT_HOSTNAME else hostname
|
name = DEFAULT_NAME if hostname == DEFAULT_HOSTNAME else hostname
|
||||||
resolver = DEFAULT_RESOLVER
|
resolver = user_input.get(CONF_RESOLVER, DEFAULT_RESOLVER)
|
||||||
resolver_ipv6 = DEFAULT_RESOLVER_IPV6
|
resolver_ipv6 = user_input.get(CONF_RESOLVER_IPV6, DEFAULT_RESOLVER_IPV6)
|
||||||
|
|
||||||
validate = await async_validate_hostname(hostname, resolver, resolver_ipv6)
|
validate = await async_validate_hostname(hostname, resolver, resolver_ipv6)
|
||||||
|
|
||||||
|
@ -119,6 +126,12 @@ class DnsIPConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.show_advanced_options is True:
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="user",
|
||||||
|
data_schema=DATA_SCHEMA_ADV,
|
||||||
|
errors=errors,
|
||||||
|
)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=DATA_SCHEMA,
|
data_schema=DATA_SCHEMA,
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"data": {
|
"data": {
|
||||||
"hostname": "The hostname for which to perform the DNS query"
|
"hostname": "The hostname for which to perform the DNS query",
|
||||||
|
"resolver": "Resolver for IPV4 lookup",
|
||||||
|
"resolver_ipv6": "Resolver for IPV6 lookup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"data": {
|
"data": {
|
||||||
"hostname": "The hostname for which to perform the DNS query"
|
"hostname": "The hostname for which to perform the DNS query",
|
||||||
|
"resolver": "Resolver for IPV4 lookup",
|
||||||
|
"resolver_ipv6": "Resolver for IPV6 lookup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ from aiodns.error import DNSError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components.dnsip.config_flow import DATA_SCHEMA, DATA_SCHEMA_ADV
|
||||||
from homeassistant.components.dnsip.const import (
|
from homeassistant.components.dnsip.const import (
|
||||||
CONF_HOSTNAME,
|
CONF_HOSTNAME,
|
||||||
CONF_IPV4,
|
CONF_IPV4,
|
||||||
|
@ -47,6 +48,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
|
assert result["data_schema"] == DATA_SCHEMA
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -79,6 +81,48 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_adv(hass: HomeAssistant) -> None:
|
||||||
|
"""Test we get the form with advanced options on."""
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_USER, "show_advanced_options": True},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["data_schema"] == DATA_SCHEMA_ADV
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.dnsip.config_flow.aiodns.DNSResolver",
|
||||||
|
return_value=RetrieveDNS(),
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.dnsip.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{
|
||||||
|
CONF_HOSTNAME: "home-assistant.io",
|
||||||
|
CONF_RESOLVER: "8.8.8.8",
|
||||||
|
CONF_RESOLVER_IPV6: "2620:0:ccc::2",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
|
assert result2["title"] == "home-assistant.io"
|
||||||
|
assert result2["data"] == {
|
||||||
|
"hostname": "home-assistant.io",
|
||||||
|
"name": "home-assistant.io",
|
||||||
|
"ipv4": True,
|
||||||
|
"ipv6": True,
|
||||||
|
}
|
||||||
|
assert result2["options"] == {
|
||||||
|
"resolver": "8.8.8.8",
|
||||||
|
"resolver_ipv6": "2620:0:ccc::2",
|
||||||
|
}
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_error(hass: HomeAssistant) -> None:
|
async def test_form_error(hass: HomeAssistant) -> None:
|
||||||
"""Test validate url fails."""
|
"""Test validate url fails."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
|
Loading…
Reference in New Issue