mirror of
https://github.com/home-assistant/core.git
synced 2026-05-23 00:40:20 +01:00
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""Test Tuya initialization."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from syrupy.assertion import SnapshotAssertion
|
|
from tuya_sharing import CustomerDevice
|
|
|
|
from homeassistant.components.tuya import ManagerCompat
|
|
from homeassistant.components.tuya.const import DOMAIN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
|
|
|
from . import DEVICE_MOCKS, initialize_entry
|
|
|
|
from tests.common import MockConfigEntry, async_load_json_object_fixture
|
|
|
|
|
|
@pytest.mark.parametrize("mock_device_code", ["ydkt_jevroj5aguwdbs2e"])
|
|
async def test_unsupported_device(
|
|
hass: HomeAssistant,
|
|
mock_manager: ManagerCompat,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_device: CustomerDevice,
|
|
device_registry: dr.DeviceRegistry,
|
|
entity_registry: er.EntityRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test unsupported device."""
|
|
|
|
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
|
|
|
# Device is registered
|
|
assert (
|
|
dr.async_entries_for_config_entry(device_registry, mock_config_entry.entry_id)
|
|
== snapshot
|
|
)
|
|
# No entities registered
|
|
assert not er.async_entries_for_config_entry(
|
|
entity_registry, mock_config_entry.entry_id
|
|
)
|
|
|
|
|
|
async def test_fixtures_valid(hass: HomeAssistant) -> None:
|
|
"""Ensure Tuya fixture files are valid."""
|
|
# We want to ensure that the fixture files do not contain
|
|
# `home_assistant`, `id`, or `terminal_id` keys.
|
|
# These are provided by the Tuya diagnostics and should be removed
|
|
# from the fixture.
|
|
EXCLUDE_KEYS = ("home_assistant", "id", "terminal_id")
|
|
|
|
for device_code in DEVICE_MOCKS:
|
|
details = await async_load_json_object_fixture(
|
|
hass, f"{device_code}.json", DOMAIN
|
|
)
|
|
for key in EXCLUDE_KEYS:
|
|
assert key not in details, (
|
|
f"Please remove data[`'{key}']` from {device_code}.json"
|
|
)
|