Hook in pylint to the pre-commit hook and start to fix some of its
[python_utils.git] / google_assistant.py
index 75ca6432cf76b9f84506aa549855e5cec25e1844..b0aabf37095ef986b35b726d02700f55d017f78b 100644 (file)
@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 
 import logging
-from typing import NamedTuple
 import sys
 import warnings
+from typing import NamedTuple, Optional
 
 import requests
 import speech_recognition as sr  # type: ignore
@@ -36,7 +36,7 @@ class GoogleResponse(NamedTuple):
     success: bool
     response: str
     audio_url: str
-    audio_transcription: str
+    audio_transcription: Optional[str]  # None if not available.
 
     def __repr__(self):
         return f"""
@@ -67,9 +67,10 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
     success = False
     response = ""
     audio = ""
-    audio_transcription = ""
+    audio_transcription: Optional[str] = ""
     if r.status_code == 200:
         j = r.json()
+        logger.debug(j)
         success = bool(j["success"])
         response = j["response"] if success else j["error"]
         if success:
@@ -105,9 +106,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse:
             audio_transcription=audio_transcription,
         )
     else:
-        message = (
-            f'HTTP request to {url} with {payload} failed; code {r.status_code}'
-        )
+        message = f'HTTP request to {url} with {payload} failed; code {r.status_code}'
         logger.error(message)
         return GoogleResponse(
             success=False,