X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=light_utils.py;h=63379af9b83059dfec9b0200b6a554c6f4e9e3f8;hb=b10d30a46e601c9ee1f843241f2d69a1f90f7a94;hp=f63ba0b9b75193d2a076ed5fcfa9c015b65dc621;hpb=3bc4daf1edc121cd633429187392227f2fa61885;p=python_utils.git diff --git a/light_utils.py b/light_utils.py index f63ba0b..63379af 100644 --- a/light_utils.py +++ b/light_utils.py @@ -14,9 +14,8 @@ from typing import Dict, List, Optional, Set import argparse_utils import config -import logical_search import logging_utils -import google_assistant as goog +from google_assistant import ask_google, GoogleResponse from decorator_utils import timeout, memoized logger = logging.getLogger(__name__) @@ -118,21 +117,21 @@ class GoogleLight(Light): return name.replace("_", " ") @staticmethod - def parse_google_response(response: goog.GoogleResponse) -> bool: + def parse_google_response(response: GoogleResponse) -> bool: return response.success def turn_on(self) -> bool: return GoogleLight.parse_google_response( - goog.ask_google(f"turn {self.goog_name()} on") + ask_google(f"turn {self.goog_name()} on") ) def turn_off(self) -> bool: return GoogleLight.parse_google_response( - goog.ask_google(f"turn {self.goog_name()} off") + ask_google(f"turn {self.goog_name()} off") ) def is_on(self) -> bool: - r = goog.ask_google(f"is {self.goog_name()} on?") + r = ask_google(f"is {self.goog_name()} on?") if not r.success: return False return 'is on' in r.audio_transcription @@ -143,7 +142,7 @@ class GoogleLight(Light): def get_dimmer_level(self) -> Optional[int]: if not self.has_keyword("dimmer"): return False - r = goog.ask_google(f'how bright is {self.goog_name()}?') + r = ask_google(f'how bright is {self.goog_name()}?') if not r.success: return None @@ -161,7 +160,7 @@ class GoogleLight(Light): return False if 0 <= level <= 100: was_on = self.is_on() - r = goog.ask_google(f"set {self.goog_name()} to {level} percent") + r = ask_google(f"set {self.goog_name()} to {level} percent") if not r.success: return False if not was_on: @@ -171,7 +170,7 @@ class GoogleLight(Light): def make_color(self, color: str) -> bool: return GoogleLight.parse_google_response( - goog.ask_google(f"make {self.goog_name()} {color}") + ask_google(f"make {self.goog_name()} {color}") ) @@ -294,6 +293,7 @@ class LightingConfig(object): self, config_file: str = None, ) -> None: + import logical_search if config_file is None: config_file = config.config[ 'light_utils_network_mac_addresses_location'