Set a plugin argument on AssistantEvents besides assistant.

`assistant` contains the assistant plugin object that triggered the
event, but you can't create event hook conditions on attributes that are
plugins.

The event should also store a `plugin` attribute which contains the
unique plugin name, so hooks like these can be built:

```
from platypush import hook
from platypush.events.assistant import ConversationStartEvent

@when(ConversationStartEvent, plugin="assistant.google")
def on_google_conversation_start():
  ...
```

It wouldn't be possible to construct a hook condition like the one above
on the plugin object reported on the `assistant` attribute.
This commit is contained in:
Fabio Manganiello 2024-05-31 19:29:50 +02:00
parent 23e02de1d7
commit 4513bb9569
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -19,14 +19,12 @@ class AssistantEvent(Event):
"""
assistant = assistant or kwargs.get('assistant')
if assistant:
assistant = (
kwargs['plugin'] = kwargs['_assistant'] = (
assistant
if isinstance(assistant, str)
else get_plugin_name_by_class(assistant.__class__)
)
kwargs['_assistant'] = assistant
super().__init__(*args, **kwargs)
@property