Skip to content

Commit c35fab6

Browse files
Removed types defined on class variables as string and moved to Enum
1 parent 175ae17 commit c35fab6

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

src/python_testing/TC_CC_2_1.py

+55-50
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
# === END CI TEST ARGUMENTS ===
3737

3838
import logging
39+
from enum import Enum
3940
from typing import Optional
4041

4142
import chip.clusters as Clusters
@@ -48,6 +49,15 @@
4849
logger = logging.getLogger(__name__)
4950

5051

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+
5161
class TC_CC_2_1(MatterBaseTest):
5262

5363
def desc_TC_CC_2_1(self) -> str:
@@ -133,12 +143,12 @@ def steps_TC_CC_2_1(self) -> list[TestStep]:
133143

134144
return steps
135145

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):
137147
"""Verify the attribute exists and value is the specific type of value.
138148
139149
Args:
140150
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)
142152
enum_range (list, optional): Range that the enum may have. 0-2 or 0-5. Defaults to Optional[list].
143153
min_len (int, optional): If present verify the low range of the attribute.
144154
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
150160
# it is so retrieve the value to check the type.
151161
attr_val = await self.read_single_attribute_check_success(cluster=self.cluster, attribute=attribute, endpoint=self.endpoint)
152162
logger.info(f"Current value for {attribute} is {attr_val}")
153-
if data_type == self.UINT8:
163+
if data_type == ValueTypesEnum.UINT8:
154164
logger.info("Checkng is uint8")
155165
matter_asserts.assert_valid_uint8(attr_val, "Is not uint8")
156-
elif data_type == self.UINT16:
166+
elif data_type == ValueTypesEnum.UINT16:
157167
logger.info("Checkng is uint16")
158168
matter_asserts.assert_valid_uint16(attr_val, "Is not uint16")
159-
elif data_type == self.UINT32:
169+
elif data_type == ValueTypesEnum.UINT32:
160170
logger.info("Checkng is uint32")
161171
matter_asserts.assert_valid_uint32(attr_val, "Is not uint32")
162-
elif data_type == self.ENUM:
172+
elif data_type == ValueTypesEnum.ENUM:
163173
if len(enum_range) >= 0:
164174
logger.info(f"Checking for enum with range {enum_range}")
165175
asserts.assert_in(attr_val, enum_range, f"Value is not in range for enum with range {enum_range}")
166176
else:
167177
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):
169179
if max_len > 0:
170180
logger.info(f"Validating string with a max len of {max_len}")
171181
asserts.assert_true((len(attr_val) <= max_len), "String len is out of range.")
172182
else:
173-
asserts.fail("FAILED")
183+
asserts.fail("Invalid String range provided.")
174184
else:
175185
asserts.fail("Validation not possible as not data type provided.")
176186

177187
# if we land at this point it mean validation had passed
178188
# 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):
180190
if isinstance(min_len, int):
181191
logger.info(f"Min len defined validation max range for uint {min_len}")
182192
asserts.assert_true((attr_val >= min_len),
@@ -215,85 +225,80 @@ def _verify_first_4bits(self, numa, numb):
215225

216226
@async_test_body
217227
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"
223228
self.cluster = Clusters.ColorControl
224229
self.endpoint = self.get_endpoint(1)
225230
self.attributes = Clusters.ColorControl.Attributes
226231

227232
self.step(1)
228233

229234
self.step(2)
230-
await self._verify_attribute(self.attributes.CurrentHue, self.UINT8)
235+
await self._verify_attribute(self.attributes.CurrentHue, ValueTypesEnum.UINT8)
231236

232237
self.step(3)
233-
await self._verify_attribute(self.attributes.CurrentSaturation, self.UINT8)
238+
await self._verify_attribute(self.attributes.CurrentSaturation, ValueTypesEnum.UINT8)
234239

235240
self.step(4)
236-
await self._verify_attribute(self.attributes.RemainingTime, self.UINT16)
241+
await self._verify_attribute(self.attributes.RemainingTime, ValueTypesEnum.UINT16)
237242

238243
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)
240245

241246
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)
243248

244249
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))
246251

247252
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)
249254

250255
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)
252257

253258
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))
255260

256261
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)
258263

259264
self.step(12)
260-
await self._verify_attribute(self.attributes.EnhancedCurrentHue, self.UINT16)
265+
await self._verify_attribute(self.attributes.EnhancedCurrentHue, ValueTypesEnum.UINT16)
261266

262267
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))
264269

265270
self.step(14)
266-
await self._verify_attribute(self.attributes.ColorLoopActive, self.UINT8)
271+
await self._verify_attribute(self.attributes.ColorLoopActive, ValueTypesEnum.UINT8)
267272

268273
self.step(15)
269-
await self._verify_attribute(self.attributes.ColorLoopDirection, self.UINT8)
274+
await self._verify_attribute(self.attributes.ColorLoopDirection, ValueTypesEnum.UINT8)
270275

271276
self.step(16)
272-
await self._verify_attribute(self.attributes.ColorLoopTime, self.UINT16)
277+
await self._verify_attribute(self.attributes.ColorLoopTime, ValueTypesEnum.UINT16)
273278

274279
self.step(17)
275-
await self._verify_attribute(self.attributes.ColorLoopStartEnhancedHue, self.UINT16)
280+
await self._verify_attribute(self.attributes.ColorLoopStartEnhancedHue, ValueTypesEnum.UINT16)
276281

277282
self.step(18)
278-
await self._verify_attribute(self.attributes.ColorLoopStoredEnhancedHue, self.UINT16)
283+
await self._verify_attribute(self.attributes.ColorLoopStoredEnhancedHue, ValueTypesEnum.UINT16)
279284

280285
self.step("18.a")
281286
# read and save FeatureMap attribute
282287
feature_map_value = await self.read_single_attribute_check_success(cluster=self.cluster, endpoint=self.endpoint, attribute=self.attributes.FeatureMap)
283288

284289
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)
286291
# verify the first 4 bits of colorcapabilities are the same on FeatureMap
287292
self._verify_first_4bits(feature_map_value, color_capabilities_value)
288293

289294
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)
291296

292297
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)
294299

295300
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)
297302

298303
self.step(23)
299304
# Manual check
@@ -306,7 +311,7 @@ async def test_TC_CC_2_1(self):
306311
# Issue: #9103 to address remove 0 in NumberofPrimaries.
307312
# After this is resolved, check not 0.
308313
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)
310315
# Verify for numberofprimaries section
311316
# We are at step 24 before all the number of primaries checks
312317
current_step = 24
@@ -323,47 +328,47 @@ async def test_TC_CC_2_1(self):
323328
# Get the attributes to check then perform guard (at _verify_attribute)
324329
current_step += 1
325330
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)
327332
current_step += 1
328333
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)
330335
current_step += 1
331336
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)
333338

334339
# No more check numberofprimaries at this point
335340
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)
337342

338343
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)
340345

341346
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)
343348

344349
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)
346351

347352
self.step(47)
348-
await self._verify_attribute(self.attributes.ColorPointRIntensity, self.UINT8)
353+
await self._verify_attribute(self.attributes.ColorPointRIntensity, ValueTypesEnum.UINT8)
349354

350355
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)
352357

353358
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)
355360

356361
self.step(50)
357-
await self._verify_attribute(self.attributes.ColorPointGIntensity, self.UINT8)
362+
await self._verify_attribute(self.attributes.ColorPointGIntensity, ValueTypesEnum.UINT8)
358363

359364
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)
361366

362367
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)
364369

365370
self.step(53)
366-
await self._verify_attribute(self.attributes.ColorPointBIntensity, self.UINT8)
371+
await self._verify_attribute(self.attributes.ColorPointBIntensity, ValueTypesEnum.UINT8)
367372

368373

369374
if __name__ == "__main__":

0 commit comments

Comments
 (0)