Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python SDK - improve wifi SSID matching (#378) #413

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool:
discovered = False
while not discovered and (time.time() - start) <= timeout:
# Scan for network
response = cmd(f"{self.sudo} nmcli device wifi list")
response = cmd(f"{self.sudo} nmcli -f SSID device wifi list")
for result in response.splitlines()[1:]: # Skip title row
# Remove * in IN-USE column since it makes the SSID column non-determinant
if result.strip(" *").split()[1] == ssid:
if result.strip() == ssid.strip():
discovered = True
break
if discovered:
Expand Down Expand Up @@ -457,10 +456,9 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool:
while not discovered and (time.time() - start) <= timeout:
# Scan for network
cmd(f"{self.sudo} nmcli device wifi rescan")
response = cmd(f"{self.sudo} nmcli device wifi list")
response = cmd(f"{self.sudo} nmcli -f SSID device wifi list")
for result in response.splitlines()[1:]: # Skip title row
# Remove * in IN-USE column since it makes the SSID column non-determinant
if result.strip(" *").split()[1] == ssid:
if result.strip() == ssid.strip():
discovered = True
break
if discovered:
Expand Down Expand Up @@ -693,8 +691,12 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool:
response = cmd(
r"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --scan"
)
for result in response.splitlines()[1:]: # Skip title row
if result.split()[0] == ssid:
lines = response.splitlines()
ssid_end_index = lines[0].index("SSID") + 4 # Find where the SSID column ends

for result in lines[1:]: # Skip title row
current_ssid = result[:ssid_end_index].strip()
if current_ssid == ssid.strip():
discovered = True
break
if discovered:
Expand Down
Loading