mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Fix host_valid()
logic in DuneHD config flow (#49860)
This commit is contained in:
parent
3210c086ef
commit
61991572d7
@ -17,7 +17,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
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:
|
||||
if len(host) > 253:
|
||||
|
@ -64,6 +64,16 @@ async def test_user_invalid_host(hass):
|
||||
assert result["errors"] == {CONF_HOST: "invalid_host"}
|
||||
|
||||
|
||||
async def test_user_very_long_host(hass):
|
||||
"""Test that errors are shown when the host is longer than 253 chars."""
|
||||
long_host = "very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host_very_long_host"
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: long_host}
|
||||
)
|
||||
|
||||
assert result["errors"] == {CONF_HOST: "invalid_host"}
|
||||
|
||||
|
||||
async def test_user_cannot_connect(hass):
|
||||
"""Test that errors are shown when cannot connect to the host."""
|
||||
with patch("pdunehd.DuneHDPlayer.update_state", return_value={}):
|
||||
@ -101,3 +111,17 @@ async def test_create_entry(hass):
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "dunehd-host"
|
||||
assert result["data"] == {CONF_HOST: "dunehd-host"}
|
||||
|
||||
|
||||
async def test_create_entry_with_ipv6_address(hass):
|
||||
"""Test that the user step works with device IPv6 address.."""
|
||||
with patch("pdunehd.DuneHDPlayer.update_state", return_value=DUNEHD_STATE):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: "2001:db8::1428:57ab"},
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "2001:db8::1428:57ab"
|
||||
assert result["data"] == {CONF_HOST: "2001:db8::1428:57ab"}
|
||||
|
Loading…
Reference in New Issue
Block a user