ZHA: Successful pairing feedback (#32456)

This commit is contained in:
Alexei Chetroi authored and GitHub committed 2020-03-04 19:27:37 -05:00
1 parent 76fec90fec
commit e416f17e4d
6 files changed
+56 -3

No files matched your search

+1
View File
@@ -29,6 +29,7 @@ class FakeEndpoint:
self.model = model
self.profile_id = zigpy.profiles.zha.PROFILE_ID
self.device_type = None
self.request = CoroutineMock()
def add_input_cluster(self, cluster_id):
"""Add an input cluster."""
+3 -1
View File
@@ -166,7 +166,9 @@ def zha_device_restored(hass, zigpy_app_controller, setup_zha):
@pytest.fixture(params=["zha_device_joined", "zha_device_restored"])
def zha_device_joined_restored(request):
"""Join or restore ZHA device."""
return request.getfixturevalue(request.param)
named_method = request.getfixturevalue(request.param)
named_method.name = request.param
return named_method
@pytest.fixture
+34
View File
@@ -3,11 +3,14 @@
import re
from unittest import mock
import asynctest
import pytest
import zigpy.quirks
import zigpy.types
import zigpy.zcl.clusters.closures
import zigpy.zcl.clusters.general
import zigpy.zcl.clusters.security
import zigpy.zcl.foundation as zcl_f
import homeassistant.components.zha.binary_sensor
import homeassistant.components.zha.core.channels as zha_channels
@@ -48,6 +51,12 @@ def channels_mock(zha_device_mock):
return _mock
@asynctest.patch(
"zigpy.zcl.clusters.general.Identify.request",
new=asynctest.CoroutineMock(
return_value=[mock.sentinel.data, zcl_f.Status.SUCCESS]
),
)
@pytest.mark.parametrize("device", DEVICES)
async def test_devices(
device, hass, zigpy_device_mock, monkeypatch, zha_device_joined_restored
@@ -66,6 +75,10 @@ async def test_devices(
node_descriptor=device["node_descriptor"],
)
cluster_identify = _get_first_identify_cluster(zigpy_device)
if cluster_identify:
cluster_identify.request.reset_mock()
orig_new_entity = zha_channels.ChannelPool.async_new_entity
_dispatch = mock.MagicMock(wraps=orig_new_entity)
try:
@@ -81,6 +94,21 @@ async def test_devices(
ent for ent in entity_ids if ent.split(".")[0] in zha_const.COMPONENTS
}
if cluster_identify:
called = int(zha_device_joined_restored.name == "zha_device_joined")
assert cluster_identify.request.call_count == called
assert cluster_identify.request.await_count == called
if called:
assert cluster_identify.request.call_args == mock.call(
False,
64,
(zigpy.types.uint8_t, zigpy.types.uint8_t),
2,
0,
expect_reply=True,
manufacturer=None,
)
event_channels = {
ch.id for pool in zha_dev.channels.pools for ch in pool.relay_channels.values()
}
@@ -108,6 +136,12 @@ async def test_devices(
assert entity_cls.__name__ == entity_map[key]["entity_class"]
def _get_first_identify_cluster(zigpy_device):
for endpoint in list(zigpy_device.endpoints.values())[1:]:
if hasattr(endpoint, "identify"):
return endpoint.identify
@mock.patch(
"homeassistant.components.zha.core.discovery.ProbeEndpoint.discover_by_device_type"
)