Fabian Peter Hammerle 5 years ago
commit
80571b57ed
3 changed files with 79 additions and 0 deletions
  1. 19 0
      LICENSE
  2. 43 0
      acpi_backlight/__init__.py
  3. 17 0
      setup.py

+ 19 - 0
LICENSE

@@ -0,0 +1,19 @@
+Copyright (c) 2018 Fabian Peter Hammerle
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 43 - 0
acpi_backlight/__init__.py

@@ -0,0 +1,43 @@
+# pylint: disable=missing-docstring
+
+import os
+
+_ACPI_BACKLIGHT_ROOT_DIR_PATH = '/sys/class/backlight'
+
+
+class Backlight:
+
+    def __init__(self, name='intel_backlight'):
+        self._acpi_dir_path = os.path.join(_ACPI_BACKLIGHT_ROOT_DIR_PATH, name)
+
+    @property
+    def _brightness_path(self):
+        return os.path.join(self._acpi_dir_path, 'brightness')
+
+    @property
+    def _max_brightness_path(self):
+        return os.path.join(self._acpi_dir_path, 'max_brightness')
+
+    @property
+    def _brightness_absolute(self):
+        with open(self._brightness_path, 'r') as brightness_file:
+            return int(brightness_file.read())
+
+    @_brightness_absolute.setter
+    def _brightness_absolute(self, brightness_absolute):
+        with open(self._brightness_path, 'w') as brightness_file:
+            return brightness_file.write(str(round(brightness_absolute)))
+
+    @property
+    def _max_brightness_absolute(self):
+        with open(self._max_brightness_path, 'r') as max_brightness_file:
+            return int(max_brightness_file.read())
+
+    @property
+    def brightness_relative(self):
+        return self._brightness_absolute / self._max_brightness_absolute
+
+    @brightness_relative.setter
+    def brightness_relative(self, brightness_relative):
+        self._brightness_absolute = max(0, min(1, brightness_relative)) \
+                                    * self._max_brightness_absolute

+ 17 - 0
setup.py

@@ -0,0 +1,17 @@
+""" python setup script """
+
+import setuptools
+
+setuptools.setup(
+    name='acpi-backlight',
+    use_scm_version=True,
+    author='Fabian Peter Hammerle',
+    author_email='fabian@hammerle.me',
+    packages=['acpi_backlight'],
+    setup_requires=['setuptools_scm'],
+    classifiers=[
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: POSIX :: Linux",
+        "Programming Language :: Python :: 3",
+    ],
+)