Rename a method, cleanup lint errors.
authorScott Gasch <[email protected]>
Sun, 27 Feb 2022 06:41:58 +0000 (22:41 -0800)
committerScott Gasch <[email protected]>
Sun, 27 Feb 2022 06:41:58 +0000 (22:41 -0800)
smart_home/lights.py
smart_home/outlets.py
smart_home/tplink_utils.py

index 9a5a2311ee516587e2515ae8e1c30be716c26e0d..2a0b1cd802f500eae7caa94d82d32dd283904403 100644 (file)
@@ -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):
index b9bfe22e694f7645df142c73335492aa41831b50..37655673550364f77c0e97c693058575bb4a9821 100644 (file)
@@ -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
index 053ce33b5499afbc505032d5060200f3b3e50d4b..30d3bd83e7a40d7cd1878b0ed0a2121b62fdfc97 100644 (file)
@@ -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)