Merge pull request #5105 from jziolkowski/development

decode-status.py update to 6.4.1.14
This commit is contained in:
Theo Arends 2019-02-04 11:24:49 +01:00 committed by GitHub
commit 7b8a8a0cc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 50 additions and 36 deletions

View File

@ -84,6 +84,13 @@ a_setoption = [[
"Enforce HASS light group",
"Do not show Wifi and Mqtt state using Led"
],[
"Key hold time (ms)",
"Sonoff POW Max_Power_Retry",
"Tuya dimmer device id",
"","","",
"","","","","","",
"","","","","","",
],[
"Timers enabled",
"Generic ESP8285 GPIO enabled",
"Add UTC time offset to JSON message",
@ -168,66 +175,73 @@ if (options.device):
obj = json.loads(body)
else:
jsonfile = options.jsonfile
fp = open(jsonfile, "r")
obj = json.load(fp)
fp.close()
with open(jsonfile, "r") as fp:
obj = json.load(fp)
def StartDecode():
print ("\n*** decode-status.py v20180730 by Theo Arends ***")
# print("Decoding\n{}".format(obj))
if ("StatusSNS" in obj):
if ("Time" in obj["StatusSNS"]):
if "StatusSNS" in obj:
if "Time" in obj["StatusSNS"]:
time = str(" from status report taken at {}".format(obj["StatusSNS"]["Time"]))
if ("Status" in obj):
if ("FriendlyName" in obj["Status"]):
if "Status" in obj:
if "FriendlyName" in obj["Status"]:
print("Decoding information for device {}{}".format(obj["Status"]["FriendlyName"][0], time))
if ("StatusLOG" in obj):
if ("SetOption" in obj["StatusLOG"]):
if "StatusLOG" in obj:
if "SetOption" in obj["StatusLOG"]:
options = []
o = 0
p = 0
r = 1
if (len(obj["StatusLOG"]["SetOption"]) == 3):
r = 2
for f in range(r):
if (f == 1):
o = 2
p = 50
option = obj["StatusLOG"]["SetOption"][o]
i_option = int(option,16)
for i in range(len(a_setoption[f])):
if (a_setoption[f][i]):
state = (i_option >> i) & 1
options.append(str("{0:2d} ({1}) {2}".format(i + p, a_on_off[state], a_setoption[f][i])))
i = 0
for r,opt_group in enumerate(a_setoption):
register = obj["StatusLOG"]["SetOption"][r]
if r > 0 and len(obj["StatusLOG"]["SetOption"]) == 2: # old firmware: array consisted only of SetOptions 0..31 and resolution
break
if r == 1:
if len(register) == 8: # pre 6.1.1.14: array consisted of SetOptions 0..31, resolution, and SetOptions 50..81
i += 18 # adjust option index and skip 2nd register
continue
elif len(register) == 36: # 6.1.1.14: array consists of SetOptions 0..31, SetOptions 32..49, and SetOptions 50..81
split_register = [int(register[opt*2:opt*2+2],16) for opt in range(18)] # split register into 18 values
for opt_idx, option in enumerate(opt_group):
options.append(str("{0:2d} ({1:3d}) {2}".format(i, split_register[opt_idx], option)))
i += 1
if r in (0, 2): #registers 1 and 3 hold binary values
for opt_idx, option in enumerate(opt_group):
i_register = int(register,16)
state = (i_register >> opt_idx) & 1
options.append(str("{0:2d} ({1}) {2}".format(i, a_on_off[state], option)))
i += 1
print("\nOptions")
for i in range(len(options)):
print(" {}".format(options[i]))
for o in options:
print(" {}".format(o))
if ("StatusMEM" in obj):
if ("Features" in obj["StatusMEM"]):
if "StatusMEM" in obj:
if "Features" in obj["StatusMEM"]:
features = []
for f in range(5):
feature = obj["StatusMEM"]["Features"][f]
i_feature = int(feature,16)
if (f == 0):
if f == 0:
features.append(str("Language LCID = {}".format(i_feature & 0xFFFF)))
else:
for i in range(len(a_features[f -1])):
if ((i_feature >> i) & 1):
if (i_feature >> i) & 1:
features.append(a_features[f -1][i])
features.sort()
print("\nFeatures")
for i in range(len(features)):
print(" {}".format(features[i]))
for f in features:
print(" {}".format(f))
if __name__ == "__main__":
try: