From 160e4e4d054a3266204a5ccb6fe0e77331d27a5f Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sat, 5 Jul 2025 21:36:15 +0200 Subject: [PATCH] Block options flow for default hostname in dnsip (#148221) --- homeassistant/components/dnsip/config_flow.py | 3 ++ homeassistant/components/dnsip/strings.json | 3 +- tests/components/dnsip/test_config_flow.py | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/dnsip/config_flow.py b/homeassistant/components/dnsip/config_flow.py index 6b86f1627bc..ab1ca42acd3 100644 --- a/homeassistant/components/dnsip/config_flow.py +++ b/homeassistant/components/dnsip/config_flow.py @@ -172,6 +172,9 @@ class DnsIPOptionsFlowHandler(OptionsFlow): self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Manage the options.""" + if self.config_entry.data[CONF_HOSTNAME] == DEFAULT_HOSTNAME: + return self.async_abort(reason="no_options") + errors = {} if user_input is not None: resolver = user_input.get(CONF_RESOLVER, DEFAULT_RESOLVER) diff --git a/homeassistant/components/dnsip/strings.json b/homeassistant/components/dnsip/strings.json index 39a0fbf7cd3..70472d37917 100644 --- a/homeassistant/components/dnsip/strings.json +++ b/homeassistant/components/dnsip/strings.json @@ -30,7 +30,8 @@ } }, "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": { "invalid_resolver": "Invalid IP address or port for resolver" diff --git a/tests/components/dnsip/test_config_flow.py b/tests/components/dnsip/test_config_flow.py index 1a565345275..d9420afaa8c 100644 --- a/tests/components/dnsip/test_config_flow.py +++ b/tests/components/dnsip/test_config_flow.py @@ -16,6 +16,7 @@ from homeassistant.components.dnsip.const import ( CONF_PORT_IPV6, CONF_RESOLVER, CONF_RESOLVER_IPV6, + DEFAULT_HOSTNAME, DOMAIN, ) 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"} if p_input[CONF_IPV6]: 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"