|
5 | 5 | from __future__ import annotations
|
6 | 6 |
|
7 | 7 | import asyncio
|
8 |
| -from collections.abc import Callable |
9 | 8 | import logging
|
10 | 9 | from typing import Any
|
11 | 10 | from unittest.mock import AsyncMock, call, patch, sentinel
|
12 | 11 |
|
13 | 12 | import pytest
|
14 |
| -from zigpy.device import Device as ZigpyDevice |
15 | 13 | from zigpy.profiles import zha
|
16 | 14 | from zigpy.zcl.clusters import general, lighting
|
17 | 15 | import zigpy.zcl.foundation as zcl_f
|
18 | 16 | import zigpy.zdo.types as zdo_t
|
19 | 17 |
|
20 | 18 | from tests.common import (
|
| 19 | + SIG_EP_INPUT, |
| 20 | + SIG_EP_OUTPUT, |
| 21 | + SIG_EP_PROFILE, |
| 22 | + SIG_EP_TYPE, |
| 23 | + create_mock_zigpy_device, |
21 | 24 | get_entity,
|
22 | 25 | get_group_entity,
|
23 | 26 | group_entity_availability_test,
|
24 | 27 | join_zigpy_device,
|
25 | 28 | send_attributes_report,
|
26 | 29 | update_attribute_cache,
|
27 | 30 | )
|
28 |
| -from tests.conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE |
29 | 31 | from zha.application import Platform
|
30 | 32 | from zha.application.gateway import Gateway
|
31 | 33 | from zha.application.platforms import GroupEntity, PlatformEntity
|
|
90 | 92 |
|
91 | 93 | @pytest.fixture
|
92 | 94 | async def coordinator(
|
93 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
94 | 95 | zha_gateway: Gateway,
|
95 | 96 | ) -> Device:
|
96 | 97 | """Test zha light platform."""
|
97 | 98 |
|
98 |
| - zigpy_device = zigpy_device_mock( |
| 99 | + zigpy_device = create_mock_zigpy_device( |
| 100 | + zha_gateway, |
99 | 101 | {
|
100 | 102 | 1: {
|
101 | 103 | SIG_EP_INPUT: [general.Groups.cluster_id],
|
@@ -134,12 +136,12 @@ async def coordinator(
|
134 | 136 |
|
135 | 137 | @pytest.fixture
|
136 | 138 | async def device_light_1(
|
137 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
138 | 139 | zha_gateway: Gateway,
|
139 | 140 | ) -> Device:
|
140 | 141 | """Test zha light platform."""
|
141 | 142 |
|
142 |
| - zigpy_device = zigpy_device_mock( |
| 143 | + zigpy_device = create_mock_zigpy_device( |
| 144 | + zha_gateway, |
143 | 145 | {
|
144 | 146 | 1: {
|
145 | 147 | SIG_EP_INPUT: [
|
@@ -171,12 +173,12 @@ async def device_light_1(
|
171 | 173 |
|
172 | 174 | @pytest.fixture
|
173 | 175 | async def device_light_2(
|
174 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
175 | 176 | zha_gateway: Gateway,
|
176 | 177 | ) -> Device:
|
177 | 178 | """Test zha light platform."""
|
178 | 179 |
|
179 |
| - zigpy_device = zigpy_device_mock( |
| 180 | + zigpy_device = create_mock_zigpy_device( |
| 181 | + zha_gateway, |
180 | 182 | {
|
181 | 183 | 1: {
|
182 | 184 | SIG_EP_INPUT: [
|
@@ -207,12 +209,12 @@ async def device_light_2(
|
207 | 209 |
|
208 | 210 | @pytest.fixture
|
209 | 211 | async def device_light_3(
|
210 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
211 | 212 | zha_gateway: Gateway,
|
212 | 213 | ) -> Device:
|
213 | 214 | """Test zha light platform."""
|
214 | 215 |
|
215 |
| - zigpy_device = zigpy_device_mock( |
| 216 | + zigpy_device = create_mock_zigpy_device( |
| 217 | + zha_gateway, |
216 | 218 | {
|
217 | 219 | 1: {
|
218 | 220 | SIG_EP_INPUT: [
|
@@ -246,12 +248,12 @@ async def device_light_3(
|
246 | 248 |
|
247 | 249 | @pytest.fixture
|
248 | 250 | async def eWeLink_light(
|
249 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
250 | 251 | zha_gateway: Gateway,
|
251 | 252 | ):
|
252 | 253 | """Mock eWeLink light."""
|
253 | 254 |
|
254 |
| - zigpy_device = zigpy_device_mock( |
| 255 | + zigpy_device = create_mock_zigpy_device( |
| 256 | + zha_gateway, |
255 | 257 | {
|
256 | 258 | 1: {
|
257 | 259 | SIG_EP_INPUT: [
|
@@ -286,11 +288,10 @@ async def eWeLink_light(
|
286 | 288 |
|
287 | 289 | @pytest.mark.looptime
|
288 | 290 | async def test_light_refresh(
|
289 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
290 | 291 | zha_gateway: Gateway,
|
291 | 292 | ):
|
292 | 293 | """Test zha light platform refresh."""
|
293 |
| - zigpy_device = zigpy_device_mock(LIGHT_ON_OFF) |
| 294 | + zigpy_device = create_mock_zigpy_device(zha_gateway, LIGHT_ON_OFF) |
294 | 295 | on_off_cluster = zigpy_device.endpoints[1].on_off
|
295 | 296 | on_off_cluster.PLUGGED_ATTR_READS = {"on_off": 0}
|
296 | 297 | zha_device = await join_zigpy_device(zha_gateway, zigpy_device)
|
@@ -371,15 +372,14 @@ async def test_light_refresh(
|
371 | 372 | )
|
372 | 373 | @pytest.mark.looptime
|
373 | 374 | async def test_light(
|
374 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
375 | 375 | zha_gateway: Gateway,
|
376 | 376 | device: dict,
|
377 | 377 | reporting: tuple, # pylint: disable=unused-argument
|
378 | 378 | ) -> None:
|
379 | 379 | """Test zha light platform."""
|
380 | 380 |
|
381 | 381 | # create zigpy devices
|
382 |
| - zigpy_device = zigpy_device_mock(device) |
| 382 | + zigpy_device = create_mock_zigpy_device(zha_gateway, device) |
383 | 383 | cluster_color: lighting.Color = getattr(
|
384 | 384 | zigpy_device.endpoints[1], "light_color", None
|
385 | 385 | )
|
@@ -1075,15 +1075,14 @@ async def test_zha_group_light_entity(
|
1075 | 1075 | # TODO remove? No light will ever only support HS, we no longer support it
|
1076 | 1076 | async def test_light_initialization(
|
1077 | 1077 | zha_gateway: Gateway,
|
1078 |
| - zigpy_device_mock: Callable[..., ZigpyDevice], |
1079 | 1078 | plugged_attr_reads: dict[str, Any],
|
1080 | 1079 | config_override: dict[str, Any],
|
1081 | 1080 | expected_state: dict[str, Any], # pylint: disable=unused-argument
|
1082 | 1081 | ) -> None:
|
1083 | 1082 | """Test ZHA light initialization with cached attributes and color modes."""
|
1084 | 1083 |
|
1085 | 1084 | # create zigpy devices
|
1086 |
| - zigpy_device = zigpy_device_mock(LIGHT_COLOR) |
| 1085 | + zigpy_device = create_mock_zigpy_device(zha_gateway, LIGHT_COLOR) |
1087 | 1086 |
|
1088 | 1087 | # mock attribute reads
|
1089 | 1088 | zigpy_device.endpoints[1].light_color.PLUGGED_ATTR_READS = plugged_attr_reads
|
|
0 commit comments