forked from MyHomeMyData/E3onCAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE3onCAN_dids2json.py
38 lines (26 loc) · 1.02 KB
/
E3onCAN_dids2json.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
#
# Convert datapoint list for E380 and E3100CB to JSON format, e.g. for use in ioBroker adapter E3onCAN
#
import json
from datetime import date
import E3onCANdatapointsE380
from E3onCANdatapointsE380 import *
import E3onCANdatapointsE3100CB
from E3onCANdatapointsE3100CB import *
def dids2json(ids, fname, ver):
cntDps = 0
didsDict = {}
for dp in ids:
didsDict[str(dp).replace('.','_')] = ids[dp].getCodecInfo()
cntDps += 1
didsDict['Version'] = ver
with open(fname+'.json', 'w') as json_file:
json.dump(didsDict, json_file, indent=2)
print(str(cntDps)+' dids converted to JSON format. See file "'+fname+'.json"')
# MAIN
# ====
print('Start conversion of datapoints for energy meters to json format.\n')
didsListVersion = date.today().strftime("%Y%m%d")
dids2json(dict(E3onCANdatapointsE380.dataIdentifiersE380), 'E3onCANdatapointsE380', didsListVersion)
dids2json(dict(E3onCANdatapointsE3100CB.dataIdentifiersE3100CB), 'E3onCANdatapointsE3100CB', didsListVersion)
print('\nDone.')