mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Block options flow for default hostname in dnsip (#148221)
This commit is contained in:
parent
eb0f11a859
commit
160e4e4d05
@ -172,6 +172,9 @@ class DnsIPOptionsFlowHandler(OptionsFlow):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Manage the options."""
|
"""Manage the options."""
|
||||||
|
if self.config_entry.data[CONF_HOSTNAME] == DEFAULT_HOSTNAME:
|
||||||
|
return self.async_abort(reason="no_options")
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
resolver = user_input.get(CONF_RESOLVER, DEFAULT_RESOLVER)
|
resolver = user_input.get(CONF_RESOLVER, DEFAULT_RESOLVER)
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||||
|
"no_options": "The myip hostname requires the default resolvers and therefore cannot be configured."
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"invalid_resolver": "Invalid IP address or port for resolver"
|
"invalid_resolver": "Invalid IP address or port for resolver"
|
||||||
|
@ -16,6 +16,7 @@ from homeassistant.components.dnsip.const import (
|
|||||||
CONF_PORT_IPV6,
|
CONF_PORT_IPV6,
|
||||||
CONF_RESOLVER,
|
CONF_RESOLVER,
|
||||||
CONF_RESOLVER_IPV6,
|
CONF_RESOLVER_IPV6,
|
||||||
|
DEFAULT_HOSTNAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
@ -379,3 +380,36 @@ async def test_options_error(hass: HomeAssistant, p_input: dict[str, str]) -> No
|
|||||||
assert result2["errors"] == {"resolver": "invalid_resolver"}
|
assert result2["errors"] == {"resolver": "invalid_resolver"}
|
||||||
if p_input[CONF_IPV6]:
|
if p_input[CONF_IPV6]:
|
||||||
assert result2["errors"] == {"resolver_ipv6": "invalid_resolver"}
|
assert result2["errors"] == {"resolver_ipv6": "invalid_resolver"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cannot_configure_options_for_myip(hass: HomeAssistant) -> None:
|
||||||
|
"""Test options config flow aborts for default myip hostname."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
unique_id="12345",
|
||||||
|
data={
|
||||||
|
CONF_HOSTNAME: DEFAULT_HOSTNAME,
|
||||||
|
CONF_NAME: "myip",
|
||||||
|
CONF_IPV4: True,
|
||||||
|
CONF_IPV6: False,
|
||||||
|
},
|
||||||
|
options={
|
||||||
|
CONF_RESOLVER: "208.67.222.222",
|
||||||
|
CONF_RESOLVER_IPV6: "2620:119:53::5",
|
||||||
|
CONF_PORT: 53,
|
||||||
|
CONF_PORT_IPV6: 53,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.dnsip.config_flow.aiodns.DNSResolver",
|
||||||
|
return_value=RetrieveDNS(),
|
||||||
|
):
|
||||||
|
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)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "no_options"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user