36
36
# === END CI TEST ARGUMENTS ===
37
37
38
38
import logging
39
- from enum import Enum
40
39
from typing import Optional
41
40
42
41
import chip .clusters as Clusters
49
48
logger = logging .getLogger (__name__ )
50
49
51
50
52
- class ValueTypesEnum (Enum ):
53
- """Data types to validate in this case."""
54
- UINT8 = 1
55
- UINT16 = 2
56
- UINT32 = 3
57
- STRING = 4
58
- ENUM = 5
59
-
60
-
61
51
class TC_CC_2_1 (MatterBaseTest ):
62
52
63
53
def desc_TC_CC_2_1 (self ) -> str :
@@ -143,12 +133,12 @@ def steps_TC_CC_2_1(self) -> list[TestStep]:
143
133
144
134
return steps
145
135
146
- async def _verify_attribute (self , attribute : Attribute , data_type : ValueTypesEnum , enum_range : Optional [list ] = None , min_len : Optional [int ] = None , max_len : Optional [int ] = None ):
136
+ async def _verify_attribute (self , attribute : Attribute , data_type : str , enum_range : Optional [list ] = None , min_len : Optional [int ] = None , max_len : Optional [int ] = None ):
147
137
"""Verify the attribute exists and value is the specific type of value.
148
138
149
139
Args:
150
140
attribute (Attribute): Name of the attribute we want to retrieve
151
- data_type (ValueTypesEnum ): type of data we want to validate against (uint8,uint16,uint32,string,enum)
141
+ data_type (str ): type of data we want to validate against (uint8,uint16,uint32,string,enum)
152
142
enum_range (list, optional): Range that the enum may have. 0-2 or 0-5. Defaults to Optional[list].
153
143
min_len (int, optional): If present verify the low range of the attribute.
154
144
max_len (int, optional): If present verify the high range of the attribute.
@@ -160,33 +150,33 @@ async def _verify_attribute(self, attribute: Attribute, data_type: ValueTypesEnu
160
150
# it is so retrieve the value to check the type.
161
151
attr_val = await self .read_single_attribute_check_success (cluster = self .cluster , attribute = attribute , endpoint = self .endpoint )
162
152
logger .info (f"Current value for { attribute } is { attr_val } " )
163
- if data_type == ValueTypesEnum .UINT8 :
153
+ if data_type == self .UINT8 :
164
154
logger .info ("Checkng is uint8" )
165
155
matter_asserts .assert_valid_uint8 (attr_val , "Is not uint8" )
166
- elif data_type == ValueTypesEnum .UINT16 :
156
+ elif data_type == self .UINT16 :
167
157
logger .info ("Checkng is uint16" )
168
158
matter_asserts .assert_valid_uint16 (attr_val , "Is not uint16" )
169
- elif data_type == ValueTypesEnum .UINT32 :
159
+ elif data_type == self .UINT32 :
170
160
logger .info ("Checkng is uint32" )
171
161
matter_asserts .assert_valid_uint32 (attr_val , "Is not uint32" )
172
- elif data_type == ValueTypesEnum .ENUM :
162
+ elif data_type == self .ENUM :
173
163
if len (enum_range ) >= 0 :
174
164
logger .info (f"Checking for enum with range { enum_range } " )
175
165
asserts .assert_in (attr_val , enum_range , f"Value is not in range for enum with range { enum_range } " )
176
166
else :
177
167
asserts .fail ("Range list is empty" )
178
- elif data_type == ValueTypesEnum .STRING and isinstance (attr_val , str ):
168
+ elif data_type == self .STRING and isinstance (attr_val , str ):
179
169
if max_len > 0 :
180
170
logger .info (f"Validating string with a max len of { max_len } " )
181
171
asserts .assert_true ((len (attr_val ) <= max_len ), "String len is out of range." )
182
172
else :
183
- asserts .fail ("Invalid String range provided. " )
173
+ asserts .fail ("FAILED " )
184
174
else :
185
175
asserts .fail ("Validation not possible as not data type provided." )
186
176
187
177
# if we land at this point it mean validation had passed
188
178
# check if string has uint and verify is we need to compare against a min or max value
189
- if 'uint' in data_type . name . lower () and (max_len is not None or min_len is not None ):
179
+ if 'uint' in data_type and (max_len is not None or min_len is not None ):
190
180
if isinstance (min_len , int ):
191
181
logger .info (f"Min len defined validation max range for uint { min_len } " )
192
182
asserts .assert_true ((attr_val >= min_len ),
@@ -225,80 +215,85 @@ def _verify_first_4bits(self, numa, numb):
225
215
226
216
@async_test_body
227
217
async def test_TC_CC_2_1 (self ):
218
+ self .UINT8 = "uint8"
219
+ self .UINT16 = "uint16"
220
+ self .UINT32 = 'uint32'
221
+ self .STRING = "string"
222
+ self .ENUM = "enum"
228
223
self .cluster = Clusters .ColorControl
229
224
self .endpoint = self .get_endpoint (1 )
230
225
self .attributes = Clusters .ColorControl .Attributes
231
226
232
227
self .step (1 )
233
228
234
229
self .step (2 )
235
- await self ._verify_attribute (self .attributes .CurrentHue , ValueTypesEnum .UINT8 )
230
+ await self ._verify_attribute (self .attributes .CurrentHue , self .UINT8 )
236
231
237
232
self .step (3 )
238
- await self ._verify_attribute (self .attributes .CurrentSaturation , ValueTypesEnum .UINT8 )
233
+ await self ._verify_attribute (self .attributes .CurrentSaturation , self .UINT8 )
239
234
240
235
self .step (4 )
241
- await self ._verify_attribute (self .attributes .RemainingTime , ValueTypesEnum .UINT16 )
236
+ await self ._verify_attribute (self .attributes .RemainingTime , self .UINT16 )
242
237
243
238
self .step (5 )
244
- await self ._verify_attribute (self .attributes .CurrentX , ValueTypesEnum .UINT16 , max_len = 0xfeff )
239
+ await self ._verify_attribute (self .attributes .CurrentX , self .UINT16 , max_len = 0xfeff )
245
240
246
241
self .step (6 )
247
- await self ._verify_attribute (self .attributes .CurrentY , ValueTypesEnum .UINT16 , max_len = 0xfeff )
242
+ await self ._verify_attribute (self .attributes .CurrentY , self .UINT16 , max_len = 0xfeff )
248
243
249
244
self .step (7 )
250
- await self ._verify_attribute (self .attributes .DriftCompensation , ValueTypesEnum .ENUM , enum_range = range (0 , 5 ))
245
+ await self ._verify_attribute (self .attributes .DriftCompensation , self .ENUM , enum_range = range (0 , 5 ))
251
246
252
247
self .step (8 )
253
- await self ._verify_attribute (self .attributes .CompensationText , ValueTypesEnum .STRING , max_len = 254 )
248
+ await self ._verify_attribute (self .attributes .CompensationText , self .STRING , max_len = 254 )
254
249
255
250
self .step (9 )
256
- await self ._verify_attribute (self .attributes .ColorTemperatureMireds , ValueTypesEnum .UINT16 , min_len = 1 , max_len = 0xfeff )
251
+ await self ._verify_attribute (self .attributes .ColorTemperatureMireds , self .UINT16 , min_len = 1 , max_len = 0xfeff )
257
252
258
253
self .step (10 )
259
- await self ._verify_attribute (self .attributes .ColorMode , ValueTypesEnum .ENUM , enum_range = range (0 , 3 ))
254
+ await self ._verify_attribute (self .attributes .ColorMode , self .ENUM , enum_range = range (0 , 3 ))
260
255
261
256
self .step (11 )
262
- await self ._verify_attribute (self .attributes .Options , ValueTypesEnum .UINT8 , max_len = 4 )
257
+ await self ._verify_attribute (self .attributes .Options , self .UINT8 , max_len = 4 )
263
258
264
259
self .step (12 )
265
- await self ._verify_attribute (self .attributes .EnhancedCurrentHue , ValueTypesEnum .UINT16 )
260
+ await self ._verify_attribute (self .attributes .EnhancedCurrentHue , self .UINT16 )
266
261
267
262
self .step (13 )
268
- await self ._verify_attribute (self .attributes .EnhancedColorMode , ValueTypesEnum .ENUM , enum_range = range (0 , 4 ))
263
+ await self ._verify_attribute (self .attributes .EnhancedColorMode , self .ENUM , enum_range = range (0 , 4 ))
269
264
270
265
self .step (14 )
271
- await self ._verify_attribute (self .attributes .ColorLoopActive , ValueTypesEnum .UINT8 )
266
+ await self ._verify_attribute (self .attributes .ColorLoopActive , self .UINT8 )
272
267
273
268
self .step (15 )
274
- await self ._verify_attribute (self .attributes .ColorLoopDirection , ValueTypesEnum .UINT8 )
269
+ await self ._verify_attribute (self .attributes .ColorLoopDirection , self .UINT8 )
275
270
276
271
self .step (16 )
277
- await self ._verify_attribute (self .attributes .ColorLoopTime , ValueTypesEnum .UINT16 )
272
+ await self ._verify_attribute (self .attributes .ColorLoopTime , self .UINT16 )
278
273
279
274
self .step (17 )
280
- await self ._verify_attribute (self .attributes .ColorLoopStartEnhancedHue , ValueTypesEnum .UINT16 )
275
+ await self ._verify_attribute (self .attributes .ColorLoopStartEnhancedHue , self .UINT16 )
281
276
282
277
self .step (18 )
283
- await self ._verify_attribute (self .attributes .ColorLoopStoredEnhancedHue , ValueTypesEnum .UINT16 )
278
+ await self ._verify_attribute (self .attributes .ColorLoopStoredEnhancedHue , self .UINT16 )
284
279
285
280
self .step ("18.a" )
286
281
# read and save FeatureMap attribute
287
282
feature_map_value = await self .read_single_attribute_check_success (cluster = self .cluster , endpoint = self .endpoint , attribute = self .attributes .FeatureMap )
288
283
289
284
self .step (19 )
290
- color_capabilities_value = await self ._verify_attribute (self .attributes .ColorCapabilities , ValueTypesEnum .UINT16 , max_len = 0x001f )
285
+ color_capabilities_value = await self ._verify_attribute (self .attributes .ColorCapabilities , self .UINT16 , max_len = 0x001f )
291
286
# verify the first 4 bits of colorcapabilities are the same on FeatureMap
292
287
self ._verify_first_4bits (feature_map_value , color_capabilities_value )
293
288
294
289
self .step (20 )
295
- colortempphysicalminmireds_val = await self ._verify_attribute (self .attributes .ColorTempPhysicalMinMireds , ValueTypesEnum .UINT16 , min_len = 1 , max_len = 0xfeff )
290
+ colortempphysicalminmireds_val = await self ._verify_attribute (self .attributes .ColorTempPhysicalMinMireds , self .UINT16 , min_len = 1 , max_len = 0xfeff )
296
291
297
292
self .step (21 )
298
- colortempphysicalmaxmireds_val = await self ._verify_attribute (self .attributes .ColorTempPhysicalMaxMireds , ValueTypesEnum .UINT16 , min_len = 1 , max_len = 0xfeff )
293
+ colortempphysicalmaxmireds_val = await self ._verify_attribute (self .attributes .ColorTempPhysicalMaxMireds , self .UINT16 , min_len = 1 , max_len = 0xfeff )
299
294
300
295
self .step (22 )
301
- await self ._verify_attribute (self .attributes .CoupleColorTempToLevelMinMireds , ValueTypesEnum .UINT16 , min_len = colortempphysicalminmireds_val , max_len = colortempphysicalmaxmireds_val )
296
+ await self ._verify_attribute (self .attributes .CoupleColorTempToLevelMinMireds , self .UINT16 , min_len = colortempphysicalminmireds_val , max_len = colortempphysicalmaxmireds_val )
302
297
303
298
self .step (23 )
304
299
# Manual check
@@ -311,7 +306,7 @@ async def test_TC_CC_2_1(self):
311
306
# Issue: #9103 to address remove 0 in NumberofPrimaries.
312
307
# After this is resolved, check not 0.
313
308
self .step (24 )
314
- numberofprimaries_value = await self ._verify_attribute (self .attributes .NumberOfPrimaries , ValueTypesEnum .UINT8 , max_len = 6 )
309
+ numberofprimaries_value = await self ._verify_attribute (self .attributes .NumberOfPrimaries , self .UINT8 , max_len = 6 )
315
310
# Verify for numberofprimaries section
316
311
# We are at step 24 before all the number of primaries checks
317
312
current_step = 24
@@ -328,47 +323,47 @@ async def test_TC_CC_2_1(self):
328
323
# Get the attributes to check then perform guard (at _verify_attribute)
329
324
current_step += 1
330
325
self .step (current_step )
331
- await self ._verify_attribute (getattr (self .attributes , f"Primary{ primariesindex } X" ), ValueTypesEnum .UINT16 , max_len = 0xfeff )
326
+ await self ._verify_attribute (getattr (self .attributes , f"Primary{ primariesindex } X" ), self .UINT16 , max_len = 0xfeff )
332
327
current_step += 1
333
328
self .step (current_step )
334
- await self ._verify_attribute (getattr (self .attributes , f"Primary{ primariesindex } Y" ), ValueTypesEnum .UINT16 , max_len = 0xfeff )
329
+ await self ._verify_attribute (getattr (self .attributes , f"Primary{ primariesindex } Y" ), self .UINT16 , max_len = 0xfeff )
335
330
current_step += 1
336
331
self .step (current_step )
337
- await self ._verify_attribute (getattr (self .attributes , f"Primary{ primariesindex } Intensity" ), ValueTypesEnum .UINT8 )
332
+ await self ._verify_attribute (getattr (self .attributes , f"Primary{ primariesindex } Intensity" ), self .UINT8 )
338
333
339
334
# No more check numberofprimaries at this point
340
335
self .step (43 )
341
- await self ._verify_attribute (self .attributes .WhitePointX , ValueTypesEnum .UINT16 , max_len = 0xfeff )
336
+ await self ._verify_attribute (self .attributes .WhitePointX , self .UINT16 , max_len = 0xfeff )
342
337
343
338
self .step (44 )
344
- await self ._verify_attribute (self .attributes .WhitePointY , ValueTypesEnum .UINT16 , max_len = 0xfeff )
339
+ await self ._verify_attribute (self .attributes .WhitePointY , self .UINT16 , max_len = 0xfeff )
345
340
346
341
self .step (45 )
347
- await self ._verify_attribute (self .attributes .ColorPointRX , ValueTypesEnum .UINT16 , max_len = 0xfeff )
342
+ await self ._verify_attribute (self .attributes .ColorPointRX , self .UINT16 , max_len = 0xfeff )
348
343
349
344
self .step (46 )
350
- await self ._verify_attribute (self .attributes .ColorPointRY , ValueTypesEnum .UINT16 , max_len = 0xfeff )
345
+ await self ._verify_attribute (self .attributes .ColorPointRY , self .UINT16 , max_len = 0xfeff )
351
346
352
347
self .step (47 )
353
- await self ._verify_attribute (self .attributes .ColorPointRIntensity , ValueTypesEnum .UINT8 )
348
+ await self ._verify_attribute (self .attributes .ColorPointRIntensity , self .UINT8 )
354
349
355
350
self .step (48 )
356
- await self ._verify_attribute (self .attributes .ColorPointGX , ValueTypesEnum .UINT16 , max_len = 0xfeff )
351
+ await self ._verify_attribute (self .attributes .ColorPointGX , self .UINT16 , max_len = 0xfeff )
357
352
358
353
self .step (49 )
359
- await self ._verify_attribute (self .attributes .ColorPointGY , ValueTypesEnum .UINT16 , max_len = 0xfeff )
354
+ await self ._verify_attribute (self .attributes .ColorPointGY , self .UINT16 , max_len = 0xfeff )
360
355
361
356
self .step (50 )
362
- await self ._verify_attribute (self .attributes .ColorPointGIntensity , ValueTypesEnum .UINT8 )
357
+ await self ._verify_attribute (self .attributes .ColorPointGIntensity , self .UINT8 )
363
358
364
359
self .step (51 )
365
- await self ._verify_attribute (self .attributes .ColorPointBX , ValueTypesEnum .UINT16 , max_len = 0xfeff )
360
+ await self ._verify_attribute (self .attributes .ColorPointBX , self .UINT16 , max_len = 0xfeff )
366
361
367
362
self .step (52 )
368
- await self ._verify_attribute (self .attributes .ColorPointBY , ValueTypesEnum .UINT16 , max_len = 0xfeff )
363
+ await self ._verify_attribute (self .attributes .ColorPointBY , self .UINT16 , max_len = 0xfeff )
369
364
370
365
self .step (53 )
371
- await self ._verify_attribute (self .attributes .ColorPointBIntensity , ValueTypesEnum .UINT8 )
366
+ await self ._verify_attribute (self .attributes .ColorPointBIntensity , self .UINT8 )
372
367
373
368
374
369
if __name__ == "__main__" :
0 commit comments