From 0e15af9e23bf05da3217b88987be30f8118526f0 Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Tue, 14 Jul 2020 13:30:52 +0200 Subject: bin:test_bt_keyboard -> test_bt_keyboard.py --- bin/test_bt_keyboard | 51 ------------------------------------------------ bin/test_bt_keyboard.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ units/bluetooth/jobs.pxu | 2 +- 3 files changed, 52 insertions(+), 52 deletions(-) delete mode 100755 bin/test_bt_keyboard create mode 100755 bin/test_bt_keyboard.py diff --git a/bin/test_bt_keyboard b/bin/test_bt_keyboard deleted file mode 100755 index 1457a1d..0000000 --- a/bin/test_bt_keyboard +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2016 Canonical Ltd. -# All rights reserved. -# -# Written by: -# Maciej Kisielewski - -import checkbox_support.bt_helper - - -def main(): - mgr = bt_helper.BtManager() - mgr.ensure_adapters_powered() - print('Make sure that the keyboard is turned on and is in pairable state.') - print('Then press ENTER') - input() - print('Scanning for devices...') - mgr.scan() - - keyboards = sorted(mgr.get_bt_devices( - category=bt_helper.BT_KEYBOARD, filters={'Paired': False}), - key=lambda x: int(x.rssi or -255), reverse=True) - if not keyboards: - print("No keyboards detected") - return - print('Detected keyboards (sorted by RSSI; highest first).') - # let's assing numbers to keyboards - keyboards = dict(enumerate(keyboards, 1)) - for num, kb in keyboards.items(): - print('{}. {} (RSSI: {})'.format(num, kb, kb.rssi)) - chosen = False - while not chosen: - print('Which one would you like to connect to? (0 to exit) ', - flush=True) - num = input() - if num == '0': - return - chosen = num.isnumeric() and int(num) in keyboards.keys() - kb = keyboards[int(num)] - print('{} chosen. Pairing...'.format(kb)) - kb.pair() - print(('Try typing on a keyboard. ' - 'Type "quit" and press ENTER to end the test.')) - while input().lower() != 'quit': - pass - print('Unpairing the keyboard...') - kb.unpair() - - -if __name__ == '__main__': - main() diff --git a/bin/test_bt_keyboard.py b/bin/test_bt_keyboard.py new file mode 100755 index 0000000..1457a1d --- /dev/null +++ b/bin/test_bt_keyboard.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# Copyright 2016 Canonical Ltd. +# All rights reserved. +# +# Written by: +# Maciej Kisielewski + +import checkbox_support.bt_helper + + +def main(): + mgr = bt_helper.BtManager() + mgr.ensure_adapters_powered() + print('Make sure that the keyboard is turned on and is in pairable state.') + print('Then press ENTER') + input() + print('Scanning for devices...') + mgr.scan() + + keyboards = sorted(mgr.get_bt_devices( + category=bt_helper.BT_KEYBOARD, filters={'Paired': False}), + key=lambda x: int(x.rssi or -255), reverse=True) + if not keyboards: + print("No keyboards detected") + return + print('Detected keyboards (sorted by RSSI; highest first).') + # let's assing numbers to keyboards + keyboards = dict(enumerate(keyboards, 1)) + for num, kb in keyboards.items(): + print('{}. {} (RSSI: {})'.format(num, kb, kb.rssi)) + chosen = False + while not chosen: + print('Which one would you like to connect to? (0 to exit) ', + flush=True) + num = input() + if num == '0': + return + chosen = num.isnumeric() and int(num) in keyboards.keys() + kb = keyboards[int(num)] + print('{} chosen. Pairing...'.format(kb)) + kb.pair() + print(('Try typing on a keyboard. ' + 'Type "quit" and press ENTER to end the test.')) + while input().lower() != 'quit': + pass + print('Unpairing the keyboard...') + kb.unpair() + + +if __name__ == '__main__': + main() diff --git a/units/bluetooth/jobs.pxu b/units/bluetooth/jobs.pxu index 8b9b405..7f4272a 100644 --- a/units/bluetooth/jobs.pxu +++ b/units/bluetooth/jobs.pxu @@ -351,7 +351,7 @@ _verification: plugin: user-verify user: root flags: also-after-suspend -command: test_bt_keyboard +command: test_bt_keyboard.py category_id: com.canonical.plainbox::bluetooth estimated_duration: 1m -- cgit v1.2.3