45
45
46
46
class TC_IDM_4_3 (MatterBaseTest ):
47
47
48
+ # ANSI escape codes for background colors
49
+ BACKGROUND_COLORS = {
50
+ 'black' : '\033 [40m' ,
51
+ 'red' : '\033 [41m' ,
52
+ 'green' : '\033 [42m' ,
53
+ 'yellow' : '\033 [43m' ,
54
+ 'blue' : '\033 [44m' ,
55
+ 'magenta' : '\033 [45m' ,
56
+ 'cyan' : '\033 [46m' ,
57
+ 'white' : '\033 [47m' ,
58
+ 'reset' : '\033 [0m'
59
+ }
60
+
61
+ # Function to print text with a specific background color
62
+ def fprint (self , text : str , background_color : str ):
63
+ print (f"{ self .BACKGROUND_COLORS .get (background_color , self .BACKGROUND_COLORS ['reset' ])} { text } { self .BACKGROUND_COLORS ['reset' ]} " )
64
+
48
65
def steps_TC_IDM_4_3 (self ):
49
66
return [TestStep ("1a" , "DUT and TH activate the subscription." ,
50
67
"Verify on the TH, a report data message is received. Verify on the TH the Subscribe Response has the following fields: SubscriptionId and MaxInterval In the following Steps 2, 3, 5-10, 13, and 15, the MaxInterval time reference in each step is the MaxInterval presented in the Subscribe Response of the subscription." ),
@@ -93,11 +110,45 @@ def steps_TC_IDM_4_3(self):
93
110
]
94
111
95
112
def on_notify_subscription_still_active (self ):
96
- print ("NotifyLogic" )
113
+
114
+ self .previous_report_data_time = self .current_report_data_time
115
+ self .current_report_data_time = time .time ()
116
+
117
+ if self .previous_report_data_time > 0 :
118
+ diff = self .current_report_data_time - self .previous_report_data_time
119
+ else :
120
+ diff = 0
121
+
122
+ self .fprint (f"NotifyLogic { time .time ()} >>> t: { diff } " , "red" )
123
+
124
+ def wait_for_attribute_update_report (self , expected_attribute , output ):
125
+ try :
126
+ path , transaction = output .get (block = True , timeout = 10 )
127
+ except queue .Empty :
128
+ asserts .fail (
129
+ f"[AttributeChangeCallback | Local] Failed to receive a report for the { expected_attribute } attribute change" )
130
+
131
+ asserts .assert_equal (path .AttributeType , expected_attribute ,
132
+ f"[AttributeChangeCallback | Local] Received incorrect report. Expected: { expected_attribute } , received: { path .AttributeType } " )
133
+ try :
134
+ attribute_value = transaction .GetAttribute (path )
135
+
136
+ self .attr_update_report_data_time = time .time ()
137
+
138
+ logging .info (
139
+ f"[AttributeChangeCallback | Local] Got attribute subscription report. Attribute { path .AttributeType } . Updated value: { attribute_value } . SubscriptionId: { transaction .subscriptionId } " )
140
+ except KeyError :
141
+ asserts .fail ("[AttributeChangeCallback | Local] Attribute {expected_attribute} not found in returned report" )
142
+
143
+ current_report_data_time : time = 0
144
+ previous_report_data_time : time = 0
145
+ attr_update_report_data_time : time = 0
146
+
147
+ min_interval_floor_sec : int = 2
148
+ max_interval_ceiling_sec : int = 3
97
149
98
150
@async_test_body
99
151
async def test_TC_IDM_4_3 (self ):
100
- print ("Hey there" )
101
152
102
153
# Test setup
103
154
node_label_attr = Clusters .BasicInformation .Attributes .NodeLabel
@@ -109,44 +160,30 @@ async def test_TC_IDM_4_3(self):
109
160
self .step ("1a" )
110
161
111
162
# Subscribe to attribute
112
- sub_th_step1a = await TH .ReadAttribute (
163
+ sub_th_step1ab = await TH .ReadAttribute (
113
164
nodeid = self .dut_node_id ,
114
165
attributes = node_label_attr_path ,
115
- reportInterval = (3 , 5 ),
166
+ reportInterval = (self . min_interval_floor_sec , self . max_interval_ceiling_sec ),
116
167
keepSubscriptions = False
117
168
)
118
169
170
+ sub_th_step1ab .SetNotifySubscriptionStillActiveCallback (self .on_notify_subscription_still_active )
119
171
120
-
121
-
122
-
123
-
124
-
125
- sub_th_step1a .SetNotifySubscriptionStillActiveCallback (self .on_notify_subscription_still_active )
126
-
127
- secs = 60
172
+ secs = 45
128
173
print (f"\n \n \n \n \n Time to sleep { secs } second(s)" )
129
174
time .sleep (secs )
130
175
print (f"Rise and shine after { secs } second(s)\n \n \n \n \n " )
131
176
132
-
133
-
134
-
135
-
136
-
137
-
138
177
# Verify that the subscription is activated between TH and DUT
139
178
# Verify on the TH, a report data message is received.
140
- asserts .assert_true (sub_th_step1a .subscriptionId , "Subscription not activated" )
179
+ asserts .assert_true (sub_th_step1ab .subscriptionId , "Subscription not activated" )
141
180
142
181
# Verify subscriptionId field is present
143
- asserts .assert_is_not_none (sub_th_step1a .subscriptionId , "SubscriptionId field not present" )
182
+ asserts .assert_is_not_none (sub_th_step1ab .subscriptionId , "SubscriptionId field not present" )
144
183
145
184
# Verify MaxInterval field is present
146
- sub_th_step1a_min_interval_sec , sub_th_step1a_max_interval_sec = sub_th_step1a .GetReportingIntervalsSeconds ()
147
- asserts .assert_is_not_none (sub_th_step1a_max_interval_sec , "MaxInterval field not present" )
148
-
149
- # sub_th_step1a.Shutdown()
185
+ sub_th_step1ab_min_interval_sec , sub_th_step1ab_max_interval_sec = sub_th_step1ab .GetReportingIntervalsSeconds ()
186
+ asserts .assert_is_not_none (sub_th_step1ab_max_interval_sec , "MaxInterval field not present" )
150
187
151
188
# *** Step 1b ***
152
189
# Change the value of the attribute which has been subscribed on the DUT by manually changing some
@@ -156,16 +193,29 @@ async def test_TC_IDM_4_3(self):
156
193
157
194
# Set Attribute Update Callback
158
195
node_label_update_cb = AttributeChangeCallback (node_label_attr )
159
- sub_th_step1a .SetAttributeUpdateCallback (node_label_update_cb )
196
+ sub_th_step1ab .SetAttributeUpdateCallback (node_label_update_cb )
160
197
161
- # Modify attribute value
198
+ # Update attribute value
162
199
new_node_label_write = "NewNodeLabel_11001100"
163
200
await TH .WriteAttribute (
164
201
self .dut_node_id ,
165
202
[(0 , node_label_attr (value = new_node_label_write ))]
166
203
)
167
204
168
- node_label_update_cb .wait_for_report ()
205
+ self .wait_for_attribute_update_report (node_label_attr , node_label_update_cb ._output )
206
+
207
+ # Number of seconds elapsed between the last report data event
208
+ # and the arrival of the attribute update report data
209
+ elapsed_time_since_report = self .attr_update_report_data_time - self .previous_report_data_time
210
+
211
+ # Verify that the attribute update report data is sent
212
+ # after MinInterval time and before MaxInterval time
213
+ asserts .assert_greater (elapsed_time_since_report , self .min_interval_floor_sec ,
214
+ f"Attribute update report data must be sent after the MinInterval" )
215
+ asserts .assert_less (elapsed_time_since_report , self .max_interval_ceiling_sec ,
216
+ f"Attribute update report data must be sent before the MaxInterval" )
217
+
218
+ sub_th_step1ab .Shutdown ()
169
219
170
220
171
221
if __name__ == "__main__" :
0 commit comments