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
import logging
39
39
40
40
import chip .clusters as Clusters
41
- from chip .clusters .Types import Nullable
42
41
from chip .testing .matter_testing import MatterBaseTest , TestStep , async_test_body , default_matter_test_main
43
42
from mobly import asserts
43
+ from chip .clusters .Types import NullValue
44
44
45
45
logger = logging .getLogger (__name__ )
46
46
47
47
48
48
class MOD_1_2 (MatterBaseTest ):
49
49
"""Proposal test for Mode Select Cluster attributes as a server."""
50
50
51
- def TC_MOD_1_2 (self ) -> str :
51
+ def desc_MOD_1_2 (self ) -> str :
52
52
return "80.2.1. [TC-MOD-1.2] Cluster attributes with DUT as Server"
53
53
54
54
def pics_MOD_1_2 (self ):
@@ -91,26 +91,25 @@ def _verify_supported_mode(self, supported_mode):
91
91
logger .info (
92
92
"SupportedMode.semanticTags contains values, verifying attributes for manufacturedcode and value are not longer than 16bits int" )
93
93
for semantictag in supported_mode .semanticTags :
94
- asserts .assert_true (semantictag >= 0 and semantictag .mfgCode <= self ._16bitshex ,
94
+ asserts .assert_true (semantictag . mfgCode >= 0 and semantictag .mfgCode <= self ._16bitshex ,
95
95
"Element semantictag.Mfgcode is greater than 16 bits" )
96
- asserts .assert_true (semantictag >= 0 and semantictag .value <= self ._16bitshex ,
96
+ asserts .assert_true (semantictag . value >= 0 and semantictag .value <= self ._16bitshex ,
97
97
"Element semantictag.Value is greater than 16 bits" )
98
98
99
99
def _log_attribute (self , name , value ):
100
- logger .info (f"{ name } attribute { value } with type { type (value )} " )
100
+ logger .info (f"{ name } attribute with value: { value } with type: { type (value )} " )
101
101
102
102
@async_test_body
103
103
async def test_MOD_1_2 (self ):
104
104
self .cluster = Clusters .ModeSelect
105
105
self .endpoint = self .get_endpoint (1 )
106
106
self ._16bitshex = 0xFFFF
107
- self .is_ci = self .check_pics ("PICS_SDK_CI_ONLY" )
108
107
109
- # commision device
110
- # in the test plan step 1 is defined as a precondition.
108
+ # Commision device
109
+ # In the test plan step 1 is defined as a precondition.
111
110
self .step (1 )
112
111
113
- # veirfy the Supported modes
112
+ # Veirfy the Supported modes
114
113
# Verify contains attributes label and mode
115
114
# Verify if semantic tags has elements in list , and if there are values assert the values
116
115
self .step (2 )
@@ -122,9 +121,9 @@ async def test_MOD_1_2(self):
122
121
for supported_mode in supported_modes :
123
122
logger .info (
124
123
f"Label { supported_mode } with type { type (supported_mode )} and { supported_mode .label } and { supported_mode .mode } and { supported_mode .semanticTags } " )
125
- # verify the struct values
124
+ # Verify the struct values
126
125
self ._verify_supported_mode (supported_mode = supported_mode )
127
- # after verifying the struct is correct append the mode value.
126
+ # After verifying the struct is correct append the mode value.
128
127
supported_modes_values .append (supported_mode .mode )
129
128
logger .info (f"Supported modes values { supported_modes_values } " )
130
129
@@ -137,30 +136,31 @@ async def test_MOD_1_2(self):
137
136
138
137
self .step (4 )
139
138
on_mode = await self .read_single_attribute_check_success (endpoint = self .endpoint , cluster = self .cluster , attribute = self .cluster .Attributes .OnMode )
140
- # On mode can be null
139
+ # On mode can be Nullvalue
141
140
self ._log_attribute ("OnMode" , on_mode )
142
- asserts .assert_true ((isinstance (on_mode , int ) or isinstance ( on_mode , Nullable ) ),
143
- "Onmode is not int or is not clusters.Types.Nullable " )
144
- # verify that OnMode is in the list of Supported Modes, but if null, cant be verified.
145
- if not isinstance ( on_mode , Nullable ) :
146
- asserts .assert_in (on_mode , supported_modes_values , f"Onmode { current_mode } is not in { supported_modes_values } " )
141
+ asserts .assert_true ((isinstance (on_mode , int ) or on_mode is NullValue ),
142
+ "Onmode is not int or is not Nullvalue " )
143
+ # Verify that OnMode is in the list of Supported Modes, but if null, cant be verified.
144
+ if on_mode is not NullValue :
145
+ asserts .assert_in (on_mode , supported_modes_values , f"Onmode { on_mode } is not in { supported_modes_values } " )
147
146
148
- # Validate startup mode
147
+ # Validate startup mode ( attribute Startup is optional)
149
148
self .step (5 )
150
- startup_mode = await self .read_single_attribute_check_success (endpoint = self .endpoint , cluster = self .cluster , attribute = self .cluster .Attributes .StartUpMode )
151
- self ._log_attribute ("StartupMode" , startup_mode )
152
- asserts .assert_true (isinstance (startup_mode , int ), "Startupmode is not int" )
153
- asserts .assert_in (startup_mode , supported_modes_values , f"Startupmode { current_mode } is not in { supported_modes_values } " )
154
-
155
- # Verify the string for ci is larger that 1 char.
149
+ if await self .attribute_guard (endpoint = self .endpoint , attribute = self .cluster .Attributes .StartUpMode ):
150
+ startup_mode = await self .read_single_attribute_check_success (endpoint = self .endpoint , cluster = self .cluster , attribute = self .cluster .Attributes .StartUpMode )
151
+ self ._log_attribute ("StartupMode" , startup_mode )
152
+ asserts .assert_true (isinstance (startup_mode , int ), "Startupmode is not int" )
153
+ asserts .assert_in (startup_mode , supported_modes_values ,
154
+ f"Startupmode { startup_mode } is not in { supported_modes_values } " )
155
+
156
+ # Verify the string is str and larger that 1 char.
156
157
# If is non ci ask the user if can read and understand the string.
157
158
self .step (6 )
158
159
description = await self .read_single_attribute_check_success (endpoint = self .endpoint , cluster = self .cluster , attribute = self .cluster .Attributes .Description )
159
160
self ._log_attribute ("Description" , description )
160
- if self .is_ci :
161
- asserts .assert_true (isinstance (description , str ), "Description attribute is not str" )
162
- asserts .assert_true (len (description ) >= 1 , "Description is lower that 1 char." )
163
- else :
161
+ asserts .assert_true (isinstance (description , str ), "Description attribute is not str" )
162
+ asserts .assert_true (len (description ) >= 1 , "Description is lower that 1 char." )
163
+ if not self .is_pics_sdk_ci_only :
164
164
user_response = self .wait_for_user_input (prompt_msg = f"Is the value \" { description } \" for attribute Description a readable and understandable string? Enter 'y' or 'n'" ,
165
165
prompt_msg_placeholder = "y" ,
166
166
default_value = "y" )
@@ -170,8 +170,8 @@ async def test_MOD_1_2(self):
170
170
self .step (7 )
171
171
standard_namepace = await self .read_single_attribute_check_success (endpoint = self .endpoint , cluster = self .cluster , attribute = self .cluster .Attributes .StandardNamespace )
172
172
self ._log_attribute ("StandardNamespace" , standard_namepace )
173
- asserts .assert_true ((isinstance ( standard_namepace , Nullable ) or (isinstance (standard_namepace , int ) and (standard_namepace >= 0 and standard_namepace <= self ._16bitshex ))),
174
- "Standard namespace is not 16bit enum or not Nullable " )
173
+ asserts .assert_true ((standard_namepace is NullValue or (isinstance (standard_namepace , int ) and (standard_namepace >= 0 and standard_namepace <= self ._16bitshex ))),
174
+ "Standard namespace is not 16bit enum or not Nullvalue " )
175
175
176
176
177
177
if __name__ == "__main__" :
0 commit comments