mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-20 01:06:31 +00:00
AND_list (#18904)
This commit is contained in:
parent
5059a11b9f
commit
92ce18f87c
@ -118,6 +118,9 @@ class Rule_Matcher
|
|||||||
# <instance match="Payload">, <instance match_any>, <instance match="Temperature", <instance op='>' val='50'>
|
# <instance match="Payload">, <instance match_any>, <instance match="Temperature", <instance op='>' val='50'>
|
||||||
#
|
#
|
||||||
# Instance types:
|
# Instance types:
|
||||||
|
# Rule_Matcher_AND_List(key): checks that the input map matches with all contains individual conditions in the list
|
||||||
|
# returns an array of sub-value or `nil` if at least one doesn't match
|
||||||
|
#
|
||||||
# Rule_Matcher_Key(key): checks that the input map contains the key (case insensitive) and
|
# Rule_Matcher_Key(key): checks that the input map contains the key (case insensitive) and
|
||||||
# returns the sub-value or `nil` if the key does not exist
|
# returns the sub-value or `nil` if the key does not exist
|
||||||
#
|
#
|
||||||
@ -127,6 +130,33 @@ class Rule_Matcher
|
|||||||
# Rule_Matcher_Operator: checks is a simple value (numerical or string) matches the operator and the value
|
# Rule_Matcher_Operator: checks is a simple value (numerical or string) matches the operator and the value
|
||||||
# returns the value unchanged if match, or `nil` if no match
|
# returns the value unchanged if match, or `nil` if no match
|
||||||
|
|
||||||
|
|
||||||
|
# do a logical AND of all sub-matchers
|
||||||
|
static class Rule_Matcher_AND_List
|
||||||
|
var and_list
|
||||||
|
|
||||||
|
def init(and_list)
|
||||||
|
self.and_list = and_list
|
||||||
|
end
|
||||||
|
|
||||||
|
def match(val)
|
||||||
|
var idx = 0
|
||||||
|
var ret_list = []
|
||||||
|
while idx < size(self.and_list)
|
||||||
|
var rule = self.and_list[idx]
|
||||||
|
var ret = rule.match(val)
|
||||||
|
if ret == nil return nil end # abort as soon as a matcher fails
|
||||||
|
ret_list.push(ret)
|
||||||
|
idx += 1
|
||||||
|
end
|
||||||
|
return ret_list
|
||||||
|
end
|
||||||
|
|
||||||
|
def tostring()
|
||||||
|
return "<Matcher_AND_List " + str(self.and_list) + ">"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
static class Rule_Matcher_Key
|
static class Rule_Matcher_Key
|
||||||
var name # literal name of what to match
|
var name # literal name of what to match
|
||||||
|
|
||||||
@ -294,6 +324,18 @@ class Rule_Matcher
|
|||||||
import string
|
import string
|
||||||
if pattern == nil return nil end
|
if pattern == nil return nil end
|
||||||
|
|
||||||
|
# special case if a list of patterns, recursively make a list of matchers
|
||||||
|
if isinstance(pattern, list)
|
||||||
|
var and_list = []
|
||||||
|
var trigger_list = []
|
||||||
|
for p: pattern
|
||||||
|
var matcher = _class.parse(p)
|
||||||
|
and_list.push(matcher)
|
||||||
|
trigger_list.push(matcher.trigger)
|
||||||
|
end
|
||||||
|
return _class(pattern, trigger_list, [_class.Rule_Matcher_AND_List(and_list)])
|
||||||
|
end
|
||||||
|
|
||||||
var matchers = []
|
var matchers = []
|
||||||
|
|
||||||
# changes "Dimmer>50" to ['Dimmer', '>', '50']
|
# changes "Dimmer>50" to ['Dimmer', '>', '50']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user