X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=smart_home%2Ftplink_utils.py;h=abf4970c3c9593f76b641114716fcff88a782627;hb=532df2c5b57c7517dfb3dddd8c1358fbadf8baf3;hp=053ce33b5499afbc505032d5060200f3b3e50d4b;hpb=4863b00af3b2ddcfaa2e5f47fd6dd7e95c1eb6c5;p=python_utils.git diff --git a/smart_home/tplink_utils.py b/smart_home/tplink_utils.py index 053ce33..abf4970 100644 --- a/smart_home/tplink_utils.py +++ b/smart_home/tplink_utils.py @@ -10,7 +10,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Modifications by Scott Gasch Copyright 2020-2022 also released under +Modifications by Scott Gasch Copyright © 2020-2022 also released under the Apache 2.0 license as required by the license (see above). Unless required by applicable law or agreed to in writing, software @@ -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)