mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
Add test
This commit is contained in:
@@ -17,9 +17,12 @@ from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
DEVICE_ID = "KNC1-W-00000214"
|
||||
FORMATTED_MAC = "aa:bb:cc:dd:ee:ff"
|
||||
|
||||
DHCP_DISCOVERY = DhcpServiceInfo(
|
||||
ip="1.1.1.1",
|
||||
hostname="KNC1-W-00000214",
|
||||
hostname=DEVICE_ID,
|
||||
macaddress="aabbccddeeff",
|
||||
)
|
||||
|
||||
@@ -168,6 +171,56 @@ async def test_dhcp_mac(
|
||||
assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "aa:bb:cc:dd:ee:ff")}
|
||||
|
||||
|
||||
async def test_dhcp_mac_multiple_entries(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test the DHCP discovery updates the mac on every matching device.
|
||||
|
||||
Two config entries each own a device sharing the discovered identifier. The
|
||||
migration to async_get_devices must update both devices; the deprecated
|
||||
async_get_device would only have resolved to a single one.
|
||||
"""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
second_config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Knocki 2",
|
||||
unique_id="test-id-2",
|
||||
data={CONF_TOKEN: "test-token"},
|
||||
)
|
||||
second_config_entry.add_to_hass(hass)
|
||||
|
||||
device_1 = device_registry.async_get_or_create(
|
||||
config_entry_id=mock_config_entry.entry_id,
|
||||
identifiers={(DOMAIN, DEVICE_ID)},
|
||||
)
|
||||
device_2 = device_registry.async_get_or_create(
|
||||
config_entry_id=second_config_entry.entry_id,
|
||||
identifiers={(DOMAIN, DEVICE_ID)},
|
||||
)
|
||||
assert device_1.id != device_2.id
|
||||
assert device_1.connections == set()
|
||||
assert device_2.connections == set()
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_DHCP}, data=DHCP_DISCOVERY
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
device_1 = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, DEVICE_ID), mock_config_entry.entry_id
|
||||
)
|
||||
device_2 = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, DEVICE_ID), second_config_entry.entry_id
|
||||
)
|
||||
assert device_1
|
||||
assert device_2
|
||||
assert device_1.connections == {(dr.CONNECTION_NETWORK_MAC, FORMATTED_MAC)}
|
||||
assert device_2.connections == {(dr.CONNECTION_NETWORK_MAC, FORMATTED_MAC)}
|
||||
|
||||
|
||||
async def test_dhcp_already_setup(
|
||||
hass: HomeAssistant,
|
||||
mock_knocki_client: AsyncMock,
|
||||
|
||||
Reference in New Issue
Block a user