mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 20:40:18 +00:00
Select correct Reolink device uid (#142864)
* Select correct device_uid * Fix styling * restructure * Add test * Update test_util.py * Add explanation string
This commit is contained in:
@@ -23,15 +23,21 @@ from homeassistant.components.number import (
|
||||
DOMAIN as NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.components.reolink.const import DOMAIN
|
||||
from homeassistant.components.reolink.util import get_device_uid_and_ch
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .conftest import TEST_NVR_NAME
|
||||
from .conftest import TEST_NVR_NAME, TEST_UID, TEST_UID_CAM
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
DEV_ID_NVR = f"{TEST_UID}_{TEST_UID_CAM}"
|
||||
DEV_ID_STANDALONE_CAM = f"{TEST_UID_CAM}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "expected"),
|
||||
@@ -123,3 +129,36 @@ async def test_try_function(
|
||||
assert err.value.translation_key == expected.translation_key
|
||||
|
||||
reolink_connect.set_volume.reset_mock(side_effect=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("identifiers"),
|
||||
[
|
||||
({(DOMAIN, DEV_ID_NVR), (DOMAIN, DEV_ID_STANDALONE_CAM)}),
|
||||
({(DOMAIN, DEV_ID_STANDALONE_CAM), (DOMAIN, DEV_ID_NVR)}),
|
||||
],
|
||||
)
|
||||
async def test_get_device_uid_and_ch(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_connect: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
identifiers: set[tuple[str, str]],
|
||||
) -> None:
|
||||
"""Test get_device_uid_and_ch with multiple identifiers."""
|
||||
reolink_connect.channels = [0]
|
||||
|
||||
dev_entry = device_registry.async_get_or_create(
|
||||
identifiers=identifiers,
|
||||
config_entry_id=config_entry.entry_id,
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
# setup CH 0 and host entities/device
|
||||
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = get_device_uid_and_ch(dev_entry, config_entry.runtime_data.host)
|
||||
# always get the uid and channel form the DEV_ID_NVR since is_nvr = True
|
||||
assert result == ([TEST_UID, TEST_UID_CAM], 0, False)
|
||||
|
||||
Reference in New Issue
Block a user