Files
2025-05-23 01:55:25 +03:00

38 lines
976 B
Python

import monitorcontrol
BRIGHTNESS = 10
def get_monitors():
"""Retrieve a list of connected monitors."""
return monitorcontrol.get_monitors()
def set_brightness(monitor, brightness):
"""Set the brightness of a specific monitor."""
if not 0 <= brightness <= 100:
raise ValueError("Brightness must be between 0 and 100")
with monitor:
monitor.set_luminance(brightness)
print(f"Set brightness to {brightness}%")
def get_brightness(args):
global BRIGHTNESS
return {"value":BRIGHTNESS}
def change_brightness(args):
global BRIGHTNESS
try:
level = args.get('level', 10)
BRIGHTNESS = level
monitors = get_monitors()
if not monitors:
raise OSError(f"No DDC/CI compatible monitors found.")
return
for i, monitor in enumerate(monitors):
set_brightness(monitor, level)
except Exception as e:
raise OSError(f"An error occurred: {e}")