diff options
| author | J.M. Dana <jmdana@gmail.com> | 2015-02-21 12:43:58 +0000 |
|---|---|---|
| committer | J.M. Dana <jmdana@gmail.com> | 2015-02-21 12:43:58 +0000 |
| commit | 2dee830be88dea42e92c445abec37d058a28ef1b (patch) | |
| tree | 3469c7c9f366f7770ec7c2ca4d43c5237002ab66 /py3status/modules/bluetooth.py | |
| parent | 151d108c57cc13ff7b140e78f746b1e6ba8e327c (diff) | |
New bluetooth module added
It shows the status of the bluetooth connection
Diffstat (limited to 'py3status/modules/bluetooth.py')
| -rw-r--r-- | py3status/modules/bluetooth.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py new file mode 100644 index 0000000..9840794 --- /dev/null +++ b/py3status/modules/bluetooth.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +Module for displaying bluetooth status + +Requires: + - hcitool + - sed + +@author jmdana <https://github.com/jmdana> +@license GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt> +""" + +from time import time +import subprocess +import shlex + +class Py3status: + # configuration parameters + cache_timeout = 10 + color_good = None + color_bad = None + + def __init__(self): + pass + + def kill(self, i3s_output_list, i3s_config): + pass + + def on_click(self, i3s_output_list, i3s_config, event): + pass + + def get_status(self, i3s_output_list, i3s_config): + # The whole command: + # hcitool name `hcitool con | sed -n -r 's/.*([0-9A-F:]{17}).*/\\1/p'` + + cmd1 = shlex.split("hcitool con") + cmd2 = shlex.split("sed -n -r 's/.*([0-9A-F:]{17}).*/\\1/p'") + output = "BT: " + color = self.color_bad or i3s_config['color_bad'] + + p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE) + p2 = subprocess.Popen(cmd2, stdin=p1.stdout, stdout=subprocess.PIPE) + + mac = p2.communicate()[0].strip().decode("utf-8") + + if mac != "": + cmd3 = shlex.split("hcitool name %s" % mac) + p3 = subprocess.Popen(cmd3, stdout=subprocess.PIPE) + output += p3.communicate()[0].strip().decode("utf-8") + 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.get_status([], config)) + sleep(1) |
