code beautifying

This commit is contained in:
2020-08-30 22:13:30 +02:00
parent 4e07e84ce7
commit 93adb7a5d4

View File

@ -242,53 +242,31 @@ if __name__ == "__main__":
m = MeterbusSerial() m = MeterbusSerial()
m.open() m.open()
devices = [ 84, 87, 86, 85, 82, 81, 83, 80 ]
stats = { stats = {
84: { 'total': {
'ok': 0, 'ok': 0,
'error': 0 'error': 0
}, },
87: { 'devices': { x: { 'ok': 0, 'error': 0 } for x in devices }
'ok': 0,
'error': 0
},
86: {
'ok': 0,
'error': 0
},
85: {
'ok': 0,
'error': 0
},
82: {
'ok': 0,
'error': 0
},
81: {
'ok': 0,
'error': 0
},
83: {
'ok': 0,
'error': 0
},
80: {
'ok': 0,
'error': 0
}
} }
pp = pprint.PrettyPrinter(indent=4) pp = pprint.PrettyPrinter(indent=4)
while True: while True:
for a in stats.keys(): for a in devices:
r = m.shortFrameRequest(0x5b, a) r = m.shortFrameRequest(0x5b, a)
if r['status'] == 'ERROR': if r['status'] == 'ERROR':
stats[a]['error'] += 1 stats['total']['error'] += 1
stats['devices'][a]['error'] += 1
print("Error for {}, last state was {}, restarting loop".format(a, r['code'])) print("Error for {}, last state was {}, restarting loop".format(a, r['code']))
m.close() m.close()
sleep(5) sleep(5)
m.open() m.open()
else: else:
stats[a]['ok'] += 1 stats['total']['ok'] += 1
stats['devices'][a]['ok'] += 1
sleep(1) sleep(1)
pp.pprint(stats) pp.pprint(stats)
print("") print("")