summaryrefslogtreecommitdiff
path: root/light_utils.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-07-08 22:25:12 -0700
committerScott Gasch <[email protected]>2021-07-08 22:25:12 -0700
commit11eeb8574b7b4620ac6fd440cb251f8aa2458f5b (patch)
tree97f8e64eddd4528b01af58df269427814b889929 /light_utils.py
parente516059c716537259c601c022cc3bad44025385e (diff)
Reduce import scopes, remove cycles.
Diffstat (limited to 'light_utils.py')
-rw-r--r--light_utils.py18
1 files changed, 9 insertions, 9 deletions
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'