diff --git a/docs/rules.md b/docs/rules.md index 82bffb3d..8eeda69d 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -112,8 +112,9 @@ or the window's Window manager class or instance name starts with their string a `MouseProcess` conditions are true if the process for the window under the mouse or the window's Window manager class or instance name starts with their string argument. +`Device` conditions are true if a particular device originated the notification. `Active` conditions are true if a particular device is active. -`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. `Setting` conditions check the value of a Solaar setting on a device. diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index f2c1e24b..2437e91e 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -968,6 +968,28 @@ class Active(Condition): return {'Active': self.devID} +class Device(Condition): + + def __init__(self, devID, warn=True): + if not (isinstance(devID, str)): + if warn: + _log.warn('rule Device argument not a string: %s', devID) + self.devID = '' + self.devID = devID + + def __str__(self): + return 'Device: ' + str(self.devID) + + def evaluate(self, feature, notification, device, status, last_result): + if _log.isEnabledFor(_DEBUG): + _log.debug('evaluate condition: %s', self) + dev = _Device.find(self.devID) + return device == dev + + def data(self): + return {'Device': self.devID} + + class Action(RuleComponent): def __init__(self, *args): @@ -1265,6 +1287,7 @@ COMPONENTS = { 'TestBytes': TestBytes, 'MouseGesture': MouseGesture, 'Active': Active, + 'Device': Device, 'KeyPress': KeyPress, 'MouseScroll': MouseScroll, 'MouseClick': MouseClick,