diff --git a/platypush/backend/assistant/google.py b/platypush/backend/assistant/google.py index 1ac4075a..36f843c7 100644 --- a/platypush/backend/assistant/google.py +++ b/platypush/backend/assistant/google.py @@ -85,6 +85,7 @@ class AssistantGoogleBackend(AssistantBackend): self.credentials = None self.assistant = None self._has_error = False + self._is_muted = False self.logger.info('Initialized Google Assistant backend') @@ -140,8 +141,8 @@ class AssistantGoogleBackend(AssistantBackend): 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._is_muted = event.args.get('is_muted') + event = MicMutedEvent() if self._is_muted else MicUnmutedEvent() self.bus.post(event) def start_conversation(self): @@ -161,6 +162,9 @@ class AssistantGoogleBackend(AssistantBackend): self.assistant.set_mic_mute(muted) + def is_muted(self) -> bool: + return self._is_muted + def send_text_query(self, query): if not self.assistant: self.logger.warning('Assistant not running') diff --git a/platypush/plugins/assistant/google/__init__.py b/platypush/plugins/assistant/google/__init__.py index 8ad69b2d..9b5b3e35 100644 --- a/platypush/plugins/assistant/google/__init__.py +++ b/platypush/plugins/assistant/google/__init__.py @@ -47,6 +47,23 @@ class AssistantGooglePlugin(AssistantPlugin): assistant = self._get_assistant() assistant.set_mic_mute(muted) + @action + def toggle_mic_mute(self): + """ + Toggle the mic mute state. + """ + assistant = self._get_assistant() + is_muted = assistant.is_muted() + self.set_mic_mute(muted=not is_muted) + + @action + def is_muted(self) -> bool: + """ + :return: True if the microphone is muted, False otherwise. + """ + assistant = self._get_assistant() + return assistant.is_muted() + @action def send_text_query(self, query: str): """