Skip to content

Commit 1f90790

Browse files
committed
Migrate zigpy_device_mock -> create_mock_zigpy_device (test_light)
1 parent dfe26d4 commit 1f90790

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

tests/test_light.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@
55
from __future__ import annotations
66

77
import asyncio
8-
from collections.abc import Callable
98
import logging
109
from typing import Any
1110
from unittest.mock import AsyncMock, call, patch, sentinel
1211

1312
import pytest
14-
from zigpy.device import Device as ZigpyDevice
1513
from zigpy.profiles import zha
1614
from zigpy.zcl.clusters import general, lighting
1715
import zigpy.zcl.foundation as zcl_f
1816
import zigpy.zdo.types as zdo_t
1917

2018
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,
2124
get_entity,
2225
get_group_entity,
2326
group_entity_availability_test,
2427
join_zigpy_device,
2528
send_attributes_report,
2629
update_attribute_cache,
2730
)
28-
from tests.conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
2931
from zha.application import Platform
3032
from zha.application.gateway import Gateway
3133
from zha.application.platforms import GroupEntity, PlatformEntity
@@ -90,12 +92,12 @@
9092

9193
@pytest.fixture
9294
async def coordinator(
93-
zigpy_device_mock: Callable[..., ZigpyDevice],
9495
zha_gateway: Gateway,
9596
) -> Device:
9697
"""Test zha light platform."""
9798

98-
zigpy_device = zigpy_device_mock(
99+
zigpy_device = create_mock_zigpy_device(
100+
zha_gateway,
99101
{
100102
1: {
101103
SIG_EP_INPUT: [general.Groups.cluster_id],
@@ -134,12 +136,12 @@ async def coordinator(
134136

135137
@pytest.fixture
136138
async def device_light_1(
137-
zigpy_device_mock: Callable[..., ZigpyDevice],
138139
zha_gateway: Gateway,
139140
) -> Device:
140141
"""Test zha light platform."""
141142

142-
zigpy_device = zigpy_device_mock(
143+
zigpy_device = create_mock_zigpy_device(
144+
zha_gateway,
143145
{
144146
1: {
145147
SIG_EP_INPUT: [
@@ -171,12 +173,12 @@ async def device_light_1(
171173

172174
@pytest.fixture
173175
async def device_light_2(
174-
zigpy_device_mock: Callable[..., ZigpyDevice],
175176
zha_gateway: Gateway,
176177
) -> Device:
177178
"""Test zha light platform."""
178179

179-
zigpy_device = zigpy_device_mock(
180+
zigpy_device = create_mock_zigpy_device(
181+
zha_gateway,
180182
{
181183
1: {
182184
SIG_EP_INPUT: [
@@ -207,12 +209,12 @@ async def device_light_2(
207209

208210
@pytest.fixture
209211
async def device_light_3(
210-
zigpy_device_mock: Callable[..., ZigpyDevice],
211212
zha_gateway: Gateway,
212213
) -> Device:
213214
"""Test zha light platform."""
214215

215-
zigpy_device = zigpy_device_mock(
216+
zigpy_device = create_mock_zigpy_device(
217+
zha_gateway,
216218
{
217219
1: {
218220
SIG_EP_INPUT: [
@@ -246,12 +248,12 @@ async def device_light_3(
246248

247249
@pytest.fixture
248250
async def eWeLink_light(
249-
zigpy_device_mock: Callable[..., ZigpyDevice],
250251
zha_gateway: Gateway,
251252
):
252253
"""Mock eWeLink light."""
253254

254-
zigpy_device = zigpy_device_mock(
255+
zigpy_device = create_mock_zigpy_device(
256+
zha_gateway,
255257
{
256258
1: {
257259
SIG_EP_INPUT: [
@@ -286,11 +288,10 @@ async def eWeLink_light(
286288

287289
@pytest.mark.looptime
288290
async def test_light_refresh(
289-
zigpy_device_mock: Callable[..., ZigpyDevice],
290291
zha_gateway: Gateway,
291292
):
292293
"""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)
294295
on_off_cluster = zigpy_device.endpoints[1].on_off
295296
on_off_cluster.PLUGGED_ATTR_READS = {"on_off": 0}
296297
zha_device = await join_zigpy_device(zha_gateway, zigpy_device)
@@ -371,15 +372,14 @@ async def test_light_refresh(
371372
)
372373
@pytest.mark.looptime
373374
async def test_light(
374-
zigpy_device_mock: Callable[..., ZigpyDevice],
375375
zha_gateway: Gateway,
376376
device: dict,
377377
reporting: tuple, # pylint: disable=unused-argument
378378
) -> None:
379379
"""Test zha light platform."""
380380

381381
# create zigpy devices
382-
zigpy_device = zigpy_device_mock(device)
382+
zigpy_device = create_mock_zigpy_device(zha_gateway, device)
383383
cluster_color: lighting.Color = getattr(
384384
zigpy_device.endpoints[1], "light_color", None
385385
)
@@ -1075,15 +1075,14 @@ async def test_zha_group_light_entity(
10751075
# TODO remove? No light will ever only support HS, we no longer support it
10761076
async def test_light_initialization(
10771077
zha_gateway: Gateway,
1078-
zigpy_device_mock: Callable[..., ZigpyDevice],
10791078
plugged_attr_reads: dict[str, Any],
10801079
config_override: dict[str, Any],
10811080
expected_state: dict[str, Any], # pylint: disable=unused-argument
10821081
) -> None:
10831082
"""Test ZHA light initialization with cached attributes and color modes."""
10841083

10851084
# create zigpy devices
1086-
zigpy_device = zigpy_device_mock(LIGHT_COLOR)
1085+
zigpy_device = create_mock_zigpy_device(zha_gateway, LIGHT_COLOR)
10871086

10881087
# mock attribute reads
10891088
zigpy_device.endpoints[1].light_color.PLUGGED_ATTR_READS = plugged_attr_reads

0 commit comments

Comments
 (0)