From 52cda61eeaee8d6575936c28348d0b095e9af830 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 5 May 2019 13:00:28 +0200 Subject: Add device not found and not paired exception --- parrot_zik/bluetooth_paired_devices.py | 20 +++++++++++++++++--- 1 file 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 -- cgit v1.2.1