Fix options for dnsip (#65369)
parent
d24fedbe97
commit
390d32c71b
|
@ -110,11 +110,13 @@ class DnsIPConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
data={
|
||||
CONF_HOSTNAME: hostname,
|
||||
CONF_NAME: name,
|
||||
CONF_RESOLVER: resolver,
|
||||
CONF_RESOLVER_IPV6: resolver_ipv6,
|
||||
CONF_IPV4: validate[CONF_IPV4],
|
||||
CONF_IPV6: validate[CONF_IPV6],
|
||||
},
|
||||
options={
|
||||
CONF_RESOLVER: resolver,
|
||||
CONF_RESOLVER_IPV6: resolver_ipv6,
|
||||
},
|
||||
)
|
||||
|
||||
return self.async_show_form(
|
||||
|
|
|
@ -79,10 +79,8 @@ async def async_setup_entry(
|
|||
hostname = entry.data[CONF_HOSTNAME]
|
||||
name = entry.data[CONF_NAME]
|
||||
|
||||
resolver_ipv4 = entry.options.get(CONF_RESOLVER, entry.data[CONF_RESOLVER])
|
||||
resolver_ipv6 = entry.options.get(
|
||||
CONF_RESOLVER_IPV6, entry.data[CONF_RESOLVER_IPV6]
|
||||
)
|
||||
resolver_ipv4 = entry.options[CONF_RESOLVER]
|
||||
resolver_ipv6 = entry.options[CONF_RESOLVER_IPV6]
|
||||
entities = []
|
||||
if entry.data[CONF_IPV4]:
|
||||
entities.append(WanIpSensor(name, hostname, resolver_ipv4, False))
|
||||
|
|
|
@ -69,11 +69,13 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
assert result2["data"] == {
|
||||
"hostname": "home-assistant.io",
|
||||
"name": "home-assistant.io",
|
||||
"resolver": "208.67.222.222",
|
||||
"resolver_ipv6": "2620:0:ccc::2",
|
||||
"ipv4": True,
|
||||
"ipv6": True,
|
||||
}
|
||||
assert result2["options"] == {
|
||||
"resolver": "208.67.222.222",
|
||||
"resolver_ipv6": "2620:0:ccc::2",
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
@ -101,34 +103,41 @@ async def test_form_error(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"p_input,p_output",
|
||||
"p_input,p_output,p_options",
|
||||
[
|
||||
(
|
||||
{CONF_HOSTNAME: "home-assistant.io"},
|
||||
{
|
||||
"hostname": "home-assistant.io",
|
||||
"name": "home-assistant.io",
|
||||
"resolver": "208.67.222.222",
|
||||
"resolver_ipv6": "2620:0:ccc::2",
|
||||
"ipv4": True,
|
||||
"ipv6": True,
|
||||
},
|
||||
{
|
||||
"resolver": "208.67.222.222",
|
||||
"resolver_ipv6": "2620:0:ccc::2",
|
||||
},
|
||||
),
|
||||
(
|
||||
{},
|
||||
{
|
||||
"hostname": "myip.opendns.com",
|
||||
"name": "myip",
|
||||
"resolver": "208.67.222.222",
|
||||
"resolver_ipv6": "2620:0:ccc::2",
|
||||
"ipv4": True,
|
||||
"ipv6": True,
|
||||
},
|
||||
{
|
||||
"resolver": "208.67.222.222",
|
||||
"resolver_ipv6": "2620:0:ccc::2",
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_import_flow_success(
|
||||
hass: HomeAssistant, p_input: dict[str, str], p_output: dict[str, str]
|
||||
hass: HomeAssistant,
|
||||
p_input: dict[str, str],
|
||||
p_output: dict[str, str],
|
||||
p_options: dict[str, str],
|
||||
) -> None:
|
||||
"""Test a successful import of YAML."""
|
||||
|
||||
|
@ -149,6 +158,7 @@ async def test_import_flow_success(
|
|||
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result2["title"] == p_output["name"]
|
||||
assert result2["data"] == p_output
|
||||
assert result2["options"] == p_options
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
@ -160,11 +170,13 @@ async def test_flow_already_exist(hass: HomeAssistant) -> None:
|
|||
data={
|
||||
CONF_HOSTNAME: "home-assistant.io",
|
||||
CONF_NAME: "home-assistant.io",
|
||||
CONF_RESOLVER: "208.67.222.222",
|
||||
CONF_RESOLVER_IPV6: "2620:0:ccc::2",
|
||||
CONF_IPV4: True,
|
||||
CONF_IPV6: True,
|
||||
},
|
||||
options={
|
||||
CONF_RESOLVER: "208.67.222.222",
|
||||
CONF_RESOLVER_IPV6: "2620:0:ccc::2",
|
||||
},
|
||||
unique_id="home-assistant.io",
|
||||
).add_to_hass(hass)
|
||||
|
||||
|
@ -199,11 +211,13 @@ async def test_options_flow(hass: HomeAssistant) -> None:
|
|||
data={
|
||||
CONF_HOSTNAME: "home-assistant.io",
|
||||
CONF_NAME: "home-assistant.io",
|
||||
CONF_RESOLVER: "208.67.222.222",
|
||||
CONF_RESOLVER_IPV6: "2620:0:ccc::2",
|
||||
CONF_IPV4: True,
|
||||
CONF_IPV6: False,
|
||||
},
|
||||
options={
|
||||
CONF_RESOLVER: "208.67.222.222",
|
||||
CONF_RESOLVER_IPV6: "2620:0:ccc::2",
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
|
@ -267,6 +281,13 @@ async def test_options_error(hass: HomeAssistant, p_input: dict[str, str]) -> No
|
|||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.dnsip.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
||||
with patch(
|
||||
|
|
Loading…
Reference in New Issue