ZHA tests refactoring (#31682)
* Fixtures for restoring/joning a device. * binary_sensor.zha tests. * cover.zha platform tests. * device_tracker.zha platform tests. * fan.zha platform tests. * switch.zha platform tests. * Update light.zha platform tests. * Update sensor.zha platform tests. * ZHA api tests refactoring. * Update lock.zha platform tests. * Update ZHA gateway tests. * Update zha device action tests. * Update zha device trigger tests. * Cleanup.
This commit is contained in:
1 parent
118ba10442
commit
28eeed1db3
14 files changed
+648
-741
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""Test zha switch."""
|
||||
from unittest.mock import call, patch
|
||||
|
||||
import pytest
|
||||
import zigpy.zcl.clusters.general as general
|
||||
import zigpy.zcl.foundation as zcl_f
|
||||
|
||||
@@ -9,8 +10,6 @@ from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
|
||||
|
||||
from .common import (
|
||||
async_enable_traffic,
|
||||
async_init_zigpy_device,
|
||||
async_test_device_join,
|
||||
find_entity_id,
|
||||
make_attribute,
|
||||
make_zcl_header,
|
||||
@@ -22,24 +21,24 @@ ON = 1
|
||||
OFF = 0
|
||||
|
||||
|
||||
async def test_switch(hass, config_entry, zha_gateway):
|
||||
@pytest.fixture
|
||||
def zigpy_device(zigpy_device_mock):
|
||||
"""Device tracker zigpy device."""
|
||||
endpoints = {
|
||||
1: {
|
||||
"in_clusters": [general.Basic.cluster_id, general.OnOff.cluster_id],
|
||||
"out_clusters": [],
|
||||
"device_type": 0,
|
||||
}
|
||||
}
|
||||
return zigpy_device_mock(endpoints)
|
||||
|
||||
|
||||
async def test_switch(hass, zha_gateway, zha_device_joined_restored, zigpy_device):
|
||||
"""Test zha switch platform."""
|
||||
|
||||
# create zigpy device
|
||||
zigpy_device = await async_init_zigpy_device(
|
||||
hass,
|
||||
[general.OnOff.cluster_id, general.Basic.cluster_id],
|
||||
[],
|
||||
None,
|
||||
zha_gateway,
|
||||
)
|
||||
|
||||
# load up switch domain
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
zha_device = await zha_device_joined_restored(zigpy_device)
|
||||
cluster = zigpy_device.endpoints.get(1).on_off
|
||||
zha_device = zha_gateway.get_device(zigpy_device.ieee)
|
||||
entity_id = await find_entity_id(DOMAIN, zha_device, hass)
|
||||
assert entity_id is not None
|
||||
|
||||
@@ -94,4 +93,11 @@ async def test_switch(hass, config_entry, zha_gateway):
|
||||
)
|
||||
|
||||
# test joining a new switch to the network and HA
|
||||
await async_test_device_join(hass, zha_gateway, general.OnOff.cluster_id, entity_id)
|
||||
cluster.bind.reset_mock()
|
||||
cluster.configure_reporting.reset_mock()
|
||||
await zha_gateway.async_device_initialized(zigpy_device)
|
||||
await hass.async_block_till_done()
|
||||
assert cluster.bind.call_count == 1
|
||||
assert cluster.bind.await_count == 1
|
||||
assert cluster.configure_reporting.call_count == 1
|
||||
assert cluster.configure_reporting.await_count == 1
|
||||
Reference in new issue
Block a user