projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Trie repr.
[python_utils.git]
/
light_utils.py
diff --git
a/light_utils.py
b/light_utils.py
index f63ba0b9b75193d2a076ed5fcfa9c015b65dc621..63379af9b83059dfec9b0200b6a554c6f4e9e3f8 100644
(file)
--- 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 argparse_utils
import config
-import logical_search
import logging_utils
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__)
from decorator_utils import timeout, memoized
logger = logging.getLogger(__name__)
@@
-118,21
+117,21
@@
class GoogleLight(Light):
return name.replace("_", " ")
@staticmethod
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(
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(
)
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:
)
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
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
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
if not r.success:
return None
@@
-161,7
+160,7
@@
class GoogleLight(Light):
return False
if 0 <= level <= 100:
was_on = self.is_on()
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:
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(
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:
self,
config_file: str = None,
) -> None:
+ import logical_search
if config_file is None:
config_file = config.config[
'light_utils_network_mac_addresses_location'
if config_file is None:
config_file = config.config[
'light_utils_network_mac_addresses_location'