aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-05 13:00:28 +0200
committerneodarz <neodarz@neodarz.net>2019-05-05 13:00:28 +0200
commit52cda61eeaee8d6575936c28348d0b095e9af830 (patch)
tree4627cbf1895aa2d893b6c3f1a7126a57fd74485e
parentef754651e828e246129f9b846b8323d24f0f6e00 (diff)
downloadpyParrotZikTCP-52cda61eeaee8d6575936c28348d0b095e9af830.tar.xz
pyParrotZikTCP-52cda61eeaee8d6575936c28348d0b095e9af830.zip
Add device not found and not paired exception
Diffstat (limited to '')
-rw-r--r--parrot_zik/bluetooth_paired_devices.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/parrot_zik/bluetooth_paired_devices.py b/parrot_zik/bluetooth_paired_devices.py
index edeb5f4..1618366 100644
--- a/parrot_zik/bluetooth_paired_devices.py
+++ b/parrot_zik/bluetooth_paired_devices.py
@@ -60,9 +60,14 @@ class BluezBluetoothDeviceManager(BluetoothDeviceManager):
except dbus.exceptions.DBusException:
pass
else:
- res = next(item for item in addresses if re.search(p, item["Address"]))
+ try:
+ res = next(item for item in addresses if re.search(p, item["Address"]))
+ except StopIteration:
+ raise DeviceNotFound
if res['Connected']:
return res['Address']
+ elif not res['Paired']:
+ raise DeviceNotPaired
else:
raise DeviceNotConnected
@@ -84,8 +89,10 @@ class BluetoothCmdDeviceManager(BluetoothDeviceManager):
def get_parrot_zik_mac_linux():
bluez_manager = BluezBluetoothDeviceManager()
try:
- bluez_manager.is_bluetooth_on()
- return bluez_manager.get_mac()
+ if bluez_manager.is_bluetooth_on():
+ return bluez_manager.get_mac()
+ else:
+ raise BluetoothIsNotOn
except OSError as e:
if e.errno == 2:
bluetoothcmd_manager = BluetoothCmdDeviceManager()
@@ -179,6 +186,13 @@ class DeviceNotConnected(Exception):
pass
+class DeviceNotPaired(Exception):
+ pass
+
+
+class DeviceNotFound(Exception):
+ pass
+
class ConnectionFailure(Exception):
pass