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:
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):
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:
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
@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:
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)
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)