mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 22:18:40 +00:00
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,7 +1,7 @@
|
||||
"""Test zha fan."""
|
||||
from unittest.mock import call, patch
|
||||
|
||||
import zigpy.zcl.clusters.general as general
|
||||
import pytest
|
||||
import zigpy.zcl.clusters.hvac as hvac
|
||||
import zigpy.zcl.foundation as zcl_f
|
||||
|
||||
@@ -18,8 +18,6 @@ from homeassistant.const import (
|
||||
|
||||
from .common import (
|
||||
async_enable_traffic,
|
||||
async_init_zigpy_device,
|
||||
async_test_device_join,
|
||||
find_entity_id,
|
||||
make_attribute,
|
||||
make_zcl_header,
|
||||
@@ -28,20 +26,20 @@ from .common import (
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
async def test_fan(hass, config_entry, zha_gateway):
|
||||
@pytest.fixture
|
||||
def zigpy_device(zigpy_device_mock):
|
||||
"""Device tracker zigpy device."""
|
||||
endpoints = {
|
||||
1: {"in_clusters": [hvac.Fan.cluster_id], "out_clusters": [], "device_type": 0}
|
||||
}
|
||||
return zigpy_device_mock(endpoints)
|
||||
|
||||
|
||||
async def test_fan(hass, zha_gateway, zha_device_joined_restored, zigpy_device):
|
||||
"""Test zha fan platform."""
|
||||
|
||||
# create zigpy device
|
||||
zigpy_device = await async_init_zigpy_device(
|
||||
hass, [hvac.Fan.cluster_id, general.Basic.cluster_id], [], None, zha_gateway
|
||||
)
|
||||
|
||||
# load up fan 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).fan
|
||||
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
|
||||
|
||||
@@ -98,7 +96,14 @@ async def test_fan(hass, config_entry, zha_gateway):
|
||||
assert cluster.write_attributes.call_args == call({"fan_mode": 3})
|
||||
|
||||
# test adding new fan to the network and HA
|
||||
await async_test_device_join(hass, zha_gateway, hvac.Fan.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
|
||||
|
||||
|
||||
async def async_turn_on(hass, entity_id, speed=None):
|
||||
|
||||
Reference in New Issue
Block a user