Add device registry snapshots to Tuya (#150482)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
epenet
2025-08-12 14:04:36 +02:00
committed by GitHub
parent 2612dbeb9b
commit 2b70639b11
2 changed files with 5756 additions and 45 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from tuya_sharing import CustomerDevice from tuya_sharing import CustomerDevice
@@ -16,28 +15,38 @@ from . import DEVICE_MOCKS, initialize_entry
from tests.common import MockConfigEntry, async_load_json_object_fixture from tests.common import MockConfigEntry, async_load_json_object_fixture
@pytest.mark.parametrize("mock_device_code", ["ydkt_jevroj5aguwdbs2e"]) async def test_device_registry(
async def test_unsupported_device(
hass: HomeAssistant, hass: HomeAssistant,
mock_manager: ManagerCompat, mock_manager: ManagerCompat,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
mock_device: CustomerDevice, mock_devices: CustomerDevice,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test unsupported device.""" """Validate device registry snapshots for all devices, including unsupported ones."""
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) await initialize_entry(hass, mock_manager, mock_config_entry, mock_devices)
# Device is registered device_registry_entries = dr.async_entries_for_config_entry(
assert ( device_registry, mock_config_entry.entry_id
dr.async_entries_for_config_entry(device_registry, mock_config_entry.entry_id) )
== snapshot
# Ensure the device registry contains same amount as DEVICE_MOCKS
assert len(device_registry_entries) == len(DEVICE_MOCKS)
for device_registry_entry in device_registry_entries:
assert device_registry_entry == snapshot(
name=list(device_registry_entry.identifiers)[0][1]
)
# Ensure model is suffixed with "(unsupported)" when no entities are generated
assert (" (unsupported)" in device_registry_entry.model) == (
not er.async_entries_for_device(
entity_registry,
device_registry_entry.id,
include_disabled_entities=True,
) )
# No entities registered
assert not er.async_entries_for_config_entry(
entity_registry, mock_config_entry.entry_id
) )