From 11f86b75c8139055c10c6a5837a0fb757bd8c677 Mon Sep 17 00:00:00 2001 From: jmg5e Date: Mon, 26 Jun 2017 05:31:44 -0500 Subject: [PATCH 1/3] removed xbacklight dependency for brightness module --- README.md | 1 - bumblebee/modules/brightness.py | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fa6ac70..6054b4d 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,6 @@ Modules and commandline utilities are only required for modules, the core itself # Required commandline utilities -* xbacklight (for the module 'brightness') * xset (for the module 'caffeine') * notify-send (for the module 'caffeine') * cmus-remote (for the module 'cmus') diff --git a/bumblebee/modules/brightness.py b/bumblebee/modules/brightness.py index 716a734..e61be7e 100644 --- a/bumblebee/modules/brightness.py +++ b/bumblebee/modules/brightness.py @@ -2,11 +2,9 @@ """Displays the brightness of a display -Requires the following executable: - * xbacklight - Parameters: * 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._device_path = self.parameter("device_path", "/sys/class/backlight/intel_backlight") step = self.parameter("step", 2) engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, @@ -29,9 +28,19 @@ class Module(bumblebee.engine.Module): cmd="xbacklight -{}%".format(step)) 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): - 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 From fc912a8fbc72835f21032ee07ea6375f4ffd29cc Mon Sep 17 00:00:00 2001 From: jmg5e Date: Mon, 26 Jun 2017 06:07:19 -0500 Subject: [PATCH 2/3] fixed tests for brightness module --- tests/modules/test_brightness.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/modules/test_brightness.py b/tests/modules/test_brightness.py index b636d44..5582bcc 100644 --- a/tests/modules/test_brightness.py +++ b/tests/modules/test_brightness.py @@ -10,6 +10,7 @@ except ImportError: import tests.mocks as mocks +from bumblebee.config import Config from bumblebee.input import WHEEL_UP, WHEEL_DOWN from bumblebee.modules.brightness import Module @@ -20,9 +21,9 @@ class TestBrightnessModule(unittest.TestCase): def tearDown(self): mocks.teardown_test(self) - def test_format(self): - for widget in self.module.widgets(): - self.assertEquals(len(widget.full_text()), len("100%")) + # def test_format(self): + # for widget in self.module.widgets(): + # self.assertEquals(len(widget.full_text()), len("100%")) def test_wheel_up(self): mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module) @@ -38,10 +39,20 @@ class TestBrightnessModule(unittest.TestCase): mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module) self.popen.assert_call("xbacklight -10%") - def test_update(self): - self.popen.mock.communicate.return_value = ("20.0", None) + @mock.patch('bumblebee.modules.brightness.open', create=True) + 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.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 From d37218ce4a30d80dcdc48e150cfed0d2f974747a Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 26 Jun 2017 19:10:51 +0200 Subject: [PATCH 3/3] [tests/brightness] Fix FileNotFoundError for Python 2.7 --- tests/modules/test_brightness.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/modules/test_brightness.py b/tests/modules/test_brightness.py index 5582bcc..9b91d8f 100644 --- a/tests/modules/test_brightness.py +++ b/tests/modules/test_brightness.py @@ -8,6 +8,11 @@ try: except ImportError: from io import StringIO +try: + FileNotFoundError +except NameError: + FileNotFoundError = IOError + import tests.mocks as mocks from bumblebee.config import Config