forked from platypush/platypush
Fixed arguments naming.
This commit is contained in:
parent
38262e245e
commit
ff9b76477d
2 changed files with 34 additions and 22 deletions
|
@ -157,47 +157,59 @@ class Event(Message):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# pylint: disable=too-many-branches,too-many-return-statements
|
||||||
def _matches_condition(
|
def _matches_condition(
|
||||||
self,
|
self,
|
||||||
condition: dict,
|
condition: dict,
|
||||||
args: dict,
|
event_args: dict,
|
||||||
result: "EventMatchResult",
|
result: "EventMatchResult",
|
||||||
match_scores: list,
|
match_scores: list,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
for attr, value in condition.items():
|
for attr, condition_value in condition.items():
|
||||||
if attr not in args:
|
if attr not in event_args:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if isinstance(args[attr], str):
|
event_value = event_args[attr]
|
||||||
if self._is_relational_filter(value):
|
if isinstance(event_value, str):
|
||||||
if not self._relational_filter_matches(value, args[attr]):
|
if self._is_relational_filter(condition_value):
|
||||||
|
if not self._relational_filter_matches(
|
||||||
|
condition_value, event_value
|
||||||
|
):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self._matches_argument(
|
self._matches_argument(
|
||||||
argname=attr, condition_value=value, args=args, result=result
|
argname=attr,
|
||||||
|
condition_value=condition_value,
|
||||||
|
event_args=event_args,
|
||||||
|
result=result,
|
||||||
)
|
)
|
||||||
|
|
||||||
if result.is_match:
|
if result.is_match:
|
||||||
match_scores.append(result.score)
|
match_scores.append(result.score)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif isinstance(value, dict):
|
elif isinstance(condition_value, dict):
|
||||||
if self._is_relational_filter(value):
|
if self._is_relational_filter(condition_value):
|
||||||
if not self._relational_filter_matches(value, args[attr]):
|
if not self._relational_filter_matches(
|
||||||
|
condition_value, event_value
|
||||||
|
):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if not isinstance(args[attr], dict):
|
if not isinstance(event_value, dict):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not self._matches_condition(
|
if not self._matches_condition(
|
||||||
condition=value,
|
condition=condition_value,
|
||||||
args=args[attr],
|
event_args=event_value,
|
||||||
result=result,
|
result=result,
|
||||||
match_scores=match_scores,
|
match_scores=match_scores,
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
elif args[attr] != value:
|
else:
|
||||||
return False
|
if event_value != condition_value:
|
||||||
|
return False
|
||||||
|
|
||||||
|
match_scores.append(2.0)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -215,7 +227,7 @@ class Event(Message):
|
||||||
|
|
||||||
if not self._matches_condition(
|
if not self._matches_condition(
|
||||||
condition=condition.args,
|
condition=condition.args,
|
||||||
args=self.args,
|
event_args=self.args,
|
||||||
result=result,
|
result=result,
|
||||||
match_scores=match_scores,
|
match_scores=match_scores,
|
||||||
):
|
):
|
||||||
|
@ -228,7 +240,7 @@ class Event(Message):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _matches_argument(
|
def _matches_argument(
|
||||||
self, argname, condition_value, args, result: "EventMatchResult"
|
self, argname, condition_value, event_args, result: "EventMatchResult"
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Returns an EventMatchResult if the event argument [argname] matches
|
Returns an EventMatchResult if the event argument [argname] matches
|
||||||
|
@ -236,7 +248,7 @@ class Event(Message):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Simple equality match by default. It can be overridden by the derived classes.
|
# Simple equality match by default. It can be overridden by the derived classes.
|
||||||
result.is_match = args.get(argname) == condition_value
|
result.is_match = event_args.get(argname) == condition_value
|
||||||
if result.is_match:
|
if result.is_match:
|
||||||
result.score += 2
|
result.score += 2
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -108,14 +108,14 @@ class SpeechRecognizedEvent(AssistantEvent):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def _matches_argument(self, argname, condition_value, args, result):
|
def _matches_argument(self, argname, condition_value, event_args, result):
|
||||||
"""
|
"""
|
||||||
Overrides the default `_matches_argument` method to allow partial
|
Overrides the default `_matches_argument` method to allow partial
|
||||||
phrase matches and text extraction.
|
phrase matches and text extraction.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
args = {
|
event_args = {
|
||||||
'phrase': 'Hey dude turn on the living room lights'
|
'phrase': 'Hey dude turn on the living room lights'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,13 +127,13 @@ class SpeechRecognizedEvent(AssistantEvent):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if args.get(argname) == condition_value:
|
if event_args.get(argname) == condition_value:
|
||||||
# In case of an exact match, return immediately
|
# In case of an exact match, return immediately
|
||||||
result.is_match = True
|
result.is_match = True
|
||||||
result.score = sys.maxsize
|
result.score = sys.maxsize
|
||||||
return result
|
return result
|
||||||
|
|
||||||
event_tokens = re.split(r'\s+', 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())
|
||||||
|
|
||||||
while event_tokens and condition_tokens:
|
while event_tokens and condition_tokens:
|
||||||
|
|
Loading…
Reference in a new issue