From 52ca14de4826a3501a392f110e15ff48aecd5488 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Thu, 28 Mar 2024 14:57:18 +0100 Subject: [PATCH] Add matter zeroconf (#114385) * Add matter zeroconf * Clean up --- homeassistant/components/matter/manifest.json | 3 +- homeassistant/generated/zeroconf.py | 5 +++ tests/components/matter/test_config_flow.py | 44 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/matter/manifest.json b/homeassistant/components/matter/manifest.json index 716e296ec15..0e27eb36f85 100644 --- a/homeassistant/components/matter/manifest.json +++ b/homeassistant/components/matter/manifest.json @@ -6,5 +6,6 @@ "dependencies": ["websocket_api"], "documentation": "https://www.home-assistant.io/integrations/matter", "iot_class": "local_push", - "requirements": ["python-matter-server==5.7.0"] + "requirements": ["python-matter-server==5.7.0"], + "zeroconf": ["_matter._tcp.local."] } diff --git a/homeassistant/generated/zeroconf.py b/homeassistant/generated/zeroconf.py index baf922cdc99..060084209fd 100644 --- a/homeassistant/generated/zeroconf.py +++ b/homeassistant/generated/zeroconf.py @@ -573,6 +573,11 @@ ZEROCONF = { }, }, ], + "_matter._tcp.local.": [ + { + "domain": "matter", + }, + ], "_mediaremotetv._tcp.local.": [ { "domain": "apple_tv", diff --git a/tests/components/matter/test_config_flow.py b/tests/components/matter/test_config_flow.py index e690844c228..283642c8964 100644 --- a/tests/components/matter/test_config_flow.py +++ b/tests/components/matter/test_config_flow.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Generator +from ipaddress import ip_address from typing import Any from unittest.mock import DEFAULT, AsyncMock, MagicMock, call, patch @@ -12,6 +13,7 @@ import pytest from homeassistant import config_entries from homeassistant.components.hassio import HassioAPIError, HassioServiceInfo from homeassistant.components.matter.const import ADDON_SLUG, DOMAIN +from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -177,6 +179,48 @@ async def test_manual_already_configured( assert setup_entry.call_count == 1 +async def test_zeroconf_discovery( + hass: HomeAssistant, + client_connect: AsyncMock, + setup_entry: AsyncMock, +) -> None: + """Test flow started from Zeroconf discovery.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=ZeroconfServiceInfo( + ip_address=ip_address("fd11:be53:8d46:0:729e:5a4f:539d:1ee6"), + ip_addresses=[ip_address("fd11:be53:8d46:0:729e:5a4f:539d:1ee6")], + port=5540, + hostname="CDEFGHIJ12345678.local.", + type="_matter._tcp.local.", + name="ABCDEFGH123456789-0000000012345678._matter._tcp.local.", + properties={"SII": "3300", "SAI": "1100", "T": "0"}, + ), + ) + assert result["type"] == FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] is None + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + "url": "ws://localhost:5580/ws", + }, + ) + await hass.async_block_till_done() + + assert client_connect.call_count == 1 + assert result["type"] == FlowResultType.CREATE_ENTRY + assert result["title"] == "Matter" + assert result["data"] == { + "url": "ws://localhost:5580/ws", + "integration_created_addon": False, + "use_addon": False, + } + assert setup_entry.call_count == 1 + + @pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_supervisor_discovery( hass: HomeAssistant,