15
15
16
16
17
17
@pytest .mark .parametrize (
18
- "model,manuf,channels,bidirectional " ,
18
+ "model,manuf,channels,direction_attrs " ,
19
19
[
20
20
(
21
21
"_TZE204_cjbofhxw" ,
26
26
("_TZE204_ac0fhfiq" , "TS0601" , {1 }, True ),
27
27
("_TZE200_rks0sgb7" , "TS0601" , {1 , 2 , 11 }, True ),
28
28
("_TZE204_81yrt3lo" , "TS0601" , {1 , 2 , 11 }, True ),
29
+ ("_TZE200_nslr42tt" , "TS0601" , {1 , 2 , 3 , 10 }, True ),
30
+ ("_TZE204_v9hkz2yn" , "TS0601" , {1 }, True ),
29
31
],
30
32
)
31
33
async def test_tuya_energy_meter_quirk_energy_direction_align (
32
34
zigpy_device_from_v2_quirk ,
33
35
model : str ,
34
36
manuf : str ,
35
37
channels ,
36
- bidirectional : bool ,
38
+ direction_attrs : bool ,
37
39
):
38
40
"""Test Tuya Energy Meter Quirk energy direction align in ElectricalMeasurement and Metering clusters."""
39
41
quirked_device = zigpy_device_from_v2_quirk (model , manuf )
@@ -45,16 +47,22 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
45
47
46
48
CHANNEL_A = 1
47
49
CHANNEL_B = 2
50
+ CHANNEL_C = 3
51
+ CHANNEL_TOTAL = 10
48
52
CHANNEL_AB = 11
53
+ CHANNEL_ABC = 12
49
54
50
55
UNSIGNED_ATTR_SUFFIX = "_attr_unsigned"
51
56
52
57
CURRENT = 5
53
58
POWER = 100
54
59
VOLTAGE = 230
55
60
SUMM_RECEIVED = 15000
61
+
56
62
DIRECTION_A = REVERSE
57
63
DIRECTION_B = FORWARD
64
+ DIRECTION_C = FORWARD
65
+ DIRECTION_TOTAL = FORWARD
58
66
59
67
ep = quirked_device .endpoints [1 ]
60
68
@@ -80,7 +88,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
80
88
),
81
89
}
82
90
83
- if bidirectional :
91
+ if direction_attrs :
84
92
# verify the direction attribute is present
85
93
attr = getattr (ep .tuya_manufacturer .AttributeDefs , ENERGY_DIRECTION_ATTR , None )
86
94
assert attr is not None
@@ -101,7 +109,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
101
109
)
102
110
assert attr is None
103
111
104
- if bidirectional and CHANNEL_B in channels :
112
+ if direction_attrs and CHANNEL_B in channels :
105
113
# verify the direction B attribute is present
106
114
attr = getattr (
107
115
ep .tuya_manufacturer .AttributeDefs ,
@@ -144,8 +152,12 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
144
152
direction = DIRECTION_A
145
153
elif channel == CHANNEL_B :
146
154
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
149
161
continue
150
162
assert direction is not None
151
163
@@ -190,7 +202,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
190
202
assert (
191
203
listeners [channel ]["electrical_measurement" ].attribute_updates [2 ][1 ]
192
204
== POWER
193
- if not bidirectional or direction == FORWARD
205
+ if not direction_attrs or direction == FORWARD
194
206
else - POWER
195
207
)
196
208
assert (
@@ -222,7 +234,7 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
222
234
)
223
235
assert (
224
236
listeners [channel ]["metering" ].attribute_updates [0 ][1 ] == POWER
225
- if not bidirectional or direction == FORWARD
237
+ if not direction_attrs or direction == FORWARD
226
238
else - POWER
227
239
)
228
240
assert (
@@ -275,9 +287,8 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
275
287
@pytest .mark .parametrize (
276
288
"model,manuf,mitigation_config,basic_cluster_match" ,
277
289
[
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
281
292
("_TZE204_81yrt3lo" , "TS0601" , 2 , None ), # Enabled
282
293
(
283
294
"_TZE204_81yrt3lo" ,
@@ -289,6 +300,26 @@ async def test_tuya_energy_meter_quirk_energy_direction_align(
289
300
"stack_version" : 0 ,
290
301
},
291
302
),
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
+ ),
292
323
],
293
324
)
294
325
async def test_tuya_energy_meter_quirk_energy_direction_delay_mitigation (
0 commit comments