diff options
| author | Ultrabug <ultrabug@ultrabug.net> | 2015-02-24 22:50:15 +0100 |
|---|---|---|
| committer | Ultrabug <ultrabug@ultrabug.net> | 2015-02-24 22:50:15 +0100 |
| commit | 42c486bdec6f453c3db6fff2f8a88e2ec5486bea (patch) | |
| tree | 35f7e5344d2688628b141fe13e50199d1c70597a /py3status | |
| parent | d9f8e7c164713f6815cd45bd4166f6cd5a03b8c3 (diff) | |
| parent | 602b99f314512552861c7d6f35fe46a5f4776f8e (diff) | |
Merge pull request #65 from jmdana/master
new bluetooth module by @jmdana
Diffstat (limited to 'py3status')
| -rw-r--r-- | py3status/modules/bluetooth.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py new file mode 100644 index 0000000..3585c4d --- /dev/null +++ b/py3status/modules/bluetooth.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +Module for displaying bluetooth status + +Requires: + - hcitool + +@author jmdana <https://github.com/jmdana> +@license GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt> +""" + +import re +import shlex +from subprocess import check_output +from time import time + +BTMAC_RE = re.compile(r"[0-9A-F:]{17}") + +class Py3status: + # configuration parameters + cache_timeout = 10 + color_good = None + color_bad = None + + def bluetooth(self, i3s_output_list, i3s_config): + # The whole command: + # hcitool name `hcitool con | sed -n -r 's/.*([0-9A-F:]{17}).*/\\1/p'` + + out = check_output(shlex.split("hcitool con")) + macs = re.findall(BTMAC_RE, out.decode("utf-8")) + output = "BT: " + color = self.color_bad or i3s_config['color_bad'] + + if macs != []: + names = [] + for mac in macs: + out = check_output(shlex.split("hcitool name %s" % mac)) + names.append(out.strip().decode("utf-8")) + + output += "|".join(names) + + color = self.color_good or i3s_config['color_good'] + else: + output += "OFF" + + response = { + 'cached_until': time() + self.cache_timeout, + 'full_text': output, + 'color': color, + } + + return response + +if __name__ == "__main__": + """ + Test this module by calling it directly. + """ + from time import sleep + x = Py3status() + config = { + "color_good": "#00FF00", + "color_bad": "#FF0000", + } + + while True: + print(x.bluetooth([], config)) + sleep(1) |
