Source code for platypush.message.event.assistant

import logging

from platypush.context import get_backend, get_plugin
from platypush.message.event import Event


[docs]class AssistantEvent(Event): """ Base class for assistant events """
[docs] def __init__(self, assistant=None, *args, **kwargs): super().__init__(*args, **kwargs) self.logger = logging.getLogger('platypush:assistant') if assistant: self._assistant = assistant else: self._assistant = get_backend('assistant.google') if not self._assistant: self._assistant = get_plugin('assistant.google.pushtotalk') if not self._assistant: self.logger.warning('Assistant plugin/backend not configured/initialized') self._assistant = None
[docs]class ConversationStartEvent(AssistantEvent): """ Event triggered when a new conversation starts """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class ConversationEndEvent(AssistantEvent): """ Event triggered when a conversation ends """
[docs] def __init__(self, with_follow_on_turn=False, *args, **kwargs): """ :param with_follow_on_turn: Set to true if the conversation expects a user follow-up, false otherwise :type with_follow_on_turn: str """ super().__init__(*args, with_follow_on_turn=with_follow_on_turn, **kwargs)
[docs]class ConversationTimeoutEvent(ConversationEndEvent): """ Event triggered when a conversation times out """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class ResponseEvent(ConversationEndEvent): """ Event triggered when a response is processed by the assistant """
[docs] def __init__(self, response_text, *args, **kwargs): """ :param response_text: Response text processed by the assistant :type response_text: str """ super().__init__(*args, response_text=response_text, **kwargs)
[docs]class NoResponseEvent(ConversationEndEvent): """ Event triggered when a conversation ends with no response """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class SpeechRecognizedEvent(AssistantEvent): """ Event triggered when a speech is recognized """
[docs] def __init__(self, phrase, *args, **kwargs): """ :param phrase: Recognized user phrase :type phrase: str """ super().__init__(*args, phrase=phrase, **kwargs) self.recognized_phrase = phrase.strip().lower()
[docs] def matches_condition(self, condition): """ Overrides matches condition, and stops the conversation to prevent the default assistant response if the event matched some event hook condition """ result = super().matches_condition(condition) if result.is_match and self._assistant and 'phrase' in condition.args: self._assistant.stop_conversation() return result
[docs]class HotwordDetectedEvent(AssistantEvent): """ Event triggered when a custom hotword is detected """
[docs] def __init__(self, hotword=None, *args, **kwargs): """ :param hotword: The detected user hotword :type hotword: str """ super().__init__(*args, hotword=hotword, **kwargs)
[docs]class VolumeChangedEvent(AssistantEvent): """ Event triggered when the volume of the assistant changes """
[docs] def __init__(self, volume, *args, **kwargs): super().__init__(*args, volume=volume, **kwargs)
[docs]class AlertStartedEvent(AssistantEvent): """ Event triggered when an alert starts on the assistant """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class AlertEndEvent(AssistantEvent): """ Event triggered when an alert ends on the assistant """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class AlarmStartedEvent(AlertStartedEvent): """ Event triggered when an alarm starts on the assistant """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class AlarmEndEvent(AlertEndEvent): """ Event triggered when an alarm ends on the assistant """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class TimerStartedEvent(AlertStartedEvent): """ Event triggered when a timer starts on the assistant """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class TimerEndEvent(AlertEndEvent): """ Event triggered when a timer ends on the assistant """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
[docs]class MicMutedEvent(AssistantEvent): """ Event triggered when the microphone is muted. """ pass
[docs]class MicUnmutedEvent(AssistantEvent): """ Event triggered when the microphone is muted. """ pass
# vim:sw=4:ts=4:et: