Skip to content

Commit

Permalink
bring uid back to life and make it the primary identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
BingoWon authored and Crozzers committed Oct 3, 2024
1 parent 6ec1f8b commit 164ed58
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions screen_brightness_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ def list_monitors_info(
print('Method:', display['method'])
# the EDID string associated with that display
print('EDID:', display['edid'])
# The connection_uid of the display.
# The UID of the display.
# On Windows, this identifier is derived from the InstanceName (WMI) or DeviceID (win32api),
# and represents the connection details (e.g., port, path) rather than the physical display itself.
# It changes if the display is connected to a different port or system.
print('connection_uid:', display['connection_uid'])
print('UID:', display['uid'])
```
'''
return _OS_MODULE.list_monitors_info(
Expand Down Expand Up @@ -350,6 +350,8 @@ class Display():
'''The method by which this monitor can be addressed.
This will be a class from either the windows or linux sub-module'''

uid: Optional[str] = None
"""'UID for the display connection, extracted from InstanceName (WMI) or DeviceID (win32api) on Windows."""
edid: Optional[str] = None
'''A 256 character hex string containing information about a display and its capabilities'''
manufacturer: Optional[str] = None
Expand All @@ -362,8 +364,6 @@ class Display():
'''The name of the display, often the manufacturer name plus the model name'''
serial: Optional[str] = None
'''The serial number of the display or (if serial is not available) an ID assigned by the OS'''
connection_uid: Optional[str] = None
"""'UID for the display connection, extracted from InstanceName (WMI) or DeviceID (win32api) on Windows."""

_logger: logging.Logger = field(init=False, repr=False)
_fade_thread_dict: ClassVar[Dict[FrozenSet[Tuple[Any, Any]], threading.Thread]] = {}
Expand Down Expand Up @@ -495,7 +495,7 @@ def from_dict(cls, display: dict) -> 'Display':
model=display['model'],
name=display['name'],
serial=display['serial'],
connection_uid=display.get('connection_uid')
uid=display.get('uid')
)

def get_brightness(self) -> IntPercentage:
Expand All @@ -511,14 +511,14 @@ def get_brightness(self) -> IntPercentage:
def get_identifier(self) -> Tuple[str, DisplayIdentifier]:
'''
Returns the `.types.DisplayIdentifier` for this display.
Will iterate through the EDID, serial, name, connection_uid and index and return the first
Will iterate through the UID, EDID, serial, name and index and return the first
value that is not equal to None
Returns:
The name of the property returned and the value of said property.
EG: `('serial', '123abc...')` or `('name', 'BenQ GL2450H')`
'''
for key in ('edid', 'serial', 'name', 'connection_uid'):
for key in ('uid', 'edid', 'serial', 'name'):
value = getattr(self, key, None)
if value is not None:
return key, value
Expand Down Expand Up @@ -637,7 +637,7 @@ def filter_monitor_list(to_filter):
# multiple monitors with the same identifier are allowed here, so return all of them
monitors = []
for monitor in to_filter:
for identifier in ['connection_uid', 'edid', 'serial', 'name'] + include:
for identifier in ['uid', 'edid', 'serial', 'name'] + include:
if display == monitor.get(identifier, None):
monitors.append(monitor)
break
Expand All @@ -647,7 +647,7 @@ def filter_monitor_list(to_filter):
for monitor in to_filter:
# find a valid identifier for a monitor, excluding any which are equal to None
added = False
for identifier in ['connection_uid', 'edid', 'serial', 'name'] + include:
for identifier in ['uid', 'edid', 'serial', 'name'] + include:
if monitor.get(identifier, None) is None:
continue

Expand Down
2 changes: 1 addition & 1 deletion screen_brightness_control/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
'''
Something that can be used to identify a particular display.
Can be any one of the following properties of a display:
- uid (str)
- edid (str)
- serial (str)
- name (str)
- connection_uid (str)
- index (int)
See `Display` for descriptions of each property and its type
Expand Down
2 changes: 1 addition & 1 deletion screen_brightness_control/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_display_info() -> List[dict]:
'manufacturer': manufacturer,
'manufacturer_id': man_id,
'edid': edid,
'connection_uid': match.group(1) if (match := re.search(r"UID(\d+)", instance_name)) else None,
'uid': uid_match.group(1) if (uid_match := re.search(r"UID(\d+)", instance_name)) else None,
}
if monitor.InstanceName in laptop_displays:
data['index'] = laptop
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/helpers_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_display_info(cls, display = None):
'serial': 'serial1',
'edid': '00ffffffffff00edid1',
'method': cls,
'connection_uid': '1000',
'uid': '1000',
'index': 0
}]

Expand Down
8 changes: 4 additions & 4 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ def test_returns_tuple(self, display: sbc.Display):
assert getattr(display, prop) == value
assert value is not None

@pytest.mark.parametrize('prop', ['edid', 'serial', 'name', 'connection_uid', 'index'])
@pytest.mark.parametrize('prop', ['uid', 'edid', 'serial', 'name', 'index'])
def test_returns_first_not_none_value(self, display: sbc.Display, prop: str):
all_props = ['edid', 'serial', 'name', 'connection_uid', 'index']
all_props = ['uid', 'edid', 'serial', 'name', 'index']
for p in all_props:
if p == prop:
continue
Expand All @@ -403,9 +403,9 @@ def test_allows_falsey_values(self, display: sbc.Display):
`get_identifier` should skip properties only if they are `None`.
It's very easy to do an `if truthy` check but that's not what we want here.
'''
display.edid = ''
display.uid = ''
prop, value = display.get_identifier()
assert prop == 'edid' and value == ''
assert prop == 'uid' and value == ''

def test_is_active(self, display: sbc.Display, mocker: MockerFixture):
# normal operation, should return true
Expand Down

0 comments on commit 164ed58

Please sign in to comment.