Skip to content

Commit 604227d

Browse files
committed
Use ROOT_NODE_ENDPOINT_ID as default instead of None for endpoint parameters
- Simplifies code by removing None checks and makes default behavior more explicit.
1 parent c945c69 commit 604227d

File tree

2 files changed

+16
-57
lines changed

2 files changed

+16
-57
lines changed

src/python_testing/TC_IDM_4_2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from support_modules.idm_support import IDMBaseTest
4242

4343
import matter.clusters as Clusters
44+
from matter.testing.matter_asserts import is_valid_uint_value
4445
from matter.ChipDeviceCtrl import ChipDeviceController
4546
from matter.clusters import ClusterObjects as ClusterObjects
4647
from matter.exceptions import ChipStackError
@@ -184,12 +185,12 @@ async def test_TC_IDM_4_2(self):
184185
)
185186

186187
# Verify subscriptionId is of uint32 type
187-
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step1.subscriptionId), "subscriptionId is not of uint32 type.")
188+
asserts.assert_true(is_valid_uint_value(sub_cr1_step1.subscriptionId, 32), "subscriptionId is not of uint32 type.")
188189

189190
# Verify MaxInterval is of uint32 type
190191
sub_cr1_step1_intervals = sub_cr1_step1.GetReportingIntervalsSeconds()
191192
sub_cr1_step1_min_interval_floor_sec, sub_cr1_step1_max_interval_ceiling_sec = sub_cr1_step1_intervals
192-
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step1_max_interval_ceiling_sec),
193+
asserts.assert_true(is_valid_uint_value(sub_cr1_step1_max_interval_ceiling_sec, 32),
193194
"MaxInterval is not of uint32 type.")
194195

195196
# Verify MaxInterval is less than or equal to MaxIntervalCeiling
@@ -227,12 +228,12 @@ async def test_TC_IDM_4_2(self):
227228
)
228229

229230
# Verify subscriptionId is of uint32 type
230-
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step2.subscriptionId), "subscriptionId is not of uint32 type.")
231+
asserts.assert_true(is_valid_uint_value(sub_cr1_step2.subscriptionId, 32), "subscriptionId is not of uint32 type.")
231232

232233
# Verify MaxInterval is of uint32 type
233234
sub_cr1_step2_intervals = sub_cr1_step2.GetReportingIntervalsSeconds()
234235
sub_cr1_step2_min_interval_floor_sec, sub_cr1_step2_max_interval_ceiling_sec = sub_cr1_step2_intervals
235-
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step2_max_interval_ceiling_sec),
236+
asserts.assert_true(is_valid_uint_value(sub_cr1_step2_max_interval_ceiling_sec, 32),
236237
"MaxInterval is not of uint32 type.")
237238

238239
# Verify MaxInterval is less than or equal to MaxIntervalCeiling
@@ -527,7 +528,7 @@ async def test_TC_IDM_4_2(self):
527528
cluster_revision_attr_value = sub_cr1_step11.GetAttribute(cluster_rev_attr_typed_path)
528529

529530
# Verify ClusterRevision is of uint16 type
530-
asserts.assert_true(self.is_valid_uint16_value(cluster_revision_attr_value), "ClusterRevision is not of uint16 type.")
531+
asserts.assert_true(is_valid_uint_value(cluster_revision_attr_value, 16), "ClusterRevision is not of uint16 type.")
531532

532533
# Verify valid ClusterRevision value
533534
asserts.assert_greater_equal(cluster_revision_attr_value, 0, "Invalid ClusterRevision value.")
@@ -570,7 +571,7 @@ async def test_TC_IDM_4_2(self):
570571
cluster_revision_attr_value = sub_cr1_step12.GetAttribute(cluster_rev_attr_typed_path)
571572

572573
# Verify ClusterRevision is of uint16 type
573-
asserts.assert_true(self.is_valid_uint16_value(cluster_revision_attr_value), "ClusterRevision is not of uint16 type.")
574+
asserts.assert_true(is_valid_uint_value(cluster_revision_attr_value, 16), "ClusterRevision is not of uint16 type.")
574575

575576
sub_cr1_step12.Shutdown()
576577

src/python_testing/support_modules/idm_support.py

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -93,42 +93,14 @@ def __init__(self, test_instance):
9393

9494
class IDMBaseTest(MatterBaseTest):
9595
"""Base test class for IDM tests with shared functionality."""
96-
96+
9797
ROOT_NODE_ENDPOINT_ID = 0
98-
99-
# ========================================================================
100-
# Type Validators
101-
# ========================================================================
102-
103-
@staticmethod
104-
def is_valid_uint32_value(var):
105-
"""Check if a value is a valid uint32.
106-
107-
Args:
108-
var: Value to check
109-
110-
Returns:
111-
True if value is a valid uint32, False otherwise
112-
"""
113-
return isinstance(var, int) and 0 <= var <= 0xFFFFFFFF
114-
115-
@staticmethod
116-
def is_valid_uint16_value(var):
117-
"""Check if a value is a valid uint16.
118-
119-
Args:
120-
var: Value to check
121-
122-
Returns:
123-
True if value is a valid uint16, False otherwise
124-
"""
125-
return isinstance(var, int) and 0 <= var <= 0xFFFF
126-
98+
12799
# ========================================================================
128100
# Descriptor and Cluster Reading Utilities
129101
# ========================================================================
130102

131-
async def get_descriptor_server_list(self, ctrl: ChipDeviceCtrl, ep: int = None):
103+
async def get_descriptor_server_list(self, ctrl: ChipDeviceCtrl, ep: int = ROOT_NODE_ENDPOINT_ID):
132104
"""Read ServerList attribute from Descriptor cluster.
133105
134106
Args:
@@ -138,16 +110,14 @@ async def get_descriptor_server_list(self, ctrl: ChipDeviceCtrl, ep: int = None)
138110
Returns:
139111
ServerList attribute value
140112
"""
141-
if ep is None:
142-
ep = self.ROOT_NODE_ENDPOINT_ID
143113
return await self.read_single_attribute_check_success(
144114
endpoint=ep,
145115
dev_ctrl=ctrl,
146116
cluster=Clusters.Descriptor,
147117
attribute=Clusters.Descriptor.Attributes.ServerList
148118
)
149119

150-
async def get_descriptor_parts_list(self, ctrl: ChipDeviceCtrl, ep: int = None):
120+
async def get_descriptor_parts_list(self, ctrl: ChipDeviceCtrl, ep: int = ROOT_NODE_ENDPOINT_ID):
151121
"""Read PartsList attribute from Descriptor cluster.
152122
153123
Args:
@@ -157,16 +127,14 @@ async def get_descriptor_parts_list(self, ctrl: ChipDeviceCtrl, ep: int = None):
157127
Returns:
158128
PartsList attribute value
159129
"""
160-
if ep is None:
161-
ep = self.ROOT_NODE_ENDPOINT_ID
162130
return await self.read_single_attribute_check_success(
163131
endpoint=ep,
164132
dev_ctrl=ctrl,
165133
cluster=Clusters.Descriptor,
166134
attribute=Clusters.Descriptor.Attributes.PartsList
167135
)
168136

169-
async def get_idle_mode_duration_sec(self, ctrl: ChipDeviceCtrl, ep: int = None):
137+
async def get_idle_mode_duration_sec(self, ctrl: ChipDeviceCtrl, ep: int = ROOT_NODE_ENDPOINT_ID):
170138
"""Read IdleModeDuration attribute from ICD Management cluster.
171139
172140
Args:
@@ -176,8 +144,6 @@ async def get_idle_mode_duration_sec(self, ctrl: ChipDeviceCtrl, ep: int = None)
176144
Returns:
177145
IdleModeDuration attribute value in seconds
178146
"""
179-
if ep is None:
180-
ep = self.ROOT_NODE_ENDPOINT_ID
181147
return await self.read_single_attribute_check_success(
182148
endpoint=ep,
183149
dev_ctrl=ctrl,
@@ -189,7 +155,7 @@ async def get_idle_mode_duration_sec(self, ctrl: ChipDeviceCtrl, ep: int = None)
189155
# ACL Management Functions
190156
# ========================================================================
191157

192-
async def get_dut_acl(self, ctrl: ChipDeviceCtrl, ep: int = None):
158+
async def get_dut_acl(self, ctrl: ChipDeviceCtrl, ep: int = ROOT_NODE_ENDPOINT_ID):
193159
"""Read the ACL attribute from the DUT.
194160
195161
Args:
@@ -199,8 +165,6 @@ async def get_dut_acl(self, ctrl: ChipDeviceCtrl, ep: int = None):
199165
Returns:
200166
ACL list from the DUT
201167
"""
202-
if ep is None:
203-
ep = self.ROOT_NODE_ENDPOINT_ID
204168
sub = await ctrl.ReadAttribute(
205169
nodeid=self.dut_node_id,
206170
attributes=[(ep, Clusters.AccessControl.Attributes.Acl)],
@@ -210,16 +174,14 @@ async def get_dut_acl(self, ctrl: ChipDeviceCtrl, ep: int = None):
210174
acl_list = sub[ep][Clusters.AccessControl][Clusters.AccessControl.Attributes.Acl]
211175
return acl_list
212176

213-
async def write_dut_acl(self, ctrl: ChipDeviceCtrl, acl, ep: int = None):
177+
async def write_dut_acl(self, ctrl: ChipDeviceCtrl, acl, ep: int = ROOT_NODE_ENDPOINT_ID):
214178
"""Write an ACL to the DUT.
215179
216180
Args:
217181
ctrl: Controller to use for writing
218182
acl: ACL list to write
219183
ep: Endpoint to write to (default: ROOT_NODE_ENDPOINT_ID)
220184
"""
221-
if ep is None:
222-
ep = self.ROOT_NODE_ENDPOINT_ID
223185
result = await ctrl.WriteAttribute(self.dut_node_id, [(ep, Clusters.AccessControl.Attributes.Acl(acl))])
224186
asserts.assert_equal(result[ep].Status, Status.Success, "ACL write failed")
225187

@@ -240,7 +202,7 @@ async def add_ace_to_dut_acl(self, ctrl: ChipDeviceCtrl, ace, dut_acl_original):
240202
# ========================================================================
241203

242204
@staticmethod
243-
def get_typed_attribute_path(attribute, ep: int = None):
205+
def get_typed_attribute_path(attribute, ep: int = ROOT_NODE_ENDPOINT_ID):
244206
"""Create a TypedAttributePath from an attribute.
245207
246208
Args:
@@ -250,8 +212,6 @@ def get_typed_attribute_path(attribute, ep: int = None):
250212
Returns:
251213
TypedAttributePath object
252214
"""
253-
if ep is None:
254-
ep = IDMBaseTest.ROOT_NODE_ENDPOINT_ID
255215
return TypedAttributePath(
256216
Path=AttributePath.from_attribute(
257217
EndpointId=ep,
@@ -264,7 +224,7 @@ def get_typed_attribute_path(attribute, ep: int = None):
264224
# ========================================================================
265225

266226
@staticmethod
267-
def verify_attribute_exists(sub, cluster, attribute, ep: int = None):
227+
def verify_attribute_exists(sub, cluster, attribute, ep: int = ROOT_NODE_ENDPOINT_ID):
268228
"""Verify that an attribute exists in a subscription or read response.
269229
270230
Args:
@@ -273,8 +233,6 @@ def verify_attribute_exists(sub, cluster, attribute, ep: int = None):
273233
attribute: Attribute to check for
274234
ep: Endpoint to check (default: ROOT_NODE_ENDPOINT_ID)
275235
"""
276-
if ep is None:
277-
ep = IDMBaseTest.ROOT_NODE_ENDPOINT_ID
278236
sub_attrs = sub
279237
if isinstance(sub, Clusters.Attribute.SubscriptionTransaction):
280238
sub_attrs = sub.GetAttributes()

0 commit comments

Comments
 (0)