summaryrefslogtreecommitdiff
diff options
authorPMR <pmr@pmr-lander>2019-01-08 17:26:51 +0000
committerPMR <pmr@pmr-lander>2019-01-08 17:26:51 +0000
commit75b1e3702bee6bcb3782d833f35edf1c6a899075 (patch)
tree35c06c3d295bbae9b8f64ae8a2ac9cb58fe01f0c
parenta497f396944c52579db21f66075ac058f41386ff (diff)
parent34163f4435a46984f6193c676928fe842f139362 (diff)
Merge #361202 from ~jocave/plainbox-provider-checkbox:bluetooth-detect-job
-rwxr-xr-xbin/bt_list_adapters.py46
-rw-r--r--units/bluetooth/jobs.pxu13
-rw-r--r--units/bluetooth/manifest.pxu5
3 files changed, 64 insertions, 0 deletions
diff --git a/bin/bt_list_adapters.py b/bin/bt_list_adapters.py
new file mode 100755
index 0000000..e791442
--- /dev/null
+++ b/bin/bt_list_adapters.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+#
+# This file is part of Checkbox.
+#
+# Copyright 2018 Canonical Ltd.
+#
+# Authors:
+# Jonathan Cave <jonathan.cave@canonical.com>
+#
+# Checkbox is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3,
+# as published by the Free Software Foundation.
+#
+# Checkbox is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+
+def main():
+ rfkill = '/sys/class/rfkill'
+ found_adatper = False
+ for rfdev in os.listdir(rfkill):
+ typef = os.path.join(rfkill, rfdev, 'type')
+ type = ''
+ with open(typef, 'r') as f:
+ type = f.read().strip()
+ if type != 'bluetooth':
+ continue
+ found_adatper = True
+ namef = os.path.join(rfkill, rfdev, 'name')
+ name = ''
+ with open(namef, 'r') as f:
+ name = f.read().strip()
+ print(rfdev, name)
+ if found_adatper == False:
+ raise SystemExit('No bluetooth adatpers registered with rfkill')
+
+
+if __name__ == "__main__":
+ main()
diff --git a/units/bluetooth/jobs.pxu b/units/bluetooth/jobs.pxu
index 7ab5243..3b71e70 100644
--- a/units/bluetooth/jobs.pxu
+++ b/units/bluetooth/jobs.pxu
@@ -1,3 +1,16 @@
+unit: job
+id: bluetooth/detect
+category_id: com.canonical.plainbox::bluetooth
+_summary: Make sure at least one bluetooth device is detected
+plugin: shell
+command:
+ bt_list_adapters.py
+estimated_duration: 2s
+flags: preserve-locale
+requires: manifest.has_bt_adapter
+imports: from com.canonical.plainbox import manifest
+
+
plugin: shell
category_id: com.canonical.plainbox::bluetooth
id: bluetooth/detect-output
diff --git a/units/bluetooth/manifest.pxu b/units/bluetooth/manifest.pxu
index ebf5874..576f7a8 100644
--- a/units/bluetooth/manifest.pxu
+++ b/units/bluetooth/manifest.pxu
@@ -1,4 +1,9 @@
unit: manifest entry
+id: has_bt_adapter
+_name: A Bluetooth Adapter
+value-type: bool
+
+unit: manifest entry
id: has_bt_smart
_name: Bluetooth Smart (4.0 or later) Support
value-type: bool