summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-10-11 19:21:19 -0700
committerScott Gasch <[email protected]>2021-10-11 19:21:19 -0700
commit9484900f080e16f118806fe54973e69d36b043e8 (patch)
tree63ccd29bf087f90ceed97f0872d92ec167a95e6f
parenta5c4feeac240a446a38147130b51ad96a046f6e1 (diff)
Adds logging in light stuff, minor changes in config/string.
-rw-r--r--config.py2
-rw-r--r--light_utils.py4
-rw-r--r--string_utils.py6
3 files changed, 10 insertions, 2 deletions
diff --git a/config.py b/config.py
index fc19f3d..b6262ad 100644
--- a/config.py
+++ b/config.py
@@ -89,7 +89,7 @@ args = argparse.ArgumentParser(
description=None,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
fromfile_prefix_chars="@",
- epilog=f'------------------------------------------------------------------------------\n{program_name} uses config.py ({__file__}) for global, cross-module configuration setup and parsing.\n------------------------------------------------------------------------------'
+ epilog=f'{program_name} uses config.py ({__file__}) for global, cross-module configuration setup and parsing.'
)
# Keep track of if we've been called and prevent being called more
diff --git a/light_utils.py b/light_utils.py
index bd73ee3..8101a32 100644
--- a/light_utils.py
+++ b/light_utils.py
@@ -48,13 +48,16 @@ def tplink_light_command(command: str) -> bool:
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))
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))
return False
+ logger.debug(f'{command} succeeded.')
return True
@@ -212,6 +215,7 @@ class TPLinkLight(Light):
cmd = self.get_cmdline(child) + f"-c {cmd}"
if extra_args is not None:
cmd += f" {extra_args}"
+ logger.debug(f'About to execute {cmd}')
return tplink_light_command(cmd)
def turn_on(self, child: str = None) -> bool:
diff --git a/string_utils.py b/string_utils.py
index 623ae45..a6a2da3 100644
--- a/string_utils.py
+++ b/string_utils.py
@@ -1461,10 +1461,14 @@ def to_bitstring(txt: str, *, delimiter='', encoding='utf-8', errors='surrogatep
>>> to_bitstring('test', delimiter=' ')
'01110100 01100101 01110011 01110100'
+ >>> to_bitstring(b'test')
+ '01110100011001010111001101110100'
+
"""
+ etxt = to_ascii(txt)
bits = bin(
int.from_bytes(
- txt.encode(encoding, errors),
+ etxt,
'big'
)
)