From 124d2e356d3a094b39b7649ccf651015a54af837 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 5 Mar 2020 18:03:05 +0100 Subject: [PATCH] Support for mic muted/unmuted event in Google assistant --- platypush/backend/assistant/google.py | 10 +++++++++- platypush/message/event/assistant/__init__.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/platypush/backend/assistant/google.py b/platypush/backend/assistant/google.py index 04023de53..1ac4075aa 100644 --- a/platypush/backend/assistant/google.py +++ b/platypush/backend/assistant/google.py @@ -12,7 +12,7 @@ from platypush.message.event.assistant import \ ConversationStartEvent, ConversationEndEvent, ConversationTimeoutEvent, \ ResponseEvent, NoResponseEvent, SpeechRecognizedEvent, AlarmStartedEvent, \ AlarmEndEvent, TimerStartedEvent, TimerEndEvent, AlertStartedEvent, \ - AlertEndEvent + AlertEndEvent, MicMutedEvent, MicUnmutedEvent class AssistantGoogleBackend(AssistantBackend): @@ -50,6 +50,10 @@ class AssistantGoogleBackend(AssistantBackend): when a timer starts * :class:`platypush.message.event.assistant.TimerEndEvent` \ when a timer ends + * :class:`platypush.message.event.assistant.MicMutedEvent` \ + when the microphone is muted. + * :class:`platypush.message.event.assistant.MicUnmutedEvent` \ + when the microphone is un-muted. Requires: @@ -135,6 +139,10 @@ class AssistantGoogleBackend(AssistantBackend): self.logger.error('Fatal assistant error') else: self.logger.warning('Assistant error') + if event.type == EventType.ON_MUTED_CHANGED: + muted = event.args.get('is_muted') + event = MicMutedEvent() if muted else MicUnmutedEvent() + self.bus.post(event) def start_conversation(self): """ Starts an assistant conversation """ diff --git a/platypush/message/event/assistant/__init__.py b/platypush/message/event/assistant/__init__.py index 8b0affef0..44b1f1cba 100644 --- a/platypush/message/event/assistant/__init__.py +++ b/platypush/message/event/assistant/__init__.py @@ -184,4 +184,18 @@ class TimerEndEvent(AlertEndEvent): super().__init__(*args, **kwargs) +class MicMutedEvent(AssistantEvent): + """ + Event triggered when the microphone is muted. + """ + pass + + +class MicUnmutedEvent(AssistantEvent): + """ + Event triggered when the microphone is muted. + """ + pass + + # vim:sw=4:ts=4:et: