Ignore Shelly IPv6 address in zeroconf (#123081)

This commit is contained in:
Shay Levy 2024-08-02 21:56:49 +03:00 committed by Franck Nijhof
parent fa241dcd04
commit 7623ee49e4
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
3 changed files with 23 additions and 1 deletions

View file

@ -279,6 +279,8 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""
if discovery_info.ip_address.version == 6:
return self.async_abort(reason="ipv6_not_supported")
host = discovery_info.host
# First try to get the mac address from the name
# so we can avoid making another connection to the

View file

@ -52,7 +52,8 @@
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
"reauth_unsuccessful": "Re-authentication was unsuccessful, please remove the integration and set it up again.",
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]",
"another_device": "Re-configuration was unsuccessful, the IP address/hostname of another Shelly device was used."
"another_device": "Re-configuration was unsuccessful, the IP address/hostname of another Shelly device was used.",
"ipv6_not_supported": "IPv6 is not supported."
}
},
"device_automation": {

View file

@ -1305,3 +1305,22 @@ async def test_reconfigure_with_exception(
)
assert result["errors"] == {"base": base_error}
async def test_zeroconf_rejects_ipv6(hass: HomeAssistant) -> None:
"""Test zeroconf discovery rejects ipv6."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo(
ip_address=ip_address("fd00::b27c:63bb:cc85:4ea0"),
ip_addresses=[ip_address("fd00::b27c:63bb:cc85:4ea0")],
hostname="mock_hostname",
name="shelly1pm-12345",
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "shelly1pm-12345"},
type="mock_type",
),
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "ipv6_not_supported"