@@ -67,69 +67,66 @@ async def test_TC_CNET_4_4(self):
67
67
asserts .assert_greater_equal (len (connected ), 1 , "Did not find any connected networks on a commissioned device" )
68
68
known_ssid = connected [0 ].networkID
69
69
70
- async def scan_and_check (scan_for_known_ssid : bool , breadcrumb : int ):
70
+ async def scan_and_check (ssid_to_scan : Optional [ bytes ] , breadcrumb : int , expect_results : bool = True ):
71
71
all_security = 0
72
72
for security_bitmask in cnet .Bitmaps .WiFiSecurityBitmap :
73
73
all_security |= security_bitmask
74
74
75
- if scan_for_known_ssid :
76
- ssid = known_ssid
77
- else :
78
- ssid = NullValue
75
+ ssid = ssid_to_scan if ssid_to_scan is not None else NullValue
79
76
cmd = cnet .Commands .ScanNetworks (ssid = ssid , breadcrumb = breadcrumb )
80
77
scan_results = await self .send_single_cmd (cmd = cmd )
81
78
asserts .assert_true (type_matches (scan_results , cnet .Commands .ScanNetworksResponse ),
82
79
"Unexpected value returned from scan network" )
83
- found_known_ssid = False
84
- for scan_result in scan_results :
85
- asserts .assert_equal (s .networkingStatus , cnet .Enums .NetworkCommissioningStatusEnum .kSuccess )
86
- if s .debugText :
87
- asserts .assert_less_equal (len (scan_result .debug_text ))
88
- asserts .assert_greater_equal (len (scan_result .wiFiScanResults ), 1 , "No responses returned from ScanNetwork command" )
89
- ssid_found = False
90
- for network in scan_result .wiFiScanResults :
91
- asserts .assert_true ((network .security & ~ all_security ) == 0 , "Unexpected bitmap in the security field" )
92
- asserts .assert_less_equal (len (network .ssid ), 32 , f"Returned SSID { network .ssid } is too long" )
93
- if network .ssid == known_ssid :
94
- found_known_ssid = True
95
- if scan_for_known_ssid :
96
- asserts .assert_equal (network .ssid , known_ssid , "Unexpected SSID returned in directed scan" )
97
- asserts .assert_true (type_matches (network .bssid , bytes ), "Incorrect type for BSSID" )
98
- asserts .assert_equal (len (network .bssid ), 6 , "Unexpected length of BSSID" )
99
- # TODO: this is inherited from the old test plan, but we should match the channel to the supported band. This range is unreasonably large.
100
- asserts .asserts_less_equal (len (network .channel ), 65535 , "Unexpected channel value" )
101
- if network .wiFiBand :
102
- asserts .assert_true (network .wiFiBand in supported_wifi_bands ,
103
- "Listed wiFiBand is not in supported_wifi_bands" )
104
- if network .rssi :
105
- asserts .assert_greater_equal (network .rssi , - 120 , "RSSI out of range" )
106
- asserts .assert_less_equal (network .rssi , 0 , "RSSI out of range" )
80
+ logging .info (f"Scan results: { scan_results } " )
81
+
82
+ if scan_results .debugText :
83
+ debug_text_len = len (scan_results .debug_text )
84
+ asserts .assert_less_equal (debug_text_len , 512 , f"DebugText length { debug_text_len } was out of range" )
85
+
86
+ if expect_results :
87
+ asserts .assert_equal (scan_results .networkingStatus , cnet .Enums .NetworkCommissioningStatusEnum .kSuccess ,
88
+ f"ScanNetworks was expected to have succeeded, got { scan_results .networkingStatus } instead" )
89
+ asserts .assert_greater_equal (len (scan_results .wiFiScanResults ), 1 , "No responses returned from ScanNetwork command" )
90
+ else :
91
+ asserts .assert_equal (scan_results .networkingStatus , cnet .Enums .NetworkCommissioningStatusEnum .kNetworkIDNotFound ,
92
+ f"ScanNetworks was expected to received NetworkNotFound, got { scan_results .networkingStatus } instead" )
93
+ return
94
+
95
+ for network in scan_results .wiFiScanResults :
96
+ asserts .assert_true ((network .security & ~ all_security ) == 0 , "Unexpected bitmap in the security field" )
97
+ asserts .assert_less_equal (len (network .ssid ), 32 , f"Returned SSID { network .ssid } is too long" )
98
+ if ssid_to_scan is not None :
99
+ asserts .assert_equal (network .ssid , ssid_to_scan , "Unexpected SSID returned in directed scan" )
100
+ asserts .assert_true (type_matches (network .bssid , bytes ), "Incorrect type for BSSID" )
101
+ asserts .assert_equal (len (network .bssid ), 6 , "Unexpected length of BSSID" )
102
+ # TODO: this is inherited from the old test plan, but we should match the channel to the supported band. This range is unreasonably large.
103
+ asserts .assert_less_equal (network .channel , 65535 , "Unexpected channel value" )
104
+ if network .wiFiBand :
105
+ asserts .assert_true (network .wiFiBand in supported_wifi_bands ,
106
+ "Listed wiFiBand is not in supported_wifi_bands" )
107
+ if network .rssi :
108
+ asserts .assert_greater_equal (network .rssi , - 120 , "RSSI out of range" )
109
+ asserts .assert_less_equal (network .rssi , 0 , "RSSI out of range" )
107
110
108
111
self .step (4 )
109
- await scan_and_check (scan_for_known_id = False , breadcrumb = 1 )
112
+ await scan_and_check (ssid_to_scan = None , breadcrumb = 1 )
110
113
111
114
self .step (5 )
112
115
breadcrumb = await self .read_single_attribute_check_success (cluster = Clusters .GeneralCommissioning , attribute = Clusters .GeneralCommissioning .Attributes .Breadcrumb , endpoint = 0 )
113
116
asserts .assert_equal (breadcrumb , 1 , "Incorrect breadcrumb value" )
114
117
115
118
self .step (6 )
116
- await scan_and_check (scan_for_known_ssid = True , breadcrumb = 2 )
119
+ await scan_and_check (ssid_to_scan = known_ssid , breadcrumb = 2 )
117
120
118
121
self .step (7 )
119
122
breadcrumb = await self .read_single_attribute_check_success (cluster = Clusters .GeneralCommissioning , attribute = Clusters .GeneralCommissioning .Attributes .Breadcrumb , endpoint = 0 )
120
123
asserts .assert_equal (breadcrumb , 2 , "Incorrect breadcrumb value" )
121
124
122
125
self .step (8 )
123
126
random_ssid = '' .join (random .choice (string .ascii_letters ) for _ in range (31 )).encode ("utf-8" )
124
- cmd = cnet .Commands .ScanNetworks (ssid = random_ssid , breadcrumb = 2 )
125
- scan_results = await self .send_single_cmd (cmd = cmd )
126
- asserts .assert_true (type_matches (scan_results , cnet .Commands .ScanNetworksResponse ),
127
- "Unexpected value returned from scan network" )
128
- asserts .assert_equal (s .networkingStatus , cnet .Enums .NetworkCommissioningStatusEnum .kNetworkNotFound )
127
+
128
+ await scan_and_check (ssid_to_scan = random_ssid , breadcrumb = 2 , expect_results = False )
129
129
130
130
131
131
if __name__ == "__main__" :
132
132
default_matter_test_main ()
133
- # The above code is likely importing or using a module or library called "ScanNet" in
134
- # Python. However, without more context or code, it is difficult to determine the exact
135
- # purpose or functionality of the code.
0 commit comments