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,48 +157,60 @@ class Event(Message):
|
|||
|
||||
return True
|
||||
|
||||
# pylint: disable=too-many-branches,too-many-return-statements
|
||||
def _matches_condition(
|
||||
self,
|
||||
condition: dict,
|
||||
args: dict,
|
||||
event_args: dict,
|
||||
result: "EventMatchResult",
|
||||
match_scores: list,
|
||||
) -> bool:
|
||||
for attr, value in condition.items():
|
||||
if attr not in args:
|
||||
for attr, condition_value in condition.items():
|
||||
if attr not in event_args:
|
||||
return False
|
||||
|
||||
if isinstance(args[attr], str):
|
||||
if self._is_relational_filter(value):
|
||||
if not self._relational_filter_matches(value, args[attr]):
|
||||
event_value = event_args[attr]
|
||||
if isinstance(event_value, str):
|
||||
if self._is_relational_filter(condition_value):
|
||||
if not self._relational_filter_matches(
|
||||
condition_value, event_value
|
||||
):
|
||||
return False
|
||||
else:
|
||||
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:
|
||||
match_scores.append(result.score)
|
||||
else:
|
||||
return False
|
||||
elif isinstance(value, dict):
|
||||
if self._is_relational_filter(value):
|
||||
if not self._relational_filter_matches(value, args[attr]):
|
||||
elif isinstance(condition_value, dict):
|
||||
if self._is_relational_filter(condition_value):
|
||||
if not self._relational_filter_matches(
|
||||
condition_value, event_value
|
||||
):
|
||||
return False
|
||||
else:
|
||||
if not isinstance(args[attr], dict):
|
||||
if not isinstance(event_value, dict):
|
||||
return False
|
||||
|
||||
if not self._matches_condition(
|
||||
condition=value,
|
||||
args=args[attr],
|
||||
condition=condition_value,
|
||||
event_args=event_value,
|
||||
result=result,
|
||||
match_scores=match_scores,
|
||||
):
|
||||
return False
|
||||
elif args[attr] != value:
|
||||
else:
|
||||
if event_value != condition_value:
|
||||
return False
|
||||
|
||||
match_scores.append(2.0)
|
||||
|
||||
return True
|
||||
|
||||
def matches_condition(self, condition):
|
||||
|
@ -215,7 +227,7 @@ class Event(Message):
|
|||
|
||||
if not self._matches_condition(
|
||||
condition=condition.args,
|
||||
args=self.args,
|
||||
event_args=self.args,
|
||||
result=result,
|
||||
match_scores=match_scores,
|
||||
):
|
||||
|
@ -228,7 +240,7 @@ class Event(Message):
|
|||
return result
|
||||
|
||||
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
|
||||
|
@ -236,7 +248,7 @@ class Event(Message):
|
|||
"""
|
||||
|
||||
# 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:
|
||||
result.score += 2
|
||||
else:
|
||||
|
|
|
@ -108,14 +108,14 @@ class SpeechRecognizedEvent(AssistantEvent):
|
|||
return result
|
||||
|
||||
@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
|
||||
phrase matches and text extraction.
|
||||
|
||||
Example::
|
||||
|
||||
args = {
|
||||
event_args = {
|
||||
'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
|
||||
result.is_match = True
|
||||
result.score = sys.maxsize
|
||||
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())
|
||||
|
||||
while event_tokens and condition_tokens:
|
||||
|
|
Loading…
Reference in a new issue