From 9d827d5d16d17030e95b55485297e87c0d4b76c2 Mon Sep 17 00:00:00 2001 From: smokeless Date: Thu, 12 Jul 2018 17:46:40 -0700 Subject: [PATCH] Added disconnect support for nmcli interfaces. --- wireless/Wireless.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wireless/Wireless.py b/wireless/Wireless.py index 9ae610f..dab4d91 100644 --- a/wireless/Wireless.py +++ b/wireless/Wireless.py @@ -88,6 +88,9 @@ def power(self, power=None): def driver(self): return self._driver_name + def disconnect(self): + return self._driver.disconnect() + # abstract class for all wireless drivers class WirelessDriver: @@ -113,6 +116,9 @@ def interface(self, interface=None): def power(self, power=None): pass + @abstractmethod + def disconnect(self): + pass # Linux nmcli Driver < 0.9.9.0 class NmcliWireless(WirelessDriver): @@ -164,6 +170,10 @@ def connect(self, ssid, password): # parse response return not self._errorInResponse(response) + def disconnect(self): + response = cmd('nmcli dev disconnect iface {}'.format(self._interface)) + return not self._errorInResponse(response) + # returned the ssid of the current network def current(self): # list active connections for all interfaces @@ -249,6 +259,10 @@ def _errorInResponse(self, response): # if we didn't find an error then we are in the clear return False + def disconnect(self): + response = cmd('nmcli dev disconnect iface {}'.format(self._interface)) + return not self._errorInResponse(response) + # connect to a network def connect(self, ssid, password): # clean up previous connection