32
32
# quiet: true
33
33
# === END CI TEST ARGUMENTS ===
34
34
35
- import time
36
-
37
35
import chip .clusters as Clusters
38
36
from chip .clusters .Types import NullValue
39
- from chip .interaction_model import InteractionModelError , Status
40
- from chip . testing . matter_testing import MatterBaseTest , TestStep , async_test_body , default_matter_test_main
37
+ from chip .testing . matter_testing import ( AttributeValue , ClusterAttributeChangeAccumulator , MatterBaseTest , TestStep ,
38
+ async_test_body , default_matter_test_main )
41
39
from mobly import asserts
42
40
43
41
@@ -52,12 +50,16 @@ def desc_TC_VALCC_3_1(self) -> str:
52
50
def steps_TC_VALCC_3_1 (self ) -> list [TestStep ]:
53
51
steps = [
54
52
TestStep (1 , "Commissioning, already done" , is_commissioning = True ),
55
- TestStep (2 , "Send Open command" ),
56
- TestStep (3 , "Read TargetState attribute" ),
57
- TestStep (4 , "Read CurrentState attribute" ),
58
- TestStep (5 , "Send Close command" ),
59
- TestStep (6 , "Read TargetState attribute" ),
60
- TestStep (7 , "Read CurrentState attribute" ),
53
+ TestStep (2 , "Set up a subscription to all attributes on the DUT" ),
54
+ TestStep (3 , "Send a close command to the DUT and wait until the CurrentState is closed" , "DUT returns SUCCESS" ),
55
+ TestStep (4 , "Send Open command" , "DUT returns SUCCESS" ),
56
+ TestStep (5 , "Wait until TH receives and data report for TargetState set to NULL and an attribute report for CurrentState set to Open (ordering does not matter)" ,
57
+ "Expected attribute reports are received" ),
58
+ TestStep (6 , "Read CurrentState and TargetState attribute" , "CurrentState is Open, TargetState is NULL" ),
59
+ TestStep (7 , "Send Close command" , "DUT returns SUCCESS" ),
60
+ TestStep (8 , "Wait until TH receives and data report for TargetState set to NULL and an attribute report for CurrentState set to Closed (ordering does not matter)" ,
61
+ "Expected attribute reports are received" ),
62
+ TestStep (9 , "Read CurrentState and TargetState attribute" , "CurrentState is Closed, TargetState is NULL" ),
61
63
]
62
64
return steps
63
65
@@ -72,62 +74,55 @@ async def test_TC_VALCC_3_1(self):
72
74
73
75
endpoint = self .get_endpoint (default = 1 )
74
76
75
- self .step (1 )
76
- attributes = Clusters .ValveConfigurationAndControl .Attributes
77
+ self .step (1 ) # commissioning - already done
77
78
78
79
self .step (2 )
79
- try :
80
- await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Open (), endpoint = endpoint )
81
- except InteractionModelError as e :
82
- asserts .assert_equal (e .status , Status .Success , "Unexpected error returned" )
83
- pass
80
+ cluster = Clusters .ValveConfigurationAndControl
81
+ attributes = cluster .Attributes
82
+ attribute_subscription = ClusterAttributeChangeAccumulator (cluster )
83
+ await attribute_subscription .start (self .default_controller , self .dut_node_id , endpoint )
84
84
85
85
self .step (3 )
86
- target_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetState )
87
-
88
- asserts .assert_true (target_state_dut is not NullValue , "TargetState is null" )
89
- asserts .assert_equal (target_state_dut , Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kOpen ,
90
- "TargetState is not the expected value" )
91
-
92
- self .step (4 )
86
+ # Wait for the entire duration of the test because this valve may be slow. The test will time out before this does. That's fine.
87
+ timeout = self .matter_test_config .timeout if self .matter_test_config .timeout is not None else self .default_timeout
88
+ await self .send_single_cmd (cmd = cluster .Commands .Close (), endpoint = endpoint )
93
89
current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
94
- asserts .assert_true (current_state_dut is not NullValue , "CurrentState is null" )
95
-
96
- while current_state_dut is Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kTransitioning :
97
- time .sleep (1 )
98
-
99
- current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
100
- asserts .assert_true (current_state_dut is not NullValue , "CurrentState is null" )
90
+ if current_state_dut != cluster .Enums .ValveStateEnum .kClosed :
91
+ current_state_closed = AttributeValue (
92
+ endpoint_id = endpoint , attribute = attributes .CurrentState , value = cluster .Enums .ValveStateEnum .kClosed )
93
+ attribute_subscription .await_all_final_values_reported (
94
+ expected_final_values = [current_state_closed ], timeout_sec = timeout )
101
95
102
- asserts .assert_equal (current_state_dut , Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kOpen ,
103
- "CurrentState is not the expected value" )
96
+ self .step (4 )
97
+ attribute_subscription .reset ()
98
+ await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Open (), endpoint = endpoint )
104
99
105
100
self .step (5 )
106
- try :
107
- await self .send_single_cmd (cmd = Clusters .Objects .ValveConfigurationAndControl .Commands .Close (), endpoint = endpoint )
108
- except InteractionModelError as e :
109
- asserts .assert_equal (e .status , Status .Success , "Unexpected error returned" )
110
- pass
101
+ # Wait until the current state is open and the target state is Null.
102
+ expected_final_state = [AttributeValue (endpoint_id = endpoint , attribute = attributes .TargetState , value = NullValue ), AttributeValue (
103
+ endpoint_id = endpoint , attribute = attributes .CurrentState , value = cluster .Enums .ValveStateEnum .kOpen )]
104
+ attribute_subscription .await_all_final_values_reported (expected_final_values = expected_final_state , timeout_sec = timeout )
111
105
112
106
self .step (6 )
113
107
target_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetState )
114
-
115
- asserts .assert_true (target_state_dut is not NullValue , "TargetState is null" )
116
- asserts .assert_equal (target_state_dut , Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kClosed ,
117
- "TargetState is not the expected value" )
118
-
119
- self .step (7 )
120
108
current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
121
- asserts .assert_true (current_state_dut is not NullValue , "CurrentState is null" )
109
+ asserts .assert_equal (current_state_dut , cluster .Enums .ValveStateEnum .kOpen , "CurrentState is not open" )
110
+ asserts .assert_equal (target_state_dut , NullValue , "TargetState is not null" )
122
111
123
- while current_state_dut is Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kTransitioning :
124
- time .sleep (1 )
112
+ self .step (7 )
113
+ attribute_subscription .reset ()
114
+ await self .send_single_cmd (cmd = cluster .Commands .Close (), endpoint = endpoint )
125
115
126
- current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
127
- asserts .assert_true (current_state_dut is not NullValue , "CurrentState is null" )
116
+ self .step (8 )
117
+ expected_final_state = [AttributeValue (endpoint_id = endpoint , attribute = attributes .TargetState , value = NullValue ), AttributeValue (
118
+ endpoint_id = endpoint , attribute = attributes .CurrentState , value = cluster .Enums .ValveStateEnum .kClosed )]
119
+ attribute_subscription .await_all_final_values_reported (expected_final_values = expected_final_state , timeout_sec = timeout )
128
120
129
- asserts .assert_equal (current_state_dut , Clusters .Objects .ValveConfigurationAndControl .Enums .ValveStateEnum .kClosed ,
130
- "CurrentState is not the expected value" )
121
+ self .step (9 )
122
+ target_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .TargetState )
123
+ current_state_dut = await self .read_valcc_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentState )
124
+ asserts .assert_equal (current_state_dut , cluster .Enums .ValveStateEnum .kClosed , "CurrentState is not closed" )
125
+ asserts .assert_equal (target_state_dut , NullValue , "TargetState is not null" )
131
126
132
127
133
128
if __name__ == "__main__" :
0 commit comments