Crozzers / screen_brightness_control

A Python tool for controlling the brightness of your monitor
https://crozzers.github.io/screen_brightness_control
MIT License
50 stars 9 forks source link

list_monitors_info() doesn't fully respect the defined method #21

Closed goldyfruit closed 1 year ago

goldyfruit commented 1 year ago

Hi,

When using list_monitors_info() with ddcutils as method, it seems that it's bypassed during the monitor detection.

With connected monitor to HDMI and default method.

>>> sbc.list_monitors_info()
[{'interface': 'HDMI-1', 'name': '\x00', 'method': <class 'screen_brightness_control.linux.XRandr'>, 'index': 0, 'model': 'Generic Monitor', 'serial': 'demoset-1\n 0', 'manufacturer': None, 'manufacturer_id': 'RTK', 'edid': '00ffffffffffff004a8b201901010101321d0103800000783eee91a3544c99260f5054230800d1c0b3009500810061404540814081c0023a801871382d40582c250058c31000001e000000fc00000a2020202020202020202020000000ff0064656d6f7365742d310a203020000000fd00383f545413000a2020202020200186'}]

With connected monitor to HDMI with ddcutil as method.

>>> sbc.list_monitors_info("ddcutil")
[{'interface': 'HDMI-1', 'name': '\x00', 'method': <class 'screen_brightness_control.linux.XRandr'>, 'index': 0, 'model': 'Generic Monitor', 'serial': 'demoset-1\n 0', 'manufacturer': None, 'manufacturer_id': 'RTK', 'edid': '00ffffffffffff004a8b201901010101321d0103800000783eee91a3544c99260f5054230800d1c0b3009500810061404540814081c0023a801871382d40582c250058c31000001e000000fc00000a2020202020202020202020000000ff0064656d6f7365742d310a203020000000fd00383f545413000a2020202020200186'}]

The method in the last one should not be <class 'screen_brightness_control.linux.XRandr' but <class 'screen_brightness_control.linux.DDCUtil' (I think).

Thanks for this library! :+1:

Crozzers commented 1 year ago

Good spot. Thank you!

The issue came about because list_monitors_info passes the monitors through filter_monitors to detect and remove duplicates. https://github.com/Crozzers/screen_brightness_control/blob/0c36c76f7a313856b46d1bbc76ea46b80da104eb/screen_brightness_control/linux.py#L1141-L1145 And filter_monitors would check if the haystack keyword arg had been passed in using the following check https://github.com/Crozzers/screen_brightness_control/blob/0c36c76f7a313856b46d1bbc76ea46b80da104eb/screen_brightness_control/__init__.py#L665-L666 Which would be False if the haystack kwarg had been passed in but was EMPTY (ie: no monitors detected using that method). filter_monitors would then fetch a list of monitors to filter, regardless of method.

I'll push a fix and publish something soonish

goldyfruit commented 1 year ago

Thanks for the fix, I'll wait until the PyPi release!

EDIT: Already released \o/