| 1 |
''' |
| 2 |
Wifi Facade. |
| 3 |
============= |
| 4 |
|
| 5 |
The :class:`Wifi` is to provide access to the wifi of your mobile/ desktop |
| 6 |
devices. |
| 7 |
|
| 8 |
It currently supports `connecting`, `disconnecting`, `scanning`, `getting |
| 9 |
available wifi network list` and `getting network information`. |
| 10 |
|
| 11 |
Simple examples |
| 12 |
--------------- |
| 13 |
|
| 14 |
To enable/ turn on wifi scanning:: |
| 15 |
|
| 16 |
>>> from plyer import wifi |
| 17 |
>>> wifi.start_scanning() |
| 18 |
|
| 19 |
Once the wifi is enabled/ turned on, then this command starts to scan |
| 20 |
all the nearby available wifi networks. |
| 21 |
|
| 22 |
To get network info:: |
| 23 |
|
| 24 |
>>> from plyer import wifi |
| 25 |
>>> wifi.start_scanning() |
| 26 |
>>> return wifi.get_network_info(name) |
| 27 |
|
| 28 |
Returns network details of the network who's name/ssid is provided in the |
| 29 |
`name` parameter. |
| 30 |
|
| 31 |
To connect to a network:: |
| 32 |
|
| 33 |
>>> from plyer import wifi |
| 34 |
>>> wifi.start_scanning() |
| 35 |
>>> wifi.connect(network, parameters) |
| 36 |
|
| 37 |
This connects to the network who's name/ssid is provided under `network` |
| 38 |
parameter and along with other necessary methods for connection |
| 39 |
which depends upon platform to platform. |
| 40 |
|
| 41 |
please visit following files for more details about requirements of |
| 42 |
`paramaters` argument in `connect` method: |
| 43 |
|
| 44 |
plyer/platforms/win/wifi.py |
| 45 |
plyer/platforms/macosx/wifi.py |
| 46 |
plyer/platforms/win/wifi.py |
| 47 |
|
| 48 |
To disconnect from wifi:: |
| 49 |
|
| 50 |
>>> from plyer import wifi |
| 51 |
>>> wifi.disconnect() |
| 52 |
|
| 53 |
This disconnects your device from any wifi network. |
| 54 |
|
| 55 |
To get available wifi networks:: |
| 56 |
|
| 57 |
>>> from plyer import wifi |
| 58 |
>>> wifi.start_scanning() |
| 59 |
>>> return wifi.get_available_wifi() |
| 60 |
|
| 61 |
This returns all the available wifi networks near the device. |
| 62 |
|
| 63 |
Supported Platforms |
| 64 |
------------------- |
| 65 |
Windows, OS X, Linux |
| 66 |
|
| 67 |
Ex: 6 |
| 68 |
---------- |
| 69 |
|
| 70 |
from plyer import wifi |
| 71 |
wifi.enable() |
| 72 |
|
| 73 |
This enables wifi device. |
| 74 |
|
| 75 |
Ex: 7 |
| 76 |
---------- |
| 77 |
|
| 78 |
from plyer import wifi |
| 79 |
wifi.disable() |
| 80 |
|
| 81 |
This disable wifi device |
| 82 |
''' |
| 83 |
|
| 84 |
|
| 85 |
class Wifi: |
| 86 |
''' |
| 87 |
Wifi Facade. |
| 88 |
''' |
| 89 |
|
| 90 |
def is_enabled(self): |
| 91 |
''' |
| 92 |
Return enabled status of WiFi hardware. |
| 93 |
''' |
| 94 |
return self._is_enabled() |
| 95 |
|
| 96 |
def is_connected(self, interface=None): |
| 97 |
''' |
| 98 |
Return connection state of WiFi interface. |
| 99 |
|
| 100 |
.. versionadded:: 1.4.0 |
| 101 |
''' |
| 102 |
return self._is_connected(interface=interface) |
| 103 |
|
| 104 |
@property |
| 105 |
def interfaces(self): |
| 106 |
''' |
| 107 |
List all available WiFi interfaces. |
| 108 |
|
| 109 |
.. versionadded:: 1.4.0 |
| 110 |
''' |
| 111 |
|
| 112 |
raise NotImplementedError() |
| 113 |
|
| 114 |
def start_scanning(self, interface=None): |
| 115 |
''' |
| 116 |
Turn on scanning. |
| 117 |
''' |
| 118 |
return self._start_scanning(interface=interface) |
| 119 |
|
| 120 |
def get_network_info(self, name): |
| 121 |
''' |
| 122 |
Return a dictionary of specified network. |
| 123 |
''' |
| 124 |
return self._get_network_info(name=name) |
| 125 |
|
| 126 |
def get_available_wifi(self): |
| 127 |
''' |
| 128 |
Returns a list of all the available wifi. |
| 129 |
''' |
| 130 |
return self._get_available_wifi() |
| 131 |
|
| 132 |
def connect(self, network, parameters, interface=None): |
| 133 |
''' |
| 134 |
Method to connect to some network. |
| 135 |
''' |
| 136 |
self._connect( |
| 137 |
network=network, |
| 138 |
parameters=parameters, |
| 139 |
interface=interface |
| 140 |
) |
| 141 |
|
| 142 |
def disconnect(self, interface=None): |
| 143 |
''' |
| 144 |
To disconnect from some network. |
| 145 |
''' |
| 146 |
self._disconnect(interface=interface) |
| 147 |
|
| 148 |
def enable(self): |
| 149 |
''' |
| 150 |
Wifi interface power state is set to "ON". |
| 151 |
''' |
| 152 |
self._enable() |
| 153 |
|
| 154 |
def disable(self): |
| 155 |
''' |
| 156 |
Wifi interface power state is set to "OFF". |
| 157 |
''' |
| 158 |
self._disable() |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
def _is_enabled(self): |
| 163 |
raise NotImplementedError() |
| 164 |
|
| 165 |
def _is_connected(self, interface=None): |
| 166 |
raise NotImplementedError() |
| 167 |
|
| 168 |
def _start_scanning(self, interface=None): |
| 169 |
raise NotImplementedError() |
| 170 |
|
| 171 |
def _get_network_info(self, **kwargs): |
| 172 |
raise NotImplementedError() |
| 173 |
|
| 174 |
def _get_available_wifi(self): |
| 175 |
raise NotImplementedError() |
| 176 |
|
| 177 |
def _connect(self, **kwargs): |
| 178 |
raise NotImplementedError() |
| 179 |
|
| 180 |
def _disconnect(self, interface=None): |
| 181 |
raise NotImplementedError() |
| 182 |
|
| 183 |
def _enable(self): |
| 184 |
raise NotImplementedError() |
| 185 |
|
| 186 |
def _disable(self): |
| 187 |
raise NotImplementedError() |