mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add shared DHCP discovery for Gree devices (#192097)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Config flow for Gree."""
|
||||
"""Config flow for Gree using shared user and DHCP discovery."""
|
||||
|
||||
from greeclimate.discovery import Discovery
|
||||
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Generated
+28
@@ -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*",
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user