Fix Vizio host string for zeroconf discovery (#42738)

This commit is contained in:
Raman Gupta 2020-11-02 07:08:36 -05:00 committed by GitHub
parent a4947ed32d
commit 098dead16d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View file

@ -348,9 +348,11 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle zeroconf discovery."""
assert self.hass
discovery_info[
CONF_HOST
] = f"{discovery_info[CONF_HOST]}:{discovery_info[CONF_PORT]}"
# If host already has port, no need to add it again
if ":" not in discovery_info[CONF_HOST]:
discovery_info[
CONF_HOST
] = f"{discovery_info[CONF_HOST]}:{discovery_info[CONF_PORT]}"
# Set default name to discovered device name by stripping zeroconf service
# (`type`) from `name`

View file

@ -27,6 +27,7 @@ from homeassistant.const import (
CONF_HOST,
CONF_NAME,
CONF_PIN,
CONF_PORT,
)
from homeassistant.helpers.typing import HomeAssistantType
@ -777,6 +778,35 @@ async def test_zeroconf_flow_already_configured(
assert result["reason"] == "already_configured"
async def test_zeroconf_flow_with_port_in_host(
hass: HomeAssistantType,
vizio_connect: pytest.fixture,
vizio_bypass_setup: pytest.fixture,
vizio_guess_device_type: pytest.fixture,
) -> None:
"""Test entity is already configured during zeroconf setup when port is in host."""
entry = MockConfigEntry(
domain=DOMAIN,
data=MOCK_SPEAKER_CONFIG,
options={CONF_VOLUME_STEP: VOLUME_STEP},
unique_id=UNIQUE_ID,
)
entry.add_to_hass(hass)
# Try rediscovering same device, this time with port already in host
discovery_info = MOCK_ZEROCONF_SERVICE_INFO.copy()
discovery_info[
CONF_HOST
] = f"{discovery_info[CONF_HOST]}:{discovery_info[CONF_PORT]}"
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info
)
# Flow should abort because device is already setup
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
async def test_zeroconf_dupe_fail(
hass: HomeAssistantType,
vizio_connect: pytest.fixture,