More pylint fixes

This commit is contained in:
Fabio Manganiello 2018-07-30 23:18:01 +02:00
parent 81803a364d
commit ec38ecbaf3
5 changed files with 52 additions and 25 deletions

View File

@ -2,7 +2,7 @@
Platypush
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
.. license:: MIT
.. license: MIT
"""
import argparse

View File

@ -1,6 +1,6 @@
"""
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
.. license:: MIT
.. license: MIT
"""
import importlib

View File

@ -1,6 +1,6 @@
"""
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
.. license:: MIT
.. license: MIT
"""
import json
@ -28,12 +28,18 @@ class AssistantGoogleBackend(Backend):
Triggers:
* :class:`platypush.message.event.assistant.ConversationStartEvent` when a new conversation starts
* :class:`platypush.message.event.assistant.SpeechRecognizedEvent` when a new voice command is recognized
* :class:`platypush.message.event.assistant.NoResponse` when a conversation returned no response
* :class:`platypush.message.event.assistant.ResponseEvent` when the assistant is speaking a response
* :class:`platypush.message.event.assistant.ConversationTimeoutEvent` when a conversation times out
* :class:`platypush.message.event.assistant.ConversationEndEvent` when a new conversation ends
* :class:`platypush.message.event.assistant.ConversationStartEvent` \
when a new conversation starts
* :class:`platypush.message.event.assistant.SpeechRecognizedEvent` \
when a new voice command is recognized
* :class:`platypush.message.event.assistant.NoResponse` \
when a conversation returned no response
* :class:`platypush.message.event.assistant.ResponseEvent` \
when the assistant is speaking a response
* :class:`platypush.message.event.assistant.ConversationTimeoutEvent` \
when a conversation times out
* :class:`platypush.message.event.assistant.ConversationEndEvent` \
when a new conversation ends
Requires:
@ -47,10 +53,15 @@ class AssistantGoogleBackend(Backend):
'google-oauthlib-tool', 'credentials.json'),
device_model_id='Platypush', **kwargs):
"""
:param credentials_file: Path to the Google OAuth credentials file (default: ~/.config/google-oauthlib-tool/credentials.json). See https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample#generate_credentials for how to get your own credentials file.
:param credentials_file: Path to the Google OAuth credentials file \
(default: ~/.config/google-oauthlib-tool/credentials.json). \
See https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample#generate_credentials \
for instructions to get your own credentials file.
:type credentials_file: str
:param device_model_id: Device model ID to use for the assistant (default: Platypush)
:param device_model_id: Device model ID to use for the assistant \
(default: Platypush)
:type device_model_id: str
"""
@ -60,8 +71,10 @@ class AssistantGoogleBackend(Backend):
self.assistant = None
with open(self.credentials_file, 'r') as f:
self.credentials = google.oauth2.credentials.Credentials(token=None,
**json.load(f))
self.credentials = google.oauth2.credentials.Credentials(
token=None,
**json.load(f))
self.logger.info('Initialized Google Assistant backend')
def _process_event(self, event):
@ -76,7 +89,8 @@ class AssistantGoogleBackend(Backend):
self.bus.post(ConversationTimeoutEvent())
elif event.type == EventType.ON_NO_RESPONSE:
self.bus.post(NoResponseEvent())
elif hasattr(EventType, 'ON_RENDER_RESPONSE') and event.type == EventType.ON_RENDER_RESPONSE:
elif hasattr(EventType, 'ON_RENDER_RESPONSE') and \
event.type == EventType.ON_RENDER_RESPONSE:
self.bus.post(ResponseEvent(response_text=event.args.get('text')))
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
phrase = event.args['text'].lower().strip()

View File

@ -1,6 +1,6 @@
"""
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
.. license:: MIT
.. license: MIT
"""
import concurrent
@ -12,7 +12,8 @@ import grpc
import google.auth.transport.grpc
import google.auth.transport.requests
import google.oauth2.credentials
from google.assistant.embedded.v1alpha2 import embedded_assistant_pb2, embedded_assistant_pb2_grpc
from google.assistant.embedded.v1alpha2 import embedded_assistant_pb2, \
embedded_assistant_pb2_grpc
import googlesamples.assistant.grpc.audio_helpers as audio_helpers
import googlesamples.assistant.grpc.device_helpers as device_helpers
@ -36,9 +37,12 @@ class AssistantGooglePushtotalkBackend(Backend):
Triggers:
* :class:`platypush.message.event.assistant.ConversationStartEvent` when a new conversation starts
* :class:`platypush.message.event.assistant.SpeechRecognizedEvent` when a new voice command is recognized
* :class:`platypush.message.event.assistant.ConversationEndEvent` when a new conversation ends
* :class:`platypush.message.event.assistant.ConversationStartEvent` \
when a new conversation starts
* :class:`platypush.message.event.assistant.SpeechRecognizedEvent` \
when a new voice command is recognized
* :class:`platypush.message.event.assistant.ConversationEndEvent` \
when a new conversation ends
Requires:
@ -66,10 +70,16 @@ class AssistantGooglePushtotalkBackend(Backend):
conversation_start_fifo=os.path.join(os.path.sep, 'tmp', 'pushtotalk.fifo'),
**kwargs):
"""
:param credentials_file: Path to the Google OAuth credentials file (default: ~/.config/google-oauthlib-tool/credentials.json). See https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample#generate_credentials for how to get your own credentials file.
:param credentials_file: Path to the Google OAuth credentials file \
(default: ~/.config/google-oauthlib-tool/credentials.json). \
See https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample#generate_credentials \
for instructions to get your own credentials file.
:type credentials_file: str
:param device_config: Path to device_config.json. Register your device (see https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device) and create a project, then run the pushtotalk.py script from googlesamples to create your device_config.json
:param device_config: Path to device_config.json. Register your device \
(see https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device) \
and create a project, then run the pushtotalk.py script from \
googlesamples to create your device_config.json
:type device_config: str
:param lang: Assistant language (default: en-US)
@ -197,7 +207,8 @@ class SampleAssistant:
Args:
device_model_id: identifier of the device model.
device_id: identifier of the registered device instance.
conversation_stream(ConversationStream): audio stream for recording query and playing back assistant answer.
conversation_stream(ConversationStream): audio stream for recording \
query and playing back assistant answer.
channel: authorized gRPC channel for connection to the Google Assistant API.
deadline_sec: gRPC deadline in seconds for Google Assistant API call.
device_handler: callback for device actions.

View File

@ -1,6 +1,6 @@
"""
.. moduleauthor:: Fabio Manganiello <blacklight86@gmail.com>
.. license:: MIT
.. license: MIT
"""
import json
@ -24,7 +24,8 @@ class AssistantSnowboyBackend(Backend):
Triggers:
* :class:`platypush.message.event.assistant.HotwordDetectedEvent` whenever the hotword has been detected
* :class:`platypush.message.event.assistant.HotwordDetectedEvent` \
whenever the hotword has been detected
Requires:
@ -34,7 +35,8 @@ class AssistantSnowboyBackend(Backend):
def __init__(self, voice_model_file, hotword=None, sensitivity=0.5,
audio_gain=1.0, **kwargs):
"""
:param voice_model_file: Snowboy voice model file - see https://snowboy.kitt.ai/
:param voice_model_file: Snowboy voice model file - \
see https://snowboy.kitt.ai/
:type voice_model_file: str
:param hotword: Name of the hotword