[modules] add speed test module
This commit is contained in:
parent
e9b917c214
commit
72deb7eaf8
4 changed files with 59 additions and 4 deletions
52
bumblebee_status/modules/core/speedtest.py
Normal file
52
bumblebee_status/modules/core/speedtest.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Performs a speedtest - only updates when the "play" button is clicked
|
||||
|
||||
Requires the following python module:
|
||||
* speedtest-cli
|
||||
|
||||
"""
|
||||
|
||||
import core.module
|
||||
import core.widget
|
||||
import core.decorators
|
||||
|
||||
import speedtest
|
||||
|
||||
|
||||
class Module(core.module.Module):
|
||||
@core.decorators.never
|
||||
def __init__(self, config, theme):
|
||||
super().__init__(config, theme, [])
|
||||
|
||||
self.background = True
|
||||
self.__result = "waiting"
|
||||
self.__running = False
|
||||
|
||||
start = self.add_widget(name="start")
|
||||
main = self.add_widget(name="main", full_text=self.result)
|
||||
|
||||
def result(self, _):
|
||||
return self.__result
|
||||
|
||||
def update(self):
|
||||
self.__running = True
|
||||
s = speedtest.Speedtest()
|
||||
s.get_best_server()
|
||||
s.download(threads=None)
|
||||
s.upload(threads=None)
|
||||
|
||||
self.__result = "ping: {:.2f}ms down: {:.2f}Mbps up: {:.2f}Mbps".format(
|
||||
s.results.ping,
|
||||
s.results.download / 1024 / 1024,
|
||||
s.results.upload / 1024 / 1024,
|
||||
)
|
||||
self.__running = False
|
||||
|
||||
def state(self, widget):
|
||||
if widget.name == "start":
|
||||
return "running" if self.__running else "not-running"
|
||||
return None
|
||||
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue