diff options
author | neodarz <neodarz@neodarz.net> | 2019-05-05 13:00:28 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-05-05 13:00:28 +0200 |
commit | 52cda61eeaee8d6575936c28348d0b095e9af830 (patch) | |
tree | 4627cbf1895aa2d893b6c3f1a7126a57fd74485e /parrot_zik | |
parent | ef754651e828e246129f9b846b8323d24f0f6e00 (diff) | |
download | pyParrotZikTCP-52cda61eeaee8d6575936c28348d0b095e9af830.tar.xz pyParrotZikTCP-52cda61eeaee8d6575936c28348d0b095e9af830.zip |
Add device not found and not paired exception
Diffstat (limited to 'parrot_zik')
-rw-r--r-- | parrot_zik/bluetooth_paired_devices.py | 20 |
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 |