Closed shawnc722 closed 3 years ago
There will often be multiple devices with the same name (especially with RGB RAM), so I'd want this to return a list of devices, similar to the get_devices_by_type
function. Otherwise, it would only ever return the first device of a certain name.
I checked with my own setup and saw that all my names are unique (my RAM sticks are each zones of a shared device) and assumed it'd be that way for everyone. Updated the helper to make it "get_devices_by_name" so it returns a list, empty if there's no matches.
Do you think it's worth adding a boolean to control whether or not an exact match is needed? I'm imagining something like:
def get_devices_by_name(self, name : str, exact : bool=True):
if exact: return [device for device in self.devices if device.name == name]
return [device for device in self.devices if name in device.name]
This would give it a bit more functionality but the only use cases for it I can see right now are already covered by get_devices_by_type.
I like the idea, even if its only benefit is keeping me and other users from having to type in devices' full names. Also, maybe have the inexact version be case insensitive.
Alright finally had time to get to this, everything looking good to you?
Takes a string name, searches the devices for one matching that name, and returns that device. If given an invalid name, raises a ValueError.