Merge branch 'jmg5e-master'

This commit is contained in:
Tobias Witek 2017-06-26 19:11:18 +02:00
commit 62f60a172f
3 changed files with 35 additions and 11 deletions

View file

@ -91,7 +91,6 @@ Modules and commandline utilities are only required for modules, the core itself
# Required commandline utilities # Required commandline utilities
* xbacklight (for the module 'brightness')
* xset (for the module 'caffeine') * xset (for the module 'caffeine')
* notify-send (for the module 'caffeine') * notify-send (for the module 'caffeine')
* cmus-remote (for the module 'cmus') * cmus-remote (for the module 'cmus')

View file

@ -2,11 +2,9 @@
"""Displays the brightness of a display """Displays the brightness of a display
Requires the following executable:
* xbacklight
Parameters: Parameters:
* brightness.step: The amount of increase/decrease on scroll in % (defaults to 2) * brightness.step: The amount of increase/decrease on scroll in % (defaults to 2)
* brightness.device_path: The device path (defaults to /sys/class/backlight/intel_backlight)
""" """
@ -21,6 +19,7 @@ class Module(bumblebee.engine.Module):
) )
self._brightness = 0 self._brightness = 0
self._device_path = self.parameter("device_path", "/sys/class/backlight/intel_backlight")
step = self.parameter("step", 2) step = self.parameter("step", 2)
engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP,
@ -29,9 +28,19 @@ class Module(bumblebee.engine.Module):
cmd="xbacklight -{}%".format(step)) cmd="xbacklight -{}%".format(step))
def brightness(self, widget): def brightness(self, widget):
return "{:03.0f}%".format(self._brightness) if isinstance(self._brightness, float):
return "{:03.0f}%".format(self._brightness)
else:
return "n/a"
def update(self, widgets): def update(self, widgets):
self._brightness = float(bumblebee.util.execute("xbacklight -get")) try:
with open("{}/brightness".format(self._device_path)) as f:
backlight = int(f.readline())
with open("{}/max_brightness".format(self._device_path)) as f:
max_brightness = int(f.readline())
self._brightness=float(backlight*100/max_brightness)
except:
return "Error"
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -8,8 +8,14 @@ try:
except ImportError: except ImportError:
from io import StringIO from io import StringIO
try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError
import tests.mocks as mocks import tests.mocks as mocks
from bumblebee.config import Config
from bumblebee.input import WHEEL_UP, WHEEL_DOWN from bumblebee.input import WHEEL_UP, WHEEL_DOWN
from bumblebee.modules.brightness import Module from bumblebee.modules.brightness import Module
@ -20,9 +26,9 @@ class TestBrightnessModule(unittest.TestCase):
def tearDown(self): def tearDown(self):
mocks.teardown_test(self) mocks.teardown_test(self)
def test_format(self): # def test_format(self):
for widget in self.module.widgets(): # for widget in self.module.widgets():
self.assertEquals(len(widget.full_text()), len("100%")) # self.assertEquals(len(widget.full_text()), len("100%"))
def test_wheel_up(self): def test_wheel_up(self):
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module) mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module)
@ -38,10 +44,20 @@ class TestBrightnessModule(unittest.TestCase):
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module) mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module)
self.popen.assert_call("xbacklight -10%") self.popen.assert_call("xbacklight -10%")
def test_update(self): @mock.patch('bumblebee.modules.brightness.open', create=True)
self.popen.mock.communicate.return_value = ("20.0", None) def test_update(self, mock_open):
mock_open.side_effect = [
mock.mock_open(read_data="20").return_value,
mock.mock_open(read_data="100").return_value
]
self.module.update_all() self.module.update_all()
self.assertEquals(self.module.brightness(self.anyWidget), "020%") self.assertEquals(self.module.brightness(self.anyWidget), "020%")
self.assertEquals(len(self.module.brightness(self.anyWidget)), len("100%"))
@mock.patch('bumblebee.modules.brightness.open')
def test_error(self,mock_open):
mock_open.side_effect = FileNotFoundError
self.module.update_all()
self.assertEquals(self.module.brightness(self.anyWidget), "n/a")
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4