-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
dump_changes.py
executable file
·93 lines (79 loc) · 3.01 KB
/
dump_changes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /usr/bin/env python3
# pylint: disable=invalid-name, disable=too-many-locals
"""Script to dump all value changes from Luxtronik controller"""
import os
import time
import argparse
from luxtronik import Luxtronik
from luxtronik.constants import LUXTRONIK_DEFAULT_PORT
def dump_changes():
"""Dump all value changes from Luxtronik controller"""
# pylint: disable=duplicate-code
parser = argparse.ArgumentParser(
description="Dumps all value changes from Luxtronik controller"
)
parser.add_argument("ip", help="IP address of Luxtronik controller to connect to")
parser.add_argument(
"port",
nargs="?",
type=int,
default=LUXTRONIK_DEFAULT_PORT,
help="Port to use to connect to Luxtronik controller",
)
args = parser.parse_args()
client = Luxtronik(args.ip, args.port)
prev_calcs, prev_params, prev_visis = client.read()
# pylint: enable=duplicate-code
changes = {}
while True:
# Get new data
this_calcs, this_params, this_visis = client.read()
# Compare this values with the initial values
# and add changes to dictionary
for number, param in this_params:
key = f"para_{number}"
prev_param = prev_params.get(number)
if param.raw != prev_param.raw:
changes[key] = (
f"para: Number: {number:<5} Name: {prev_param.name:<60} "
+ f"Value: {prev_param} -> {param}"
)
elif key in changes:
changes[key] = (
f"para: Number: {number:<5} Name: {prev_param.name:<60} "
+ f"Value: {prev_param} -> reverted"
)
for number, calc in this_calcs:
key = f"calc_{number}"
prev_calc = prev_calcs.get(number)
if calc.raw != prev_calc.raw:
changes[key] = (
f"calc: Number: {number:<5} Name: {prev_calc.name:<60} "
+ f"Value: {prev_calc} -> {calc}"
)
elif key in changes:
changes[key] = (
f"calc: Number: {number:<5} Name: {prev_calc.name:<60} "
+ f"Value: {prev_calc} -> reverted"
)
for number, visi in this_visis:
key = f"visi_{number}"
prev_visi = prev_visis.get(number)
if visi.raw != prev_visi.raw:
changes[key] = (
f"visi: Number: {number:<5} Name: {prev_visi.name:<60} "
+ f"Value: {prev_visi} -> {visi}"
)
elif key in changes:
changes[key] = (
f"visi: Number: {number:<5} Name: {prev_visi.name:<60} "
+ f"Value: {prev_visi} -> reverted"
)
# Print changes
os.system("clear")
print("=" * 80)
for key, values in changes.items():
print(values)
time.sleep(1)
if __name__ == "__main__":
dump_changes()