Update ZHA entity discovery tests (#31191)

* ZHA registry test fixtures refactoring.

* Update ZHA test devices list.

* Use channel.id for event relay channels test.

* Add zigpy_device factory fixture.

* Add node descriptor to mock zigpy devices.

* Use node descriptor for ZHA device tests.

* Update ZHA discovery test.

check for unique_id and channels passed into each entity.

* Address comments.
This commit is contained in:
Alexei Chetroi authored and David F. Mulcahey committed 2020-01-27 19:43:26 -05:00
1 parent 6daec557b4
commit 9d8b4de09c
6 files changed
+2012 -259

No files matched your search

+51 -1
View File
@@ -2,6 +2,7 @@
from unittest import mock
from unittest.mock import patch
import asynctest
import pytest
import zigpy
from zigpy.application import ControllerApplication
@@ -12,7 +13,7 @@ from homeassistant.components.zha.core.gateway import ZHAGateway
from homeassistant.components.zha.core.store import async_get_registry
from homeassistant.helpers.device_registry import async_get_registry as get_dev_reg
from .common import async_setup_entry
from .common import FakeDevice, FakeEndpoint, async_setup_entry
FIXTURE_GRP_ID = 0x1001
FIXTURE_GRP_NAME = "fixture group"
@@ -70,3 +71,52 @@ async def setup_zha(hass, config_entry):
# init ZHA
await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
await hass.async_block_till_done()
@pytest.fixture
def channel():
"""Channel mock factory fixture."""
def channel(name: str, cluster_id: int, endpoint_id: int = 1):
ch = mock.MagicMock()
ch.name = name
ch.generic_id = f"channel_0x{cluster_id:04x}"
ch.id = f"{endpoint_id}:0x{cluster_id:04x}"
ch.async_configure = asynctest.CoroutineMock()
ch.async_initialize = asynctest.CoroutineMock()
return ch
return channel
@pytest.fixture
def zigpy_device_mock():
"""Make a fake device using the specified cluster classes."""
def _mock_dev(
endpoints,
ieee="00:0d:6f:00:0a:90:69:e7",
manufacturer="FakeManufacturer",
model="FakeModel",
node_desc=b"\x02@\x807\x10\x7fd\x00\x00*d\x00\x00",
):
"""Make a fake device using the specified cluster classes."""
device = FakeDevice(ieee, manufacturer, model, node_desc)
for epid, ep in endpoints.items():
endpoint = FakeEndpoint(manufacturer, model, epid)
endpoint.device = device
device.endpoints[epid] = endpoint
endpoint.device_type = ep["device_type"]
profile_id = ep.get("profile_id")
if profile_id:
endpoint.profile_id = profile_id
for cluster_id in ep.get("in_clusters", []):
endpoint.add_input_cluster(cluster_id)
for cluster_id in ep.get("out_clusters", []):
endpoint.add_output_cluster(cluster_id)
return device
return _mock_dev