rules: add rule condition to test whether a device is active
This commit is contained in:
parent
f6764fcc87
commit
9f8882acd8
|
@ -579,7 +579,8 @@ class Report(Condition):
|
||||||
if warn:
|
if warn:
|
||||||
_log.warn('rule Report argument not an integer: %s', report)
|
_log.warn('rule Report argument not an integer: %s', report)
|
||||||
self.report = -1
|
self.report = -1
|
||||||
self.report = report
|
else:
|
||||||
|
self.report = report
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Report: ' + str(self.report)
|
return 'Report: ' + str(self.report)
|
||||||
|
@ -832,6 +833,25 @@ class MouseGesture(Condition):
|
||||||
return {'MouseGesture': [str(m) for m in self.movements]}
|
return {'MouseGesture': [str(m) for m in self.movements]}
|
||||||
|
|
||||||
|
|
||||||
|
class Active(Condition):
|
||||||
|
def __init__(self, devID, warn=True):
|
||||||
|
if not (isinstance(devID, str)):
|
||||||
|
if warn:
|
||||||
|
_log.warn('rule Active argument not a string: %s', devID)
|
||||||
|
self.devID = ''
|
||||||
|
self.devID = devID
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Active: ' + str(self.devID)
|
||||||
|
|
||||||
|
def evaluate(self, feature, notification, device, status, last_result):
|
||||||
|
dev = _Device.find(self.devID)
|
||||||
|
return bool(dev and dev.ping())
|
||||||
|
|
||||||
|
def data(self):
|
||||||
|
return {'Active': self.devID}
|
||||||
|
|
||||||
|
|
||||||
class Action(RuleComponent):
|
class Action(RuleComponent):
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
pass
|
pass
|
||||||
|
@ -1089,6 +1109,7 @@ COMPONENTS = {
|
||||||
'Test': Test,
|
'Test': Test,
|
||||||
'TestBytes': TestBytes,
|
'TestBytes': TestBytes,
|
||||||
'MouseGesture': MouseGesture,
|
'MouseGesture': MouseGesture,
|
||||||
|
'Active': Active,
|
||||||
'KeyPress': KeyPress,
|
'KeyPress': KeyPress,
|
||||||
'MouseScroll': MouseScroll,
|
'MouseScroll': MouseScroll,
|
||||||
'MouseClick': MouseClick,
|
'MouseClick': MouseClick,
|
||||||
|
|
Loading…
Reference in New Issue