aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-07-03 13:20:40 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-07-03 13:40:37 +0200
commit6eba736eb54ebecef14c4bd2b03df29b82f16f4b (patch)
tree91e403203a9b5bc9f1b84a69df6f5be11bfa7dfd /parrot_zik
parent0973bb1a2f8e46d7dffe67063f0d1415b3397619 (diff)
downloadpyParrotZikTCP-6eba736eb54ebecef14c4bd2b03df29b82f16f4b.tar.xz
pyParrotZikTCP-6eba736eb54ebecef14c4bd2b03df29b82f16f4b.zip
Fix mistakes and refactor.
Diffstat (limited to '')
-rw-r--r--parrot_zik/bluetooth_paired_devices.py33
1 files changed, 12 insertions, 21 deletions
diff --git a/parrot_zik/bluetooth_paired_devices.py b/parrot_zik/bluetooth_paired_devices.py
index 8eba2ce..0a40481 100644
--- a/parrot_zik/bluetooth_paired_devices.py
+++ b/parrot_zik/bluetooth_paired_devices.py
@@ -18,31 +18,24 @@ p = re.compile('90:03:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2
'A0:14:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}')
-def get_parrot_zik_mac_linux_using_bluez_test():
+def get_parrot_zik_mac_bluez():
+ pipe = Popen(['bluez-test-adapter', 'powered'], stdout=PIPE, stdin=PIPE,
+ stderr=STDOUT)
try:
- pipe = Popen(
- ['bluez-test-adapter', 'powered'],
- stdout=PIPE,
- stdin=PIPE,
- stderr=STDOUT
- )
- bluetooth_on = int(pipe.communicate())
+ stdout, stderr = pipe.communicate()
except dbus.exceptions.DBusException:
pass
else:
+ bluetooth_on = int(stdout)
if bluetooth_on == 1:
+ pipe = Popen(['bluez-test-device', 'list'], stdout=PIPE, stdin=PIPE,
+ stderr=STDOUT)
try:
- pipe = Popen(
- ['bluez-test-device', 'list'],
- stdout=PIPE,
- stdin=PIPE,
- stderr=STDOUT
- )
- out = pipe.communicate()
+ stdout, stderr = pipe.communicate()
except dbus.exceptions.DBusException:
pass
else:
- res = p.findall(out)
+ res = p.findall(stdout)
if len(res) > 0:
return res[0]
else:
@@ -51,7 +44,7 @@ def get_parrot_zik_mac_linux_using_bluez_test():
raise BluetoothIsNotOn
-def get_parrot_zik_mac_linux_using_bluetoothcmd():
+def get_parrot_zik_mac_bluetoothcmd():
pipe = Popen(['bluetoothctl'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
res = pipe.communicate("exit")
if len(res) > 0 and res[0]:
@@ -64,12 +57,10 @@ def get_parrot_zik_mac_linux_using_bluetoothcmd():
def get_parrot_zik_mac_linux():
try:
- get_parrot_zik_mac_linux_using_bluez_test()
+ return get_parrot_zik_mac_bluez()
except OSError as e:
if e.errno == 2:
- # File not found, probably it means that bluez utils are not
- # installed
- return get_parrot_zik_mac_linux_using_bluetoothcmd()
+ return get_parrot_zik_mac_bluetoothcmd()
def get_parrot_zik_mac_darwin():