Skip to content

Commit 72bd0a7

Browse files
authored
Merge pull request #48 from ushiboy/develop
Develop
2 parents a9bba28 + 8a1bdaa commit 72bd0a7

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ nmcli.device.delete(ifname: str) -> None
232232
List available Wi-Fi access points.
233233

234234
```
235-
nmcli.device.wifi() -> List[DeviceWifi]
235+
nmcli.device.wifi(ifname: str = None) -> List[DeviceWifi]
236236
```
237237

238238
#### nmcli.device.wifi_connect
@@ -437,6 +437,10 @@ nmcli.set_lang(lang: str) -> None
437437

438438
## Change Log
439439

440+
### 0.9.0
441+
442+
Added ifname param to wifi.
443+
440444
### 0.8.0
441445

442446
Added support for changing the LANG environment variable.

nmcli/_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def delete(self, ifname: str) -> None:
133133

134134
def wifi(self, ifname: str = None) -> List[DeviceWifi]:
135135
cmd = ['-t', '-f', 'IN-USE,SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,SECURITY',
136-
'device', 'wifi', 'list']
136+
'device', 'wifi', 'list']
137137
if ifname is not None:
138138
cmd += ['ifname', ifname]
139139
r = self._syscmd.nmcli(cmd)

nmcli/dummy/_device.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def reapply_args(self):
2727
def delete_args(self):
2828
return self._delete_args
2929

30+
@property
31+
def wifi_args(self):
32+
return self._wifi_args
33+
3034
@property
3135
def wifi_connect_args(self):
3236
return self._wifi_connect_args
@@ -57,6 +61,7 @@ def __init__(self,
5761
self._disconnect_args: List[str] = []
5862
self._reapply_args: List[str] = []
5963
self._delete_args: List[str] = []
64+
self._wifi_args: List[str] = []
6065
self._wifi_connect_args: List[Tuple] = []
6166
self._wifi_hotspot_args: List[Tuple] = []
6267
self._wifi_rescan_args: List[Tuple] = []
@@ -96,8 +101,10 @@ def delete(self, ifname: str) -> None:
96101
self._raise_error_if_needed()
97102
self._delete_args.append(ifname)
98103

99-
def wifi(self) -> List[DeviceWifi]:
104+
def wifi(self, ifname: str = None) -> List[DeviceWifi]:
100105
self._raise_error_if_needed()
106+
if ifname is not None:
107+
self._wifi_args.append(ifname)
101108
return self._result_wifi
102109

103110
def wifi_connect(self, ssid: str, password: str, ifname: str = None) -> None:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def run_tests(self):
1313

1414
setup(
1515
name='nmcli',
16-
version='0.8.0',
16+
version='0.9.0',
1717
author='ushiboy',
1818
license='MIT',
1919
description='A python wrapper library for the network-manager cli client',

tests/dummy/test_device.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def test_wifi():
116116
result_wifi = [DeviceWifi(False, 'ssid', '00:00:00:00:00:00', 'Infra', 1, 2400, 54, 78, 'WPA2')]
117117
c = DummyDeviceControl(result_wifi=result_wifi)
118118
assert c.wifi() == result_wifi
119+
ifname = 'wlan0'
120+
assert c.wifi(ifname) == result_wifi
121+
assert c.wifi_args == [ifname]
119122

120123

121124
def test_wifi_when_raise_error():

tests/test_device.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,27 @@ def test_device_wifi():
165165
r = device.wifi()
166166
assert len(r) == 3
167167
assert r == [
168-
DeviceWifi(True, 'AP1', '00:00:00:00:00:00', 'Infra', 1, 2400, 130, 82, 'WPA1 WPA2'),
168+
DeviceWifi(True, 'AP1', '00:00:00:00:00:00', 'Infra', 1, 2400, 130, 82, 'WPA1 WPA2'),
169169
DeviceWifi(False, 'AP2', '00:00:00:00:00:01', 'Infra', 11, 2401, 195, 74, 'WPA2'),
170170
DeviceWifi(False, 'AP3', '00:00:00:00:00:02', 'Infra', 11, 2402, 195, 72, 'WPA1 WPA2'),
171171
]
172172
assert s.passed_parameters == ['-t', '-f', 'IN-USE,SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,SECURITY',
173-
'device', 'wifi']
173+
'device', 'wifi', 'list']
174174

175175
with open(device_wifi_data_file) as f:
176176
buf = f.read()
177-
device = DeviceControl(DummySystemCommand(buf))
178-
r = device.wifi()
177+
s2 = DummySystemCommand(buf)
178+
device = DeviceControl(s2)
179+
ifname = 'wlan0'
180+
r = device.wifi(ifname)
179181
assert len(r) == 3
180182
assert r == [
181183
DeviceWifi(False, '', '00:00:00:00:00:00', 'Infra', 11, 2400, 195, 72, 'WPA1 WPA2'),
182184
DeviceWifi(False, 'AP1', '00:00:00:00:00:01', 'Infra', 4, 2401, 130, 40, 'WPA1 WPA2'),
183185
DeviceWifi(False, 'AP2', '00:00:00:00:00:02', 'Infra', 6, 2402, 65, 24, 'WPA2'),
184186
]
187+
assert s2.passed_parameters == ['-t', '-f', 'IN-USE,SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,SECURITY',
188+
'device', 'wifi', 'list', 'ifname', ifname]
185189

186190

187191
def test_wifi_connect():

0 commit comments

Comments
 (0)