From 0379dee47e5a8a835a178101e493a12e2801161a Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Thu, 29 Apr 2021 17:11:22 +0200 Subject: [PATCH] Fix `host_valid()` logic in Vilfo config flow (#49862) --- homeassistant/components/vilfo/config_flow.py | 2 +- tests/components/vilfo/test_config_flow.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/vilfo/config_flow.py b/homeassistant/components/vilfo/config_flow.py index d5646c8caf3..569ce7992fa 100644 --- a/homeassistant/components/vilfo/config_flow.py +++ b/homeassistant/components/vilfo/config_flow.py @@ -32,7 +32,7 @@ RESULT_INVALID_AUTH = "invalid_auth" def host_valid(host): """Return True if hostname or IP address is valid.""" try: - if ipaddress.ip_address(host).version == (4 or 6): + if ipaddress.ip_address(host).version in [4, 6]: return True except ValueError: disallowed = re.compile(r"[^a-zA-Z\d\-]") diff --git a/tests/components/vilfo/test_config_flow.py b/tests/components/vilfo/test_config_flow.py index d828963ba39..d3face657de 100644 --- a/tests/components/vilfo/test_config_flow.py +++ b/tests/components/vilfo/test_config_flow.py @@ -155,6 +155,7 @@ async def test_validate_input_returns_data(hass): """Test we handle the MAC address being resolved or not.""" mock_data = {"host": "testadmin.vilfo.com", "access_token": "test-token"} mock_data_with_ip = {"host": "192.168.0.1", "access_token": "test-token"} + mock_data_with_ipv6 = {"host": "2001:db8::1428:57ab", "access_token": "test-token"} mock_mac = "FF-00-00-00-00-00" with patch("vilfo.Client.ping", return_value=None), patch( @@ -178,6 +179,9 @@ async def test_validate_input_returns_data(hass): result3 = await hass.components.vilfo.config_flow.validate_input( hass, data=mock_data_with_ip ) + result4 = await hass.components.vilfo.config_flow.validate_input( + hass, data=mock_data_with_ipv6 + ) assert result2["title"] == mock_data["host"] assert result2[CONF_HOST] == mock_data["host"] @@ -188,3 +192,8 @@ async def test_validate_input_returns_data(hass): assert result3[CONF_HOST] == mock_data_with_ip["host"] assert result3[CONF_MAC] == mock_mac assert result3[CONF_ID] == mock_mac + + assert result4["title"] == mock_data_with_ipv6["host"] + assert result4[CONF_HOST] == mock_data_with_ipv6["host"] + assert result4[CONF_MAC] == mock_mac + assert result4[CONF_ID] == mock_mac