From 8b2c6d333ebc58312c487b71e588926f34574f65 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 13 Jul 2019 14:22:43 +0200 Subject: [PATCH] Lint warnings fixed --- .../backend/assistant/snowboy/__init__.py | 19 +++++++----- .../plugins/assistant/google/pushtotalk.py | 30 +++++++++---------- platypush/procedure/__init__.py | 1 + 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/platypush/backend/assistant/snowboy/__init__.py b/platypush/backend/assistant/snowboy/__init__.py index 1645d331ac..15912135bb 100644 --- a/platypush/backend/assistant/snowboy/__init__.py +++ b/platypush/backend/assistant/snowboy/__init__.py @@ -60,15 +60,19 @@ class AssistantSnowboyBackend(Backend): ok_google: # Hotword model name voice_model_file: /path/models/OK Google.pmdl # Voice model file location sensitivity: 0.5 # Model sensitivity, between 0 and 1 (default: 0.5) - assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google push-to-talk assistant plugin (optional) - assistant_language: en-US # The assistant will conversate in English when this hotword is detected (optional) + assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google + # push-to-talk assistant plugin (optional) + assistant_language: en-US # The assistant will conversate in English when this hotword is + detected (optional) detect_sound: /path/to/bell.wav # Sound file to be played when the hotword is detected (optional) ciao_google: # Hotword model name voice_model_file: /path/models/Ciao Google.pmdl # Voice model file location sensitivity: 0.5 # Model sensitivity, between 0 and 1 (default: 0.5) - assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google push-to-talk assistant plugin (optional) - assistant_language: it-IT # The assistant will conversate in Italian when this hotword is detected (optional) + assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google + # push-to-talk assistant plugin (optional) + assistant_language: it-IT # The assistant will conversate in Italian when this hotword is + # detected (optional) detect_sound: /path/to/bell.wav # Sound file to be played when the hotword is detected (optional) :type models: dict @@ -93,7 +97,8 @@ class AssistantSnowboyBackend(Backend): sensitivity=[model['sensitivity'] for model in self.models.values()], audio_gain=self.audio_gain) - self.logger.info('Initialized Snowboy hotword detection with {} voice model configurations'.format(len(self.models))) + self.logger.info('Initialized Snowboy hotword detection with {} voice model configurations'. + format(len(self.models))) def _init_models(self, models): if not models: @@ -117,7 +122,8 @@ class AssistantSnowboyBackend(Backend): detect_sound = os.path.abspath(os.path.expanduser(detect_sound)) if not os.path.isfile(model_file): - raise FileNotFoundError('Voice model file {} does not exist or it not a regular file'.format(model_file)) + raise FileNotFoundError('Voice model file {} does not exist or it not a regular file'. + format(model_file)) self.models[name] = { 'voice_model_file': model_file, @@ -136,7 +142,6 @@ class AssistantSnowboyBackend(Backend): except ImportError: import snowboy.snowboydecoder as snowboydecoder - def sound_thread(sound): snowboydecoder.play_audio_file(sound) diff --git a/platypush/plugins/assistant/google/pushtotalk.py b/platypush/plugins/assistant/google/pushtotalk.py index bbda8e8b2b..5f0d7ee8d6 100644 --- a/platypush/plugins/assistant/google/pushtotalk.py +++ b/platypush/plugins/assistant/google/pushtotalk.py @@ -3,13 +3,8 @@ """ import json -import logging import os -import google.auth.transport.grpc -import google.auth.transport.requests -import google.oauth2.credentials - import googlesamples.assistant.grpc.audio_helpers as audio_helpers import googlesamples.assistant.grpc.device_helpers as device_helpers @@ -22,6 +17,7 @@ from platypush.plugins import action from platypush.plugins.assistant import AssistantPlugin from platypush.plugins.assistant.google.lib import SampleAssistant + class AssistantGooglePushtotalkPlugin(AssistantPlugin): """ Plugin for the Google Assistant push-to-talk API. @@ -89,10 +85,12 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): # Load OAuth 2.0 credentials. try: + from google.oauth2.credentials import Credentials + from google.auth.transport.requests import Request + with open(self.credentials_file, 'r') as f: - self.credentials = google.oauth2.credentials.Credentials(token=None, - **json.load(f)) - self.http_request = google.auth.transport.requests.Request() + self.credentials = Credentials(token=None, **json.load(f)) + self.http_request = Request() self.credentials.refresh(self.http_request) except Exception as ex: self.logger.error('Error loading credentials: %s', str(ex)) @@ -105,12 +103,11 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): self.device_handler = None def _init_assistant(self): + from google.auth.transport.grpc import secure_authorized_channel self.interactions = [] # Create an authorized gRPC channel. - self.grpc_channel = google.auth.transport.grpc.secure_authorized_channel( - self.credentials, self.http_request, self.api_endpoint) - + self.grpc_channel = secure_authorized_channel(self.credentials, self.http_request, self.api_endpoint) self.logger.info('Connecting to {}'.format(self.api_endpoint)) # Configure audio source and sink. @@ -143,14 +140,16 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): self.device_handler = device_helpers.DeviceRequestHandler(self.device_id) - def on_conversation_start(self): + @staticmethod + def on_conversation_start(): """ Conversation start handler """ def handler(): get_bus().post(ConversationStartEvent()) return handler - def on_conversation_end(self): + @staticmethod + def on_conversation_end(): """ Conversation end handler """ def handler(with_follow_on_turn): get_bus().post(ConversationEndEvent(with_follow_on_turn=with_follow_on_turn)) @@ -165,7 +164,8 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): return handler - def on_volume_changed(self): + @staticmethod + def on_volume_changed(): """ Volume changed event """ def handler(volume): get_bus().post(VolumeChangedEvent(volume=volume)) @@ -192,7 +192,7 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin): return handler @action - def start_conversation(self, language=None): + def start_conversation(self, *args, language=None, **kwargs): """ Start a conversation diff --git a/platypush/procedure/__init__.py b/platypush/procedure/__init__.py index 0247b48036..b5ec9c4c78 100644 --- a/platypush/procedure/__init__.py +++ b/platypush/procedure/__init__.py @@ -38,6 +38,7 @@ class Procedure(object): if_count = 0 if_config = LifoQueue() procedure_class = procedure_class or cls + key = None for request_config in requests: # Check if this request is a for loop