From 7dd95b88a2a1a977506300f337e4b50a2df13141 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 26 Feb 2022 22:41:58 -0800 Subject: [PATCH] Rename a method, cleanup lint errors. --- smart_home/lights.py | 4 ++-- smart_home/outlets.py | 4 ++-- smart_home/tplink_utils.py | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/smart_home/lights.py b/smart_home/lights.py index 9a5a231..2a0b1cd 100644 --- a/smart_home/lights.py +++ b/smart_home/lights.py @@ -283,7 +283,7 @@ class TPLinkLight(BaseLight): if extra_args is not None: cmd += f" {extra_args}" logger.debug('About to execute: %s', cmd) - return tplink.tplink_command(cmd) + return tplink.tplink_command_wrapper(cmd) @overrides def turn_on(self) -> bool: @@ -365,7 +365,7 @@ class TPLinkLight(BaseLight): self.get_cmdline() + '-j \'{"smartlife.iot.dimmer":{"set_brightness":{"brightness":%d}}}\'' % level ) - return tplink.tplink_command(cmd) + return tplink.tplink_command_wrapper(cmd) # class GoogleLightGroup(GoogleLight): diff --git a/smart_home/outlets.py b/smart_home/outlets.py index b9bfe22..3765567 100644 --- a/smart_home/outlets.py +++ b/smart_home/outlets.py @@ -87,7 +87,7 @@ class TPLinkOutlet(BaseOutlet): cmd = self.get_cmdline() + f"-c {cmd}" if extra_args is not None: cmd += f" {extra_args}" - return tplink.tplink_command(cmd) + return tplink.tplink_command_wrapper(cmd) @overrides def turn_on(self) -> bool: @@ -152,7 +152,7 @@ class TPLinkOutletWithChildren(TPLinkOutlet): if extra_args is not None: cmd += f" {extra_args}" logger.debug('About to execute: %s', cmd) - return tplink.tplink_command(cmd) + return tplink.tplink_command_wrapper(cmd) def get_children(self) -> List[str]: return self.children diff --git a/smart_home/tplink_utils.py b/smart_home/tplink_utils.py index 053ce33..30d3bd8 100644 --- a/smart_home/tplink_utils.py +++ b/smart_home/tplink_utils.py @@ -54,7 +54,7 @@ commands = { @timeout(10.0, use_signals=False, error_message="Timed out waiting for tplink.py") -def tplink_command(command: str) -> bool: +def tplink_command_wrapper(command: str) -> bool: result = os.system(command) signal = result & 0xFF if signal != 0: @@ -166,7 +166,7 @@ def communicate_with_device( if not brief: raw = '' for b in encrypted_raw_request: - raw += '%02X ' % b + raw += f'{b:02X} ' logger.debug('Sent raw: "%s"', raw) # Note: 4 bytes of garbage (the key) @@ -176,14 +176,16 @@ def communicate_with_device( if not brief: raw = '' for b in raw_response: - raw += '%02X ' % b + raw += f'{b:02X} ' logger.debug('Received raw: "%s"', raw) - if '"err_code":0' not in decrypted_raw_response: - if '"err_code": 0' not in decrypted_raw_response: - logger.error("Did not see clean err_code in response?!") - return (False, all_responses) - logger.debug('All commands succeeded, returning True.') + if ( + '"err_code":0' not in decrypted_raw_response + and '"err_code": 0' not in decrypted_raw_response + ): + logger.error("Did not see clean err_code in response?!") + return (False, all_responses) + logger.debug('All commands succeeded.') return (True, all_responses) except socket.error: logger.error("Cound not connect to host %s:%s", ip, port) -- 2.47.1