30
30
import chip .clusters as Clusters
31
31
from chip .clusters .Types import NullValue
32
32
from chip .interaction_model import InteractionModelError , Status
33
- from matter_testing_support import MatterBaseTest , TestStep , async_test_body , default_matter_test_main
33
+ from matter_testing_support import (AttributeValue , ClusterAttributeChangeAccumulator , MatterBaseTest , TestStep , async_test_body ,
34
+ default_matter_test_main )
34
35
from mobly import asserts
35
36
36
37
@@ -45,14 +46,22 @@ def desc_TC_VALCC_3_3(self) -> str:
45
46
def steps_TC_VALCC_3_3 (self ) -> list [TestStep ]:
46
47
steps = [
47
48
TestStep (1 , "Commissioning, already done" , is_commissioning = True ),
48
- TestStep (2 , "Read AttributeList attribute" ),
49
- TestStep (3 , "Read DefaultOpenLevel attribute, if supported" ),
50
- TestStep (4 , "Send Open command" ),
51
- TestStep (5 , "Read TargetLevel attribute" ),
52
- TestStep (6 , "Read CurrentLevel attribute" ),
53
- TestStep (7 , "Send Close command" ),
54
- TestStep (8 , "Read TargetLevel attribute" ),
55
- TestStep (9 , "Read CurrentLevel attribute" ),
49
+ TestStep (2 , "Read AttributeList attribute" , "Verify that the DUT response contains the AttributeList attribute." ),
50
+ TestStep (3 , "If the DefaultOpenLevel is not supported, skip all remaining steps in this test" ),
51
+ TestStep (4 , "TH reads from the DUT the DefaultOpenLevel attribute. Store the value as defaultOpenLevel." ),
52
+ TestStep (5 , "Set up a subscription to all attributes on the DUT" , "Subscription is successful" ),
53
+ TestStep (6 , "Send a close command to the DUT and wait until the CurrentState is reported as closed" , "DUT returns SUCCESS" ),
54
+ # TODO: this test should probably SET the default open attribute as well and un-set it at the end, so we're not testing against the default.
55
+ TestStep (7 , "Send Open command with no fields populated" , "DUT returns SUCCESS" ),
56
+ TestStep (8 , "Wait until TH receives the following data reports (ordering not checked): TargetState set to NULL, TargetLevel set to NULL, CurrentState set to Open, CurrentLevel set to defaultOpenLevel" ,
57
+ "Expected attribute reports are received" ),
58
+ TestStep (9 , "Read CurrentState and TargetState attribute" , "CurrentState is Open, TargetState is NULL" ),
59
+ TestStep (10 , "Read CurrentLevel and TargetLevel attribute" , "CurrentLevel is defaultOpenLevel, TargetLevel is NULL" ),
60
+ TestStep (11 , "Send Close command" , "DUT returns SUCCESS" ),
61
+ TestStep (12 , "Wait until TH receives the following data reports (ordering not checked): TargetState set to NULL, TargetLevel set to NULL, CurrentState set to Closed, CurrentLevel set to 0" ,
62
+ "Expected attribute reports are received" ),
63
+ TestStep (13 , "Read CurrentState and TargetState attribute" , "CurrentState is Closed, TargetState is NULL" ),
64
+ TestStep (14 , "Read CurrentLevel and TargetLevel attribute" , "CurrentLevel is 0, TargetLevel is NULL" ),
56
65
]
57
66
return steps
58
67
@@ -74,78 +83,75 @@ async def test_TC_VALCC_3_3(self):
74
83
attribute_list = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .AttributeList )
75
84
76
85
self .step (3 )
77
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
78
- defaultOpenLevel = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .DefaultOpenLevel )
79
- else :
80
- logging .info ("Test step skipped" )
86
+ if attributes .DefaultOpenLevel .attribute_id not in attribute_list :
87
+ asserts .skip ('Endpoint does not match test requirements' )
81
88
82
89
self .step (4 )
83
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
84
- try :
85
- await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Open (), endpoint = endpoint )
86
- except InteractionModelError as e :
87
- asserts .assert_equal (e .status , Status .Success , "Unexpected error returned" )
88
- pass
89
- else :
90
- logging .info ("Test step skipped" )
90
+ default_open_level = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .DefaultOpenLevel )
91
91
92
92
self .step (5 )
93
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
94
- target_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetLevel )
95
-
96
- asserts .assert_true (target_level_dut is not NullValue , "TargetLevel is null" )
97
- asserts .assert_equal (target_level_dut , defaultOpenLevel , "TargetLevel is not the expected value" )
98
- else :
99
- logging .info ("Test step skipped" )
93
+ cluster = Clusters .ValveConfigurationAndControl
94
+ attributes = cluster .Attributes
95
+ attribute_subscription = ClusterAttributeChangeAccumulator (cluster )
96
+ await attribute_subscription .start (self .default_controller , self .dut_node_id , endpoint )
100
97
101
98
self .step (6 )
102
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
103
- current_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentLevel )
104
- asserts .assert_true (current_level_dut is not NullValue , "CurrentLevel is null" )
105
-
106
- while current_level_dut != defaultOpenLevel :
107
- time .sleep (1 )
108
-
109
- current_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentLevel )
110
- asserts .assert_true (current_level_dut is not NullValue , "CurrentLevel is null" )
111
-
112
- asserts .assert_equal (current_level_dut , defaultOpenLevel , "CurrentLevel is not the expected value" )
113
- else :
114
- logging .info ("Test step skipped" )
99
+ timeout = self .matter_test_config .timeout if self .matter_test_config .timeout is not None else self .default_timeout
100
+ await self .send_single_cmd (cmd = cluster .Commands .Close (), endpoint = endpoint )
101
+ current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
102
+ if current_state_dut != cluster .Enums .ValveStateEnum .kClosed :
103
+ current_state_closed = AttributeValue (
104
+ endpoint_id = endpoint , attribute = attributes .CurrentState , value = cluster .Enums .ValveStateEnum .kClosed )
105
+ attribute_subscription .await_all_final_values_reported (
106
+ expected_final_values = [current_state_closed ], timeout_sec = timeout )
115
107
116
108
self .step (7 )
117
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
118
- try :
119
- await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Close (), endpoint = endpoint )
120
- except InteractionModelError as e :
121
- asserts .assert_equal (e .status , Status .Success , "Unexpected error returned" )
122
- pass
123
- else :
124
- logging .info ("Test step skipped" )
109
+ attribute_subscription .reset ()
110
+ await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Open (), endpoint = endpoint )
125
111
126
112
self .step (8 )
127
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
128
- target_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetLevel )
129
-
130
- asserts .assert_true (target_level_dut is not NullValue , "TargetLevel is null" )
131
- asserts .assert_equal (target_level_dut , 0 , "TargetLevel is not the expected value" )
132
- else :
133
- logging .info ("Test step skipped" )
113
+ expected_final_state = [AttributeValue (endpoint_id = endpoint , attribute = attributes .TargetState , value = NullValue ),
114
+ AttributeValue (endpoint_id = endpoint , attribute = attributes .CurrentState ,
115
+ value = cluster .Enums .ValveStateEnum .kOpen ),
116
+ AttributeValue (endpoint_id = endpoint , attribute = attributes .TargetLevel , value = NullValue ),
117
+ AttributeValue (endpoint_id = endpoint , attribute = attributes .CurrentLevel , value = default_open_level )]
118
+ attribute_subscription .await_all_final_values_reported (expected_final_values = expected_final_state , timeout_sec = timeout )
134
119
135
120
self .step (9 )
136
- if attributes .DefaultOpenLevel .attribute_id in attribute_list :
137
- current_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentLevel )
138
- asserts .assert_true (current_level_dut is not NullValue , "CurrentLevel is null" )
139
-
140
- while current_level_dut is Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kTransitioning :
141
- time .sleep (1 )
142
-
143
- current_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentLevel )
144
- asserts .assert_true (current_level_dut is not NullValue , "CurrentLevel is null" )
145
-
146
- asserts .assert_equal (current_level_dut , 0 , "CurrentLevel is not the expected value" )
147
- else :
148
- logging .info ("Test step skipped" )
121
+ target_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetState )
122
+ current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
123
+ asserts .assert_equal (current_state_dut , cluster .Enums .ValveStateEnum .kOpen , "CurrentState is not open" )
124
+ asserts .assert_equal (target_state_dut , NullValue , "TargetState is not null" )
125
+
126
+ self .step (10 )
127
+ target_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetLevel )
128
+ current_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentLevel )
129
+ asserts .assert_equal (current_level_dut , default_open_level , "CurrentLevel is not defaultOpenLevel" )
130
+ asserts .assert_equal (target_level_dut , NullValue , "TargetLevel is not null" )
131
+
132
+ self .step (11 )
133
+ attribute_subscription .reset ()
134
+ await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Close (), endpoint = endpoint )
135
+
136
+ self .step (12 )
137
+ expected_final_state = [AttributeValue (endpoint_id = endpoint , attribute = attributes .TargetState , value = NullValue ),
138
+ AttributeValue (endpoint_id = endpoint , attribute = attributes .CurrentState ,
139
+ value = cluster .Enums .ValveStateEnum .kClosed ),
140
+ AttributeValue (endpoint_id = endpoint , attribute = attributes .TargetLevel , value = NullValue ),
141
+ AttributeValue (endpoint_id = endpoint , attribute = attributes .CurrentLevel , value = 0 )]
142
+ attribute_subscription .await_all_final_values_reported (expected_final_values = expected_final_state , timeout_sec = timeout )
143
+
144
+ self .step (13 )
145
+ target_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetState )
146
+ current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
147
+ asserts .assert_equal (current_state_dut , cluster .Enums .ValveStateEnum .kClosed , "CurrentState is not open" )
148
+ asserts .assert_equal (target_state_dut , NullValue , "TargetState is not null" )
149
+
150
+ self .step (14 )
151
+ target_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetLevel )
152
+ current_level_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentLevel )
153
+ asserts .assert_equal (current_level_dut , 0 , "CurrentLevel is not 0" )
154
+ asserts .assert_equal (target_level_dut , NullValue , "TargetLevel is not null" )
149
155
150
156
151
157
if __name__ == "__main__" :
0 commit comments