forked from open3e/open3e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Open3E_dids2json.py
62 lines (48 loc) · 1.79 KB
/
Open3E_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# Convert Open3E datapoint list to JSON format, e.g. for use in ioBroker adapter E3onCAN
#
# Create white list of writable datapoints based on filter patterns
#
# 08.02.2024: Added Version-String to Open3Edatapoints.json
import json
from datetime import date
import Open3Edatapoints
from Open3Ecodecs import *
dataIdentifiers = dict(Open3Edatapoints.dataIdentifiers["dids"])
didsDict = {}
didsWritable = {}
writablesPatterns = ['setpoint',
'schedule',
'backupboxconfiguration',
'target',
'offset',
'minimummaximumset',
'minimummaximumlimit',
'domestichotwatercirculationpump',
'operationstate'
]
def setToWritable(id):
res = False
for pattern in writablesPatterns:
if pattern in id.lower():
return True
return False
print('Start conversion of datapoints "Open3Edatapoints.py" to json format.')
print('Create white list for writable datapoints based on filter patterns.\n')
didsListVersion = date.today().strftime("%Y%m%d")
cntDps = 0
cntWrt = 0
for dp in dataIdentifiers:
didsDict[dp] = dataIdentifiers[dp].getCodecInfo()
if setToWritable(didsDict[dp]['id']):
didsWritable[dp] = didsDict[dp]['id']
cntWrt += 1
cntDps += 1
didsDict['Version'] = didsListVersion
with open('Open3Edatapoints.json', 'w') as json_file:
json.dump(didsDict, json_file, indent=2)
with open('Open3Edatapoints_writables.json', 'w') as json_file:
json.dump(didsWritable, json_file, indent=2)
print(str(cntDps)+' dids converted to JSON format. See file "Open3Edatapoints.json"')
print(str(cntWrt)+' dids identified as writable. See file "Open3Edatapoints_writables.json"')
print('Done.')