From 4513bb9569e0a80dc5311b4a56aa565a3358d74b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 31 May 2024 19:29:50 +0200 Subject: [PATCH] Set a `plugin` argument on `AssistantEvent`s 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. --- platypush/message/event/assistant/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/platypush/message/event/assistant/__init__.py b/platypush/message/event/assistant/__init__.py index 942e2c1ea6..309cb910b7 100644 --- a/platypush/message/event/assistant/__init__.py +++ b/platypush/message/event/assistant/__init__.py @@ -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