mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 18:08:37 -04:00
UnifiProtect: Create NVR device before loading platforms to fix via_device references (#158191)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# serializer version: 1
|
||||
# name: test_setup_creates_nvr_device
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'config_entries_subentries': <ANY>,
|
||||
'configuration_url': 'https://127.0.0.1',
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'a1:e0:0c:82:69:24',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'unifiprotect',
|
||||
'A1E00C826924',
|
||||
),
|
||||
}),
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Ubiquiti',
|
||||
'model': 'UNVR-PRO',
|
||||
'model_id': None,
|
||||
'name': 'UnifiProtect',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'sw_version': '6.0.0',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from uiprotect import NvrError, ProtectApiClient
|
||||
from uiprotect.api import DEVICE_UPDATE_INTERVAL
|
||||
from uiprotect.data import NVR, Bootstrap, CloudAccount, Light
|
||||
@@ -44,6 +45,30 @@ def mock_user_can_write_nvr(request: pytest.FixtureRequest, ufp: MockUFPFixture)
|
||||
object.__setattr__(ufp.api.bootstrap.nvr, "can_write", original_can_write)
|
||||
|
||||
|
||||
async def test_setup_creates_nvr_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
ufp: MockUFPFixture,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test that setup creates the NVR device before loading platforms.
|
||||
|
||||
This ensures that via_device references from camera/sensor entities
|
||||
to the NVR device work correctly.
|
||||
"""
|
||||
await hass.config_entries.async_setup(ufp.entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert ufp.entry.state is ConfigEntryState.LOADED
|
||||
|
||||
# Verify NVR device was created
|
||||
nvr = ufp.api.bootstrap.nvr
|
||||
nvr_device = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, nvr.mac)},
|
||||
)
|
||||
assert nvr_device == snapshot
|
||||
|
||||
|
||||
async def test_setup(hass: HomeAssistant, ufp: MockUFPFixture) -> None:
|
||||
"""Test working setup of unifiprotect entry."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user