__init__.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # pylint: disable=missing-docstring
  2. import os
  3. _ACPI_BACKLIGHT_ROOT_DIR_PATH = '/sys/class/backlight'
  4. class Backlight:
  5. def __init__(self, name='intel_backlight'):
  6. self._acpi_dir_path = os.path.join(_ACPI_BACKLIGHT_ROOT_DIR_PATH, name)
  7. @property
  8. def _brightness_path(self):
  9. return os.path.join(self._acpi_dir_path, 'brightness')
  10. @property
  11. def _max_brightness_path(self):
  12. return os.path.join(self._acpi_dir_path, 'max_brightness')
  13. @property
  14. def _brightness_absolute(self):
  15. with open(self._brightness_path, 'r') as brightness_file:
  16. return int(brightness_file.read())
  17. @_brightness_absolute.setter
  18. def _brightness_absolute(self, brightness_absolute):
  19. with open(self._brightness_path, 'w') as brightness_file:
  20. return brightness_file.write(str(round(brightness_absolute)))
  21. @property
  22. def _max_brightness_absolute(self):
  23. with open(self._max_brightness_path, 'r') as max_brightness_file:
  24. return int(max_brightness_file.read())
  25. @property
  26. def brightness_relative(self):
  27. return self._brightness_absolute / self._max_brightness_absolute
  28. @brightness_relative.setter
  29. def brightness_relative(self, brightness_relative):
  30. self._brightness_absolute = max(0, min(1, brightness_relative)) \
  31. * self._max_brightness_absolute