mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 05:20:17 +00:00
Reolink clean device registry mac (#144554)
This commit is contained in:
@@ -39,7 +39,7 @@ from homeassistant.helpers import (
|
||||
entity_registry as er,
|
||||
issue_registry as ir,
|
||||
)
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, format_mac
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .conftest import (
|
||||
@@ -51,6 +51,7 @@ from .conftest import (
|
||||
TEST_HOST,
|
||||
TEST_HOST_MODEL,
|
||||
TEST_MAC,
|
||||
TEST_MAC_CAM,
|
||||
TEST_NVR_NAME,
|
||||
TEST_PORT,
|
||||
TEST_PRIVACY,
|
||||
@@ -614,6 +615,55 @@ async def test_migrate_with_already_existing_entity(
|
||||
assert entity_registry.async_get_entity_id(domain, DOMAIN, new_id)
|
||||
|
||||
|
||||
async def test_cleanup_mac_connection(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_connect: MagicMock,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test cleanup of the MAC of a IPC which was set to the MAC of the host."""
|
||||
reolink_connect.channels = [0]
|
||||
reolink_connect.baichuan.mac_address.return_value = None
|
||||
entity_id = f"{TEST_UID}_{TEST_UID_CAM}_record_audio"
|
||||
dev_id = f"{TEST_UID}_{TEST_UID_CAM}"
|
||||
domain = Platform.SWITCH
|
||||
|
||||
dev_entry = device_registry.async_get_or_create(
|
||||
identifiers={(DOMAIN, dev_id)},
|
||||
connections={(CONNECTION_NETWORK_MAC, TEST_MAC)},
|
||||
config_entry_id=config_entry.entry_id,
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
entity_registry.async_get_or_create(
|
||||
domain=domain,
|
||||
platform=DOMAIN,
|
||||
unique_id=entity_id,
|
||||
config_entry=config_entry,
|
||||
suggested_object_id=entity_id,
|
||||
disabled_by=None,
|
||||
device_id=dev_entry.id,
|
||||
)
|
||||
|
||||
assert entity_registry.async_get_entity_id(domain, DOMAIN, entity_id)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, dev_id)})
|
||||
assert device
|
||||
assert device.connections == {(CONNECTION_NETWORK_MAC, TEST_MAC)}
|
||||
|
||||
# setup CH 0 and host entities/device
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [domain]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entity_registry.async_get_entity_id(domain, DOMAIN, entity_id)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, dev_id)})
|
||||
assert device
|
||||
assert device.connections == set()
|
||||
|
||||
reolink_connect.baichuan.mac_address.return_value = TEST_MAC_CAM
|
||||
|
||||
|
||||
async def test_no_repair_issue(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, issue_registry: ir.IssueRegistry
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user