From 0c98254cf80f9f979d415f7f3ca98bcff3faedec Mon Sep 17 00:00:00 2001 From: Clifford Roche <1007595+cmroche@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:32:32 -0500 Subject: [PATCH] Add shared DHCP discovery for Gree devices (#192097) --- homeassistant/components/gree/config_flow.py | 2 +- homeassistant/components/gree/manifest.json | 23 ++++++++++ homeassistant/generated/dhcp.py | 28 +++++++++++++ tests/components/gree/test_config_flow.py | 44 +++++++++++++++++++- 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/gree/config_flow.py b/homeassistant/components/gree/config_flow.py index 5e1180889161..9ecd73128952 100644 --- a/homeassistant/components/gree/config_flow.py +++ b/homeassistant/components/gree/config_flow.py @@ -1,4 +1,4 @@ -"""Config flow for Gree.""" +"""Config flow for Gree using shared user and DHCP discovery.""" from greeclimate.discovery import Discovery diff --git a/homeassistant/components/gree/manifest.json b/homeassistant/components/gree/manifest.json index b8fa8de9a6f3..7a603df13b31 100644 --- a/homeassistant/components/gree/manifest.json +++ b/homeassistant/components/gree/manifest.json @@ -6,6 +6,29 @@ "config_flow": true, "connectivity": ["network"], "dependencies": ["network"], + "dhcp": [ + { + "macaddress": "0447CA*" + }, + { + "macaddress": "502CC6*" + }, + { + "macaddress": "580D0D*" + }, + { + "macaddress": "7CB8E6*" + }, + { + "macaddress": "9424B8*" + }, + { + "macaddress": "C03937*" + }, + { + "macaddress": "F4911E*" + } + ], "documentation": "https://www.home-assistant.io/integrations/gree", "iot_class": "local_polling", "loggers": ["greeclimate"], diff --git a/homeassistant/generated/dhcp.py b/homeassistant/generated/dhcp.py index e91648e1c8c2..b607382f5d3d 100644 --- a/homeassistant/generated/dhcp.py +++ b/homeassistant/generated/dhcp.py @@ -456,6 +456,34 @@ DHCP: Final[list[dict[str, str | bool]]] = [ "domain": "gogogate2", "hostname": "ismartgate*", }, + { + "domain": "gree", + "macaddress": "0447CA*", + }, + { + "domain": "gree", + "macaddress": "502CC6*", + }, + { + "domain": "gree", + "macaddress": "580D0D*", + }, + { + "domain": "gree", + "macaddress": "7CB8E6*", + }, + { + "domain": "gree", + "macaddress": "9424B8*", + }, + { + "domain": "gree", + "macaddress": "C03937*", + }, + { + "domain": "gree", + "macaddress": "F4911E*", + }, { "domain": "guardian", "hostname": "gvc*", diff --git a/tests/components/gree/test_config_flow.py b/tests/components/gree/test_config_flow.py index 9871d2534538..03a2004693b8 100644 --- a/tests/components/gree/test_config_flow.py +++ b/tests/components/gree/test_config_flow.py @@ -1,13 +1,15 @@ -"""Tests for the Gree Integration.""" +"""Tests for Gree setup and shared DHCP discovery.""" from unittest.mock import AsyncMock, patch import pytest +from pytest_homeassistant.common import MockConfigEntry from homeassistant import config_entries from homeassistant.components.gree.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from .common import FakeDiscovery @@ -87,3 +89,43 @@ async def test_creating_entry_has_no_devices( await hass.async_block_till_done() mock_setup_entry.assert_called_once() + + +async def test_dhcp_discovery(hass: HomeAssistant) -> None: + """Test DHCP discovery requires confirmation and creates one shared entry.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DHCP}, + data=DhcpServiceInfo(ip="192.168.1.10", hostname="", macaddress="f4911e7aca59"), + ) + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "confirm" + assert not hass.config_entries.async_entries(DOMAIN) + + duplicate = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DHCP}, + data=DhcpServiceInfo(ip="192.168.1.11", hostname="", macaddress="502cc6123456"), + ) + assert duplicate["type"] is FlowResultType.ABORT + assert duplicate["reason"] == "single_instance_allowed" + + result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == "Gree Climate" + assert result["data"] == {} + assert result["result"].unique_id == DOMAIN + + +async def test_dhcp_already_configured(hass: HomeAssistant) -> None: + """Test DHCP discovery does not duplicate an existing shared entry.""" + entry = MockConfigEntry(domain=DOMAIN, data={}) + entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DHCP}, + data=DhcpServiceInfo(ip="192.168.1.10", hostname="", macaddress="f4911e7aca59"), + ) + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "single_instance_allowed"