Skip to content

Commit 2b020e0

Browse files
authored
Treat a Nullable attribute as raw type if it is not NullValue (project-chip#37182)
1 parent 080185d commit 2b020e0

File tree

2 files changed

+22
-49
lines changed

2 files changed

+22
-49
lines changed

src/python_testing/TC_DGWIFI_2_1.py

+20-46
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,17 @@ async def test_TC_DGWIFI_2_1(self):
131131
# If not NULL, we expect an integer in the SecurityType enum range.
132132
# Just do a minimal check here; you can refine or extend based on the spec.
133133
if security_type is not NullValue:
134-
security_type_value = security_type.Value
135-
matter_asserts.assert_valid_uint8(security_type_value, "SecurityType")
134+
matter_asserts.assert_valid_uint8(security_type, "SecurityType")
136135

137136
# Check if the security_type is a valid SecurityTypeEnum member
138-
self.assert_true(
139-
security_type_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum],
140-
f"SecurityType {security_type_value} is not a valid SecurityTypeEnum value"
141-
)
137+
matter_asserts.assert_valid_enum(security_type, "SecurityType",
138+
Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum)
142139

143140
# Additional check that it's not kUnknownEnumValue:
144141
self.assert_true(
145-
security_type_value != Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue.value,
142+
security_type != Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue,
146143
f"SecurityType should not be kUnknownEnumValue "
147-
f"({Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue.value})"
144+
f"({Clusters.Objects.WiFiNetworkDiagnostics.Enums.SecurityTypeEnum.kUnknownEnumValue})"
148145
)
149146

150147
#
@@ -154,16 +151,15 @@ async def test_TC_DGWIFI_2_1(self):
154151
wifi_version = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.WiFiVersion)
155152
# WiFiVersion is an enum. If not configured or operational, might be NULL.
156153
if wifi_version is not NullValue:
157-
wifi_version_value = wifi_version.Value
158-
matter_asserts.assert_valid_uint8(wifi_version_value, "WiFiVersion")
154+
matter_asserts.assert_valid_uint8(wifi_version, "WiFiVersion")
159155

160156
# Check if the wifi_version is a valid WiFiVersionEnum member
161-
self.assert_true(wifi_version_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum],
162-
f"WiFiVersion {wifi_version_value} is not a valid WiFiVersionEnum value")
157+
matter_asserts.assert_valid_enum(wifi_version, "WiFiVersion",
158+
Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum)
163159

164160
# Additional check that it's not kUnknownEnumValue:
165-
self.assert_true(wifi_version_value != Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue.value,
166-
f"WiFiVersion should not be kUnknownEnumValue ({Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue.value})")
161+
self.assert_true(wifi_version != Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue,
162+
f"WiFiVersion should not be kUnknownEnumValue ({Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum.kUnknownEnumValue})")
167163

168164
#
169165
# STEP 5: TH reads ChannelNumber attribute
@@ -172,7 +168,7 @@ async def test_TC_DGWIFI_2_1(self):
172168
channel_number = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.ChannelNumber)
173169
# If not operational, might be NULL. Else we expect an unsigned integer channel.
174170
if channel_number is not NullValue:
175-
matter_asserts.assert_valid_uint16(channel_number.Value, "ChannelNumber")
171+
matter_asserts.assert_valid_uint16(channel_number, "ChannelNumber")
176172

177173
#
178174
# STEP 6: TH reads RSSI attribute
@@ -181,8 +177,7 @@ async def test_TC_DGWIFI_2_1(self):
181177
rssi = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.Rssi)
182178
# RSSI is typically a signed integer (dB). If not operational, might be NULL.
183179
if rssi is not NullValue:
184-
rssi_value = rssi.Value
185-
asserts.assert_true(isinstance(rssi_value, int) and -120 <= rssi_value <= 0,
180+
asserts.assert_true(isinstance(rssi, int) and -120 <= rssi <= 0,
186181
"rssi_value is not within valid range.")
187182

188183
#
@@ -196,67 +191,52 @@ async def test_TC_DGWIFI_2_1(self):
196191
"BeaconLostCount must be of type 'Nullable' when not None.")
197192

198193
if beacon_lost_count is not NullValue:
199-
matter_asserts.assert_valid_uint32(beacon_lost_count.Value, "BeaconLostCount")
194+
matter_asserts.assert_valid_uint32(beacon_lost_count, "BeaconLostCount")
200195

201196
#
202197
# STEP 8: TH reads BeaconRxCount attribute
203198
#
204199
self.step(8)
205200
beacon_rx_count = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.BeaconRxCount)
206201
if beacon_rx_count is not None:
207-
asserts.assert_true(isinstance(beacon_rx_count, Nullable),
208-
"BeaconRxCount must be of type 'Nullable' when not None.")
209-
210202
if beacon_rx_count is not NullValue:
211-
matter_asserts.assert_valid_uint32(beacon_rx_count.Value, "BeaconRxCount")
203+
matter_asserts.assert_valid_uint32(beacon_rx_count, "BeaconRxCount")
212204

213205
#
214206
# STEP 9: TH reads PacketMulticastRxCount attribute
215207
#
216208
self.step(9)
217209
pkt_multi_rx = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.PacketMulticastRxCount)
218210
if pkt_multi_rx is not None:
219-
asserts.assert_true(isinstance(pkt_multi_rx, Nullable),
220-
"PacketMulticastRxCount must be of type 'Nullable' when not None.")
221-
222211
if pkt_multi_rx is not NullValue:
223-
matter_asserts.assert_valid_uint32(pkt_multi_rx.Value, "PacketMulticastRxCount")
212+
matter_asserts.assert_valid_uint32(pkt_multi_rx, "PacketMulticastRxCount")
224213

225214
#
226215
# STEP 10: TH reads PacketMulticastTxCount attribute
227216
#
228217
self.step(10)
229218
pkt_multi_tx = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.PacketMulticastTxCount)
230219
if pkt_multi_tx is not None:
231-
asserts.assert_true(isinstance(pkt_multi_tx, Nullable),
232-
"PacketMulticastTxCount must be of type 'Nullable' when not None.")
233-
234220
if pkt_multi_tx is not NullValue:
235-
matter_asserts.assert_valid_uint32(pkt_multi_tx.Value, "PacketMulticastTxCount")
221+
matter_asserts.assert_valid_uint32(pkt_multi_tx, "PacketMulticastTxCount")
236222

237223
#
238224
# STEP 11: TH reads PacketUnicastRxCount attribute
239225
#
240226
self.step(11)
241227
pkt_uni_rx = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.PacketUnicastRxCount)
242228
if pkt_uni_rx is not None:
243-
asserts.assert_true(isinstance(pkt_uni_rx, Nullable),
244-
"PacketUnicastRxCount must be of type 'Nullable' when not None.")
245-
246229
if pkt_uni_rx is not NullValue:
247-
matter_asserts.assert_valid_uint32(pkt_uni_rx.Value, "PacketUnicastRxCount")
230+
matter_asserts.assert_valid_uint32(pkt_uni_rx, "PacketUnicastRxCount")
248231

249232
#
250233
# STEP 12: TH reads PacketUnicastTxCount attribute
251234
#
252235
self.step(12)
253236
pkt_uni_tx = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.PacketUnicastTxCount)
254237
if pkt_uni_tx is not None:
255-
asserts.assert_true(isinstance(pkt_uni_tx, Nullable),
256-
"PacketUnicastTxCount must be of type 'Nullable' when not None.")
257-
258238
if pkt_uni_tx is not NullValue:
259-
matter_asserts.assert_valid_uint32(pkt_uni_tx.Value, "PacketUnicastTxCount")
239+
matter_asserts.assert_valid_uint32(pkt_uni_tx, "PacketUnicastTxCount")
260240

261241
#
262242
# STEP 13: TH reads CurrentMaxRate attribute
@@ -265,11 +245,8 @@ async def test_TC_DGWIFI_2_1(self):
265245
current_max_rate = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentMaxRate)
266246
# According to the spec, this is bytes per second (uint).
267247
if current_max_rate is not None:
268-
asserts.assert_true(isinstance(current_max_rate, Nullable),
269-
"CurrentMaxRate must be of type 'Nullable' when not None.")
270-
271248
if current_max_rate is not NullValue:
272-
matter_asserts.assert_valid_uint64(current_max_rate.Value, "CurrentMaxRate")
249+
matter_asserts.assert_valid_uint64(current_max_rate, "CurrentMaxRate")
273250

274251
#
275252
# STEP 14: TH reads OverrunCount attribute
@@ -278,11 +255,8 @@ async def test_TC_DGWIFI_2_1(self):
278255
overrun_count = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.OverrunCount)
279256
# This is a uint and may reset to 0 after node reboot.
280257
if overrun_count is not None:
281-
asserts.assert_true(isinstance(overrun_count, Nullable),
282-
"OverrunCount must be of type 'Nullable' when not None.")
283-
284258
if overrun_count is not NullValue:
285-
matter_asserts.assert_valid_uint64(overrun_count.Value, "OverrunCount")
259+
matter_asserts.assert_valid_uint64(overrun_count, "OverrunCount")
286260

287261

288262
if __name__ == "__main__":

src/python_testing/TC_DGWIFI_2_3.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#
3434

3535
import chip.clusters as Clusters
36-
from chip.clusters.Types import Nullable, NullValue
36+
from chip.clusters.Types import NullValue
3737
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
3838
from mobly import asserts
3939

@@ -60,10 +60,9 @@ async def read_attribute_and_validate(self, endpoint, attribute, validation_func
6060
value = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=Clusters.Objects.WiFiNetworkDiagnostics, attribute=attribute)
6161
if value is None:
6262
return
63-
asserts.assert_true(isinstance(value, Nullable), f"{field_name} must be of type 'Nullable' when not None.")
6463
if value == NullValue:
6564
return
66-
asserts.assert_true(validation_func(value.Value), f"{field_name} has an invalid value: {value.Value}")
65+
asserts.assert_true(validation_func(value), f"{field_name} has an invalid value: {value}")
6766

6867
def desc_TC_DGWIFI_2_3(self) -> str:
6968
"""Returns a description of this test."""

0 commit comments

Comments
 (0)