mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
Merge pull request #3796 from curzon01/development
Add login parms for tools/decode-status.py
This commit is contained in:
commit
eae76daa76
@ -28,12 +28,13 @@ Instructions:
|
|||||||
and store it in file status.json
|
and store it in file status.json
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
./decode-status.py -d <hostname or IP address>
|
./decode-status.py -d <hostname or IP address> [-u username] [-p password]
|
||||||
or
|
or
|
||||||
./decode-status.py -f <JSON status information file>
|
./decode-status.py -f <JSON status information file>
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
./decode-status.py -d sonoff1
|
./decode-status.py -d sonoff1
|
||||||
|
./decode-status.py -d sonoff1 -p 12345678
|
||||||
or
|
or
|
||||||
./decode-status.py -f status.json
|
./decode-status.py -f status.json
|
||||||
"""
|
"""
|
||||||
@ -42,6 +43,7 @@ import io
|
|||||||
import os.path
|
import os.path
|
||||||
import json
|
import json
|
||||||
import pycurl
|
import pycurl
|
||||||
|
import urllib2
|
||||||
from sys import exit
|
from sys import exit
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
@ -136,13 +138,20 @@ usage = "usage: decode-status {-d | -f} arg"
|
|||||||
parser = OptionParser(usage)
|
parser = OptionParser(usage)
|
||||||
parser.add_option("-d", "--dev", action="store", type="string",
|
parser.add_option("-d", "--dev", action="store", type="string",
|
||||||
dest="device", help="device to retrieve status from")
|
dest="device", help="device to retrieve status from")
|
||||||
|
parser.add_option("-u", "--username", action="store", type="string",
|
||||||
|
dest="username", help="username for login", default="admin")
|
||||||
|
parser.add_option("-p", "--password", action="store", type="string",
|
||||||
|
dest="password", help="password for login", default=None)
|
||||||
parser.add_option("-f", "--file", metavar="FILE",
|
parser.add_option("-f", "--file", metavar="FILE",
|
||||||
dest="jsonfile", default="status.json", help="status json file (default: status.json)")
|
dest="jsonfile", default="status.json", help="status json file (default: status.json)")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if (options.device):
|
if (options.device):
|
||||||
buffer = StringIO()
|
buffer = StringIO()
|
||||||
url = str("http://{}/cm?cmnd=status%200".format(options.device))
|
loginstr = ""
|
||||||
|
if options.password is not None:
|
||||||
|
loginstr = "user={}&password={}&".format(urllib2.quote(options.username), urllib2.quote(options.password))
|
||||||
|
url = str("http://{}/cm?{}cmnd=status%200".format(options.device, loginstr))
|
||||||
c = pycurl.Curl()
|
c = pycurl.Curl()
|
||||||
c.setopt(c.URL, url)
|
c.setopt(c.URL, url)
|
||||||
c.setopt(c.WRITEDATA, buffer)
|
c.setopt(c.WRITEDATA, buffer)
|
||||||
@ -217,4 +226,4 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
StartDecode()
|
StartDecode()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("E: {}".format(e))
|
print("E: {}".format(e))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user