forked from platypush/platypush
Fixed tests
This commit is contained in:
parent
d813356d9c
commit
b2c07a31f2
2 changed files with 8 additions and 4 deletions
|
@ -220,7 +220,7 @@ class Event(Message):
|
||||||
:param condition: The platypush.event.hook.EventCondition object
|
:param condition: The platypush.event.hook.EventCondition object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = EventMatchResult(is_match=False)
|
result = EventMatchResult(is_match=False, parsed_args=self.args)
|
||||||
match_scores = []
|
match_scores = []
|
||||||
|
|
||||||
if not isinstance(self, condition.type):
|
if not isinstance(self, condition.type):
|
||||||
|
|
|
@ -179,6 +179,7 @@ class SpeechRecognizedEvent(AssistantEvent):
|
||||||
result.score = sys.maxsize
|
result.score = sys.maxsize
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
parsed_args = {}
|
||||||
event_tokens = re.split(r'\s+', event_args.get(argname, '').strip().lower())
|
event_tokens = re.split(r'\s+', event_args.get(argname, '').strip().lower())
|
||||||
condition_tokens = re.split(r'\s+', condition_value.strip().lower())
|
condition_tokens = re.split(r'\s+', condition_value.strip().lower())
|
||||||
|
|
||||||
|
@ -201,11 +202,11 @@ class SpeechRecognizedEvent(AssistantEvent):
|
||||||
m = re.match(r'[^\\]*\${(.+?)}', condition_token)
|
m = re.match(r'[^\\]*\${(.+?)}', condition_token)
|
||||||
if m:
|
if m:
|
||||||
argname = m.group(1)
|
argname = m.group(1)
|
||||||
if argname not in result.parsed_args:
|
if argname not in parsed_args:
|
||||||
result.parsed_args[argname] = event_token
|
parsed_args[argname] = event_token
|
||||||
result.score += 1.0
|
result.score += 1.0
|
||||||
else:
|
else:
|
||||||
result.parsed_args[argname] += ' ' + event_token
|
parsed_args[argname] += ' ' + event_token
|
||||||
|
|
||||||
if (len(condition_tokens) == 1 and len(event_tokens) == 1) or (
|
if (len(condition_tokens) == 1 and len(event_tokens) == 1) or (
|
||||||
len(event_tokens) > 1
|
len(event_tokens) > 1
|
||||||
|
@ -223,6 +224,9 @@ class SpeechRecognizedEvent(AssistantEvent):
|
||||||
|
|
||||||
# It's a match if all the tokens in the condition string have been satisfied
|
# It's a match if all the tokens in the condition string have been satisfied
|
||||||
result.is_match = len(condition_tokens) == 0
|
result.is_match = len(condition_tokens) == 0
|
||||||
|
if result.is_match:
|
||||||
|
result.parsed_args = parsed_args
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue