Fix `host_valid()` logic in BraviaTV config flow (#49857)

pull/49862/head
Maciej Bieniek 2021-04-29 16:09:59 +02:00 committed by GitHub
parent 5b6d2edb48
commit 9588e0d35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -29,7 +29,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:
disallowed = re.compile(r"[^a-zA-Z\d\-]")

View File

@ -239,6 +239,39 @@ async def test_create_entry(hass):
}
async def test_create_entry_with_ipv6_address(hass):
"""Test that the user step works with device IPv6 address."""
with patch("bravia_tv.BraviaRC.connect", return_value=True), patch(
"bravia_tv.BraviaRC.is_connected", return_value=True
), patch(
"bravia_tv.BraviaRC.get_system_info", return_value=BRAVIA_SYSTEM_INFO
), patch(
"homeassistant.components.braviatv.async_setup_entry", return_value=True
):
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_FORM
assert result["step_id"] == "authorize"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_PIN: "1234"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["result"].unique_id == "very_unique_string"
assert result["title"] == "TV-Model"
assert result["data"] == {
CONF_HOST: "2001:db8::1428:57ab",
CONF_PIN: "1234",
CONF_MAC: "AA:BB:CC:DD:EE:FF",
}
async def test_options_flow(hass):
"""Test config flow options."""
config_entry = MockConfigEntry(