Skip to content

Commit 160e4e4

Browse files
Block options flow for default hostname in dnsip (home-assistant#148221)
1 parent eb0f11a commit 160e4e4

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

homeassistant/components/dnsip/config_flow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ async def async_step_init(
172172
self, user_input: dict[str, Any] | None = None
173173
) -> ConfigFlowResult:
174174
"""Manage the options."""
175+
if self.config_entry.data[CONF_HOSTNAME] == DEFAULT_HOSTNAME:
176+
return self.async_abort(reason="no_options")
177+
175178
errors = {}
176179
if user_input is not None:
177180
resolver = user_input.get(CONF_RESOLVER, DEFAULT_RESOLVER)

homeassistant/components/dnsip/strings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
}
3131
},
3232
"abort": {
33-
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
33+
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
34+
"no_options": "The myip hostname requires the default resolvers and therefore cannot be configured."
3435
},
3536
"error": {
3637
"invalid_resolver": "Invalid IP address or port for resolver"

tests/components/dnsip/test_config_flow.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CONF_PORT_IPV6,
1717
CONF_RESOLVER,
1818
CONF_RESOLVER_IPV6,
19+
DEFAULT_HOSTNAME,
1920
DOMAIN,
2021
)
2122
from homeassistant.config_entries import ConfigEntryState
@@ -379,3 +380,36 @@ async def test_options_error(hass: HomeAssistant, p_input: dict[str, str]) -> No
379380
assert result2["errors"] == {"resolver": "invalid_resolver"}
380381
if p_input[CONF_IPV6]:
381382
assert result2["errors"] == {"resolver_ipv6": "invalid_resolver"}
383+
384+
385+
async def test_cannot_configure_options_for_myip(hass: HomeAssistant) -> None:
386+
"""Test options config flow aborts for default myip hostname."""
387+
entry = MockConfigEntry(
388+
domain=DOMAIN,
389+
unique_id="12345",
390+
data={
391+
CONF_HOSTNAME: DEFAULT_HOSTNAME,
392+
CONF_NAME: "myip",
393+
CONF_IPV4: True,
394+
CONF_IPV6: False,
395+
},
396+
options={
397+
CONF_RESOLVER: "208.67.222.222",
398+
CONF_RESOLVER_IPV6: "2620:119:53::5",
399+
CONF_PORT: 53,
400+
CONF_PORT_IPV6: 53,
401+
},
402+
)
403+
entry.add_to_hass(hass)
404+
405+
with patch(
406+
"homeassistant.components.dnsip.config_flow.aiodns.DNSResolver",
407+
return_value=RetrieveDNS(),
408+
):
409+
assert await hass.config_entries.async_setup(entry.entry_id)
410+
await hass.async_block_till_done()
411+
412+
result = await hass.config_entries.options.async_init(entry.entry_id)
413+
414+
assert result["type"] is FlowResultType.ABORT
415+
assert result["reason"] == "no_options"

0 commit comments

Comments
 (0)