Skip to content

Commit 55847c0

Browse files
authored
Tests for 3 phase devices
1 parent 74277fc commit 55847c0

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

tests/test_tuya_energy_meter.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
@pytest.mark.parametrize(
18-
"model,manuf,channels,bidirectional",
18+
"model,manuf,channels,direction_attrs",
1919
[
2020
(
2121
"_TZE204_cjbofhxw",
@@ -26,14 +26,16 @@
2626
("_TZE204_ac0fhfiq", "TS0601", {1}, True),
2727
("_TZE200_rks0sgb7", "TS0601", {1, 2, 11}, True),
2828
("_TZE204_81yrt3lo", "TS0601", {1, 2, 11}, True),
29+
("_TZE200_nslr42tt", "TS0601", {1, 2, 3, 10}, True),
30+
("_TZE204_v9hkz2yn", "TS0601", {1}, True),
2931
],
3032
)
3133
async def test_tuya_energy_meter_quirk_energy_direction_align(
3234
zigpy_device_from_v2_quirk,
3335
model: str,
3436
manuf: str,
3537
channels,
36-
bidirectional: bool,
38+
direction_attrs: bool,
3739
):
3840
"""Test Tuya Energy Meter Quirk energy direction align in ElectricalMeasurement and Metering clusters."""
3941
quirked_device = zigpy_device_from_v2_quirk(model, manuf)
@@ -45,16 +47,22 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
4547

4648
CHANNEL_A = 1
4749
CHANNEL_B = 2
50+
CHANNEL_C = 3
51+
CHANNEL_TOTAL = 10
4852
CHANNEL_AB = 11
53+
CHANNEL_ABC = 12
4954

5055
UNSIGNED_ATTR_SUFFIX = "_attr_unsigned"
5156

5257
CURRENT = 5
5358
POWER = 100
5459
VOLTAGE = 230
5560
SUMM_RECEIVED = 15000
61+
5662
DIRECTION_A = REVERSE
5763
DIRECTION_B = FORWARD
64+
DIRECTION_C = FORWARD
65+
DIRECTION_TOTAL = FORWARD
5866

5967
ep = quirked_device.endpoints[1]
6068

@@ -80,7 +88,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
8088
),
8189
}
8290

83-
if bidirectional:
91+
if direction_attrs:
8492
# verify the direction attribute is present
8593
attr = getattr(ep.tuya_manufacturer.AttributeDefs, ENERGY_DIRECTION_ATTR, None)
8694
assert attr is not None
@@ -101,7 +109,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
101109
)
102110
assert attr is None
103111

104-
if bidirectional and CHANNEL_B in channels:
112+
if direction_attrs and CHANNEL_B in channels:
105113
# verify the direction B attribute is present
106114
attr = getattr(
107115
ep.tuya_manufacturer.AttributeDefs,
@@ -144,8 +152,12 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
144152
direction = DIRECTION_A
145153
elif channel == CHANNEL_B:
146154
direction = DIRECTION_B
147-
elif channel == CHANNEL_AB:
148-
# updates to channel AB will occur as a result of the device updates to channels A & B
155+
elif channel == CHANNEL_C:
156+
direction = DIRECTION_C
157+
elif channel == CHANNEL_TOTAL:
158+
direction = DIRECTION_TOTAL
159+
elif channel in (CHANNEL_AB, CHANNEL_ABC):
160+
# virtual channel updates occur as a result of updates to their source channels
149161
continue
150162
assert direction is not None
151163

@@ -190,7 +202,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
190202
assert (
191203
listeners[channel]["electrical_measurement"].attribute_updates[2][1]
192204
== POWER
193-
if not bidirectional or direction == FORWARD
205+
if not direction_attrs or direction == FORWARD
194206
else -POWER
195207
)
196208
assert (
@@ -222,7 +234,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
222234
)
223235
assert (
224236
listeners[channel]["metering"].attribute_updates[0][1] == POWER
225-
if not bidirectional or direction == FORWARD
237+
if not direction_attrs or direction == FORWARD
226238
else -POWER
227239
)
228240
assert (
@@ -275,9 +287,8 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
275287
@pytest.mark.parametrize(
276288
"model,manuf,mitigation_config,basic_cluster_match",
277289
[
278-
("_TZE204_cjbofhxw", "TS0601", 0, None), # Automatic
279-
("_TZE204_ac0fhfiq", "TS0601", 0, None), # Automatic
280-
("_TZE200_rks0sgb7", "TS0601", 1, None), # Disabled
290+
("_TZE204_81yrt3lo", "TS0601", 0, None), # Automatic
291+
("_TZE204_81yrt3lo", "TS0601", 1, None), # Disabled
281292
("_TZE204_81yrt3lo", "TS0601", 2, None), # Enabled
282293
(
283294
"_TZE204_81yrt3lo",
@@ -289,6 +300,26 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
289300
"stack_version": 0,
290301
},
291302
),
303+
(
304+
"_TZE204_81yrt3lo",
305+
"TS0601",
306+
1, # Disabled
307+
{
308+
"app_version": 74,
309+
"hw_version": 1,
310+
"stack_version": 0,
311+
},
312+
),
313+
(
314+
"_TZE204_81yrt3lo",
315+
"TS0601",
316+
2, # Enabled
317+
{
318+
"app_version": 74,
319+
"hw_version": 1,
320+
"stack_version": 0,
321+
},
322+
),
292323
],
293324
)
294325
async def test_tuya_energy_meter_quirk_energy_direction_delay_mitigation(

0 commit comments

Comments
 (0)