Reolink replace automatic removal of devices by manual removal (#120981)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
starkillerOG 2024-07-02 13:31:23 +02:00 committed by GitHub
parent baf2ebf1f2
commit e322cada48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 70 additions and 48 deletions

View file

@ -36,6 +36,7 @@ from .conftest import (
)
from tests.common import MockConfigEntry, async_fire_time_changed
from tests.typing import WebSocketGenerator
pytestmark = pytest.mark.usefixtures("reolink_connect", "reolink_platforms")
@ -179,16 +180,27 @@ async def test_entry_reloading(
None,
[TEST_HOST_MODEL, TEST_CAM_MODEL],
),
(
"is_nvr",
False,
[TEST_HOST_MODEL, TEST_CAM_MODEL],
),
("channels", [], [TEST_HOST_MODEL]),
(
"camera_model",
Mock(return_value="RLC-567"),
[TEST_HOST_MODEL, "RLC-567"],
"camera_online",
Mock(return_value=False),
[TEST_HOST_MODEL],
),
(
"channel_for_uid",
Mock(return_value=-1),
[TEST_HOST_MODEL],
),
],
)
async def test_cleanup_disconnected_cams(
async def test_removing_disconnected_cams(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
config_entry: MockConfigEntry,
reolink_connect: MagicMock,
device_registry: dr.DeviceRegistry,
@ -197,8 +209,10 @@ async def test_cleanup_disconnected_cams(
value: Any,
expected_models: list[str],
) -> None:
"""Test device and entity registry are cleaned up when camera is disconnected from NVR."""
"""Test device and entity registry are cleaned up when camera is removed."""
reolink_connect.channels = [0]
assert await async_setup_component(hass, "config", {})
client = await hass_ws_client(hass)
# setup CH 0 and NVR switch entities/device
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
@ -215,6 +229,13 @@ async def test_cleanup_disconnected_cams(
setattr(reolink_connect, attr, value)
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
assert await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()
expected_success = TEST_CAM_MODEL not in expected_models
for device in device_entries:
if device.model == TEST_CAM_MODEL:
response = await client.remove_device(device.id, config_entry.entry_id)
assert response["success"] == expected_success
device_entries = dr.async_entries_for_config_entry(
device_registry, config_entry.entry_id