projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make sanity check optional.
[python_utils.git]
/
smart_home
/
lights.py
diff --git
a/smart_home/lights.py
b/smart_home/lights.py
index 1c4081c750fe9fb3d6ea2a472fb66240b7299f55..64f2105ffe8a4de0864e95a14d2b05703010a2bb 100644
(file)
--- a/
smart_home/lights.py
+++ b/
smart_home/lights.py
@@
-46,14
+46,16
@@
def tplink_light_command(command: str) -> bool:
result = os.system(command)
signal = result & 0xFF
if signal != 0:
result = os.system(command)
signal = result & 0xFF
if signal != 0:
- logger.warning(f'{command} died with signal {signal}')
- logging_utils.hlog("%s died with signal %d" % (command, signal))
+ msg = f'{command} died with signal {signal}'
+ logger.warning(msg)
+ logging_utils.hlog(msg)
return False
else:
exit_value = result >> 8
if exit_value != 0:
return False
else:
exit_value = result >> 8
if exit_value != 0:
- logger.warning(f'{command} failed, exited {exit_value}')
- logging_utils.hlog("%s failed, exit %d" % (command, exit_value))
+ msg = f'{command} failed, exited {exit_value}'
+ logger.warning(msg)
+ logging_utils.hlog(msg)
return False
logger.debug(f'{command} succeeded.')
return True
return False
logger.debug(f'{command} succeeded.')
return True
@@
-318,7
+320,10
@@
class TPLinkLight(BaseLight):
@overrides
def is_on(self) -> bool:
@overrides
def is_on(self) -> bool:
- return self.get_on_duration_seconds() > 0
+ self.info = self.get_info()
+ if self.info is None:
+ raise Exception('Unable to get info?')
+ return self.info.get("relay_state", 0) == 1
@overrides
def is_off(self) -> bool:
@overrides
def is_off(self) -> bool:
@@
-339,6
+344,7
@@
class TPLinkLight(BaseLight):
out = re.sub("Received: *", "", out)
try:
self.info = json.loads(out)["system"]["get_sysinfo"]
out = re.sub("Received: *", "", out)
try:
self.info = json.loads(out)["system"]["get_sysinfo"]
+ logger.debug(json.dumps(self.info, indent=4, sort_keys=True))
self.info_ts = datetime.datetime.now()
return self.info
except Exception as e:
self.info_ts = datetime.datetime.now()
return self.info
except Exception as e: