Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion homeassistant/components/devolo_home_network/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle zeroconf discovery."""
if (
"MT" not in discovery_info.properties
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
or "SN" not in discovery_info.properties
):
return self.async_abort(reason="incomplete_query")

if discovery_info.properties["MT"] in ["2600", "2601"]:
return self.async_abort(reason="home_control")

Expand All @@ -86,7 +92,7 @@ async def async_step_zeroconf(

self.context[CONF_HOST] = discovery_info.host
self.context["title_placeholders"] = {
PRODUCT: discovery_info.properties["Product"],
PRODUCT: discovery_info.properties.get("Product", ""),
CONF_NAME: discovery_info.hostname.split(".")[0],
}

Expand Down
13 changes: 12 additions & 1 deletion tests/components/devolo_home_network/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@
hostname="mock_hostname",
name="mock_name",
port=None,
properties={"MT": "2600"},
properties={"MT": "2600", "SN": "1234567890"},
type="mock_type",
)

DISCOVERY_INFO_INCOMPLETE_QUERY = zeroconf.ZeroconfServiceInfo(
host="mock_host",
addresses=["mock_host"],
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
)


NEIGHBOR_ACCESS_POINTS = {
"neighbor_aps": [
{
Expand Down
18 changes: 17 additions & 1 deletion tests/components/devolo_home_network/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
RESULT_TYPE_FORM,
)

from .const import DISCOVERY_INFO, DISCOVERY_INFO_WRONG_DEVICE, IP
from .const import (
DISCOVERY_INFO,
DISCOVERY_INFO_INCOMPLETE_QUERY,
DISCOVERY_INFO_WRONG_DEVICE,
IP,
)


async def test_form(hass: HomeAssistant, info: dict[str, Any]):
Expand Down Expand Up @@ -118,6 +123,17 @@ async def test_zeroconf(hass: HomeAssistant):
}


async def test_abort_zeroconf_incomplete_query(hass: HomeAssistant):
"""Test we abort zeroconf on incomplete queries."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=DISCOVERY_INFO_INCOMPLETE_QUERY,
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "incomplete_query"


async def test_abort_zeroconf_wrong_device(hass: HomeAssistant):
"""Test we abort zeroconf for wrong devices."""
result = await hass.config_entries.flow.async_init(
Expand Down