rules: Device and Action rule conditions match on codename and name

This commit is contained in:
Peter F. Patel-Schneider 2025-09-21 13:13:07 -04:00
parent 62aaeac595
commit 94f4c3230b
3 changed files with 12 additions and 6 deletions

View File

@ -133,8 +133,9 @@ or the window's Window manager class or instance name starts with their string a
`Device` conditions are true if a particular device originated the notification. `Device` conditions are true if a particular device originated the notification.
`Active` conditions are true if a particular device is active. `Active` conditions are true if a particular device is active.
`Device` and `Active` conditions take one argument, which is the serial number or unit ID of a device, `Device` and `Active` conditions take one argument, which is the serial number or unit ID of a device,
as shown in Solaar's detail pane. as shown in Solaar's detail pane, or either of its names, as shown by Solaar.
Some older devices do not have a useful serial number or unit ID and so cannot be tested for by these conditions. Some older devices do not have a useful serial number or unit ID and so cannot
distinguished from other devices with the same names.
### Host ### Host
`Host` conditions are true if the computers hostname starts with the condition's argument. `Host` conditions are true if the computers hostname starts with the condition's argument.

View File

@ -207,10 +207,10 @@ class Device:
Device.instances.append(self) Device.instances.append(self)
def find(self, id): # find a device by serial number or unit ID def find(self, id): # find a device by serial number or unit ID or name or codename
assert id, "need serial number or unit ID to find a device" assert id, "need id to find a device"
for device in Device.instances: for device in Device.instances:
if device.online and (device.unitId == id or device.serial == id): if device.online and (device.unitId == id or device.serial == id or device.name == id or device.codename == id):
return device return device
@property @property

View File

@ -1118,7 +1118,12 @@ class Device(Condition):
def evaluate(self, feature, notification: HIDPPNotification, device, last_result): def evaluate(self, feature, notification: HIDPPNotification, device, last_result):
if logger.isEnabledFor(logging.DEBUG): if logger.isEnabledFor(logging.DEBUG):
logger.debug("evaluate condition: %s", self) logger.debug("evaluate condition: %s", self)
return device.unitId == self.devID or device.serial == self.devID return (
device.unitId == self.devID
or device.serial == self.devID
or device.codename == self.devID
or device.name == self.devID
)
def data(self): def data(self):
return {"Device": self.devID} return {"Device": self.devID}