aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik
diff options
context:
space:
mode:
Diffstat (limited to 'parrot_zik')
-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