X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=smart_home%2Flights.py;h=64f2105ffe8a4de0864e95a14d2b05703010a2bb;hb=f2b4fe83f6fc853a68653bd5e3d9fe0648c3d105;hp=e23569a69f60d35056faa1a795be536a3d103933;hpb=5f75cf834725ac26b289cc5f157af0cb71cd5f0e;p=python_utils.git diff --git a/smart_home/lights.py b/smart_home/lights.py index e23569a..64f2105 100644 --- 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: - 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: - 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 @@ -321,7 +323,7 @@ class TPLinkLight(BaseLight): self.info = self.get_info() if self.info is None: raise Exception('Unable to get info?') - return self.info.get("relay_state", "0") == "1" + return self.info.get("relay_state", 0) == 1 @overrides def is_off(self) -> bool: @@ -342,6 +344,7 @@ class TPLinkLight(BaseLight): 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: