mirror of
https://github.com/home-assistant/core.git
synced 2026-02-14 23:28:42 +00:00
Add DHCP Discovery to vesync (#162259)
Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
"@sapuseven"
|
||||
],
|
||||
"config_flow": true,
|
||||
"dhcp": [{ "hostname": "levoit-*" }],
|
||||
"documentation": "https://www.home-assistant.io/integrations/vesync",
|
||||
"integration_type": "hub",
|
||||
"iot_class": "cloud_polling",
|
||||
|
||||
@@ -42,8 +42,10 @@ rules:
|
||||
diagnostics:
|
||||
status: todo
|
||||
comment: room to remove content such as entities.
|
||||
discovery-update-info: todo
|
||||
discovery: todo
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: Devices aren't connected locally, nothing to update
|
||||
discovery: done
|
||||
docs-data-update: todo
|
||||
docs-examples: todo
|
||||
docs-known-limitations: todo
|
||||
|
||||
4
homeassistant/generated/dhcp.py
generated
4
homeassistant/generated/dhcp.py
generated
@@ -1342,6 +1342,10 @@ DHCP: Final[list[dict[str, str | bool]]] = [
|
||||
"domain": "verisure",
|
||||
"macaddress": "0023C1*",
|
||||
},
|
||||
{
|
||||
"domain": "vesync",
|
||||
"hostname": "levoit-*",
|
||||
},
|
||||
{
|
||||
"domain": "vicare",
|
||||
"macaddress": "B87424*",
|
||||
|
||||
@@ -5,10 +5,12 @@ from unittest.mock import PropertyMock, patch
|
||||
from pyvesync.utils.errors import VeSyncLoginError
|
||||
|
||||
from homeassistant.components.vesync import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -150,3 +152,52 @@ async def test_reauth_flow_invalid_auth(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
|
||||
async def test_dhcp_discovery(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
"""Test DHCP discovery flow."""
|
||||
|
||||
service_info = DhcpServiceInfo(
|
||||
hostname="Levoit-Purifier",
|
||||
ip="1.2.3.4",
|
||||
macaddress="aabbccddeeff",
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=service_info,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
# Configure the flow to create the config entry
|
||||
with patch("pyvesync.vesync.VeSync.login"):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_USERNAME: "user", CONF_PASSWORD: "pass"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].unique_id == "TESTACCOUNTID"
|
||||
|
||||
|
||||
async def test_dhcp_discovery_duplicate(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test DHCP discovery flow with already setup integration."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=DhcpServiceInfo(
|
||||
hostname="Levoit-Purifier",
|
||||
ip="1.2.3.4",
|
||||
macaddress="aabbccddeeff",
|
||||
),
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
Reference in New Issue
Block a user