1
1
#
2
- # Copyright (c) 2023 Project CHIP Authors
2
+ # Copyright (c) 2025 Project CHIP Authors
3
3
# All rights reserved.
4
4
#
5
5
# Licensed under the Apache License, Version 2.0 (the "License");
38
38
39
39
import chip .clusters as Clusters
40
40
import langcodes
41
+ import random
41
42
from chip .interaction_model import Status
42
43
from chip .testing .matter_testing import MatterBaseTest , TestStep , default_matter_test_main , has_cluster , run_if_endpoint_matches
44
+ from chip .testing .matter_asserts import assert_non_empty_string
43
45
from mobly import asserts
44
46
45
47
@@ -50,11 +52,8 @@ def pics_TC_LCFG_2_1(self) -> list[str]:
50
52
def has_repeated_values (self , list ):
51
53
return len (list ) != len (set (list ))
52
54
53
- def list_has_maximum_length_of_35_bytes (self , list ):
54
- return all (self .has_maximum_lenght_of_35_bytes (elem ) for elem in list )
55
-
56
- def has_maximum_lenght_of_35_bytes (self , str ):
57
- return len (str .encode ('utf-8' )) <= 35
55
+ def values_have_maximum_length (self , list , max_lenght ):
56
+ return all ((len (elem .encode ('utf-8' )) <= max_lenght ) for elem in list )
58
57
59
58
def supported_locales_has_active_locale (self , list , str ):
60
59
return str in list
@@ -74,30 +73,32 @@ async def test_TC_LCFG_2_1(self):
74
73
75
74
endpoint = self .get_endpoint (default = 0 )
76
75
value_not_present_in_supported_locales = "fw-GB"
77
- es_ES = "es-ES"
76
+ max_lenght_string = 35
77
+ max_length_list = 32
78
78
79
79
# Step 0: Commissioning DUT (already done)
80
80
self .step (0 )
81
81
82
82
# Step 1: TH reads SupportedLocales attribute from DUT
83
83
self .step (1 )
84
84
85
- initial_values_supported_locales = await self .read_single_attribute_check_success (
85
+ initial_supported_locales = await self .read_single_attribute_check_success (
86
86
cluster = Clusters .LocalizationConfiguration ,
87
87
attribute = Clusters .LocalizationConfiguration .Attributes .SupportedLocales ,
88
88
endpoint = endpoint
89
89
)
90
90
91
91
# Verify values in SupportedLocales attribute are not repeated
92
- asserts .assert_false (self .has_repeated_values (initial_values_supported_locales ),
93
- "SupportedLocales attribute has no repeated values" )
92
+ asserts .assert_false (self .has_repeated_values (initial_supported_locales ),
93
+ "SupportedLocales attribute should not have repeated values" )
94
94
95
95
# Verify maximun number of elements in the SupportedLocales list is 32
96
- asserts .assert_true (len (initial_values_supported_locales ) <= 32 , "SupportedLocales attribute has less than 32 elements" )
96
+ asserts .assert_less_equal (len (initial_supported_locales ), max_length_list ,
97
+ "SupportedLocales attribute should have less than " + str (max_length_list ) + " elements" )
97
98
98
- # Verify values of SupportedLocales attribute has a maximum lenght of 35 bytes
99
- asserts .assert_true (self .list_has_maximum_length_of_35_bytes ( initial_values_supported_locales ),
100
- "SupportedLocales attribute has a maximum lenght of 35 bytes" )
99
+ # Verify values of SupportedLocales attribute have a maximum lenght of 35 bytes
100
+ asserts .assert_true (self .values_have_maximum_length ( initial_supported_locales , max_lenght_string ),
101
+ "Values of SupportedLocales attribute should have a maximum lenght of " + str ( max_lenght_string ) + " bytes" )
101
102
102
103
# Step 2: TH reads ActiveLocale attribute from the DUT
103
104
self .step (2 )
@@ -109,19 +110,18 @@ async def test_TC_LCFG_2_1(self):
109
110
)
110
111
111
112
# Verify that the ActiveLocale attribute is not empty
112
- asserts . assert_true ( bool ( initial_active_locale ) , "ActiveLocale attribute is not empty" )
113
+ assert_non_empty_string ( initial_active_locale , "ActiveLocale attribute should not be empty" )
113
114
114
115
# Verify that the ActiveLocale attribute is Language Tag as defined by BCP47
115
- asserts .assert_true (langcodes .tag_is_valid (initial_active_locale ),
116
- "ActiveLocale attribute is Language Tag as defined by BCP47" )
116
+ assert langcodes .tag_is_valid (initial_active_locale ), "ActiveLocale attribute should be Language Tag as defined by BCP47"
117
117
118
118
# Verify that the value of ActiveLocale attribute has maximum lenght of 35 bytes
119
- asserts .assert_true ( self . has_maximum_lenght_of_35_bytes (initial_active_locale ),
120
- "ActiveLocale attribute has less than 35 bytes" )
119
+ asserts .assert_less_equal ( len (initial_active_locale ), max_lenght_string ,
120
+ "ActiveLocale attribute should have less than " + str ( max_lenght_string ) + " bytes" )
121
121
122
122
# Verify that the ActiveLocale attribute value is present in the SupportedLocales attribute list
123
- asserts .assert_true (self .supported_locales_has_active_locale (initial_values_supported_locales ,
124
- initial_active_locale ), "ActiveLocale attribute value is present in the SupportedLocales attribute list" )
123
+ asserts .assert_true (self .supported_locales_has_active_locale (initial_supported_locales ,
124
+ initial_active_locale ), "ActiveLocale attribute value should be present in the SupportedLocales attribute list" )
125
125
126
126
# Step 3: TH writes new string not present in SupportedLocales attribute to ActiveLocale attribute
127
127
self .step (3 )
@@ -134,7 +134,11 @@ async def test_TC_LCFG_2_1(self):
134
134
# Step 4: TH writes new string present in SupportedLocales attribute to ActiveALocale attribute
135
135
self .step (4 )
136
136
137
- value_present_in_supported_locales = initial_values_supported_locales [initial_values_supported_locales .index (es_ES )]
137
+ filtered_supported_locales = [elem for elem in initial_supported_locales if elem != initial_active_locale ]
138
+ if filtered_supported_locales :
139
+ value_present_in_supported_locales = random .choice (filtered_supported_locales )
140
+ else :
141
+ asserts .fail ("SupportedLocales attribute has only one element and is the same value as ActiveLocale" )
138
142
139
143
result = await self .write_single_attribute (attribute_value = Clusters .LocalizationConfiguration .Attributes .ActiveLocale (value_present_in_supported_locales ), endpoint_id = endpoint , expect_success = True )
140
144
0 commit comments