From b8afa117434bbf13c4a90cbb2cc167341af76e7f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 4 Jul 2020 17:39:56 +0200 Subject: [PATCH] Update decode-status.py to python 3.x --- tools/decode-status.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tools/decode-status.py b/tools/decode-status.py index bdffa4ba3..e6e4138bd 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -20,7 +20,7 @@ Requirements: - Python - - pip json pycurl + - pip json requests Instructions: Execute command with option -d to retrieve status report from device or @@ -42,11 +42,10 @@ Example: import io import os.path import json -import pycurl -import urllib2 +import requests +import urllib from sys import exit from optparse import OptionParser -from StringIO import StringIO a_on_off = ["OFF","ON "] @@ -146,11 +145,14 @@ a_setoption = [[ "Distinct MQTT topics per device for Zigbee", "Disable non-json MQTT response", "Enable light fading at start/power on", - "Set PWM Mode from regular PWM to ColorTemp control","", + "Set PWM Mode from regular PWM to ColorTemp control", "Keep uncompressed rules in memory to avoid CPU load of uncompressing at each tick", "Implement simpler MAX6675 protocol instead of MAX31855", - "","", - "","","","", + "Enable Wifi", + "Enable Ethernet (ESP32)", + "Set Baud rate for TuyaMCU serial communication (0 = 9600 or 1 = 115200)", + "Rotary encoder uses rules instead of light control", + "","","", "","","","", "","","","", "","","","" @@ -225,25 +227,19 @@ parser.add_option("-f", "--file", metavar="FILE", (options, args) = parser.parse_args() if (options.device): - buffer = StringIO() loginstr = "" if options.password is not None: - loginstr = "user={}&password={}&".format(urllib2.quote(options.username), urllib2.quote(options.password)) + loginstr = "user={}&password={}&".format(urllib.parse.quote(options.username), urllib.parse.quote(options.password)) url = str("http://{}/cm?{}cmnd=status%200".format(options.device, loginstr)) - c = pycurl.Curl() - c.setopt(c.URL, url) - c.setopt(c.WRITEDATA, buffer) - c.perform() - c.close() - body = buffer.getvalue() - obj = json.loads(body) + res = requests.get(url) + obj = json.loads(res.content) else: jsonfile = options.jsonfile with open(jsonfile, "r") as fp: obj = json.load(fp) def StartDecode(): - print ("\n*** decode-status.py v20200627 by Theo Arends and Jacek Ziolkowski ***") + print ("\n*** decode-status.py v20200704 by Theo Arends and Jacek Ziolkowski ***") # print("Decoding\n{}".format(obj))