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