Skip to content

Commit

Permalink
Merge pull request softScheck#53 from leifnel/master
Browse files Browse the repository at this point in the history
Default to JSON output.
  • Loading branch information
softScheck authored May 7, 2020
2 parents 395c352 + 0070bb2 commit 02d66dc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tplink_smartplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def decrypt(string):
# Parse commandline arguments
parser = argparse.ArgumentParser(description="TP-Link Wi-Fi Smart Plug Client v" + str(version))
parser.add_argument("-t", "--target", metavar="<hostname>", required=True, help="Target hostname or IP address", type=validHostname)
parser.add_argument("-q", "--quiet", dest='quiet', action='store_true', help="Only show result")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-c", "--command", metavar="<command>", help="Preset command to send. Choices are: "+", ".join(commands), choices=commands)
group.add_argument("-j", "--json", metavar="<JSON string>", help="Full JSON string of command to send")
Expand All @@ -96,8 +97,14 @@ def decrypt(string):
data = sock_tcp.recv(2048)
sock_tcp.close()

print "Sent: ", cmd
print "Received: ", decrypt(data[4:])
decrypted = decrypt(data[4:])

if args.quiet:
print decrypted
else:
print "Sent: ", cmd
print "Received: ", decrypted

except socket.error:
quit("Cound not connect to host " + ip + ":" + str(port))

0 comments on commit 02d66dc

Please sign in to comment.