-
Notifications
You must be signed in to change notification settings - Fork 0
/
Heating_Profile.py
executable file
·124 lines (101 loc) · 4.04 KB
/
Heating_Profile.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import menus
import datafiles
import json
import os
import ml
import traceback
profiles = {}
class Heating_Profile:
def set_letter(self,letter):
global profiles
if self.letter != letter:
if self.letter:
del profiles[self.letter]
# try:
# os.remove(datafiles.dtzfile(self.letter))
# except:
# pass
if letter is not None:
self.letter = letter
profiles[letter] = self
def __init__(self,letter,temp,duration, FR, EN, NL):
self.letter = None
self.temp = temp
self.duration = duration
self.label = ml.T(FR,EN,NL)
self.set_letter(letter)
def __str__(self):
return self.letter+": "+str(self.temp)+"°C, "+str(self.duration)+'" : '+self.label.french
def to_dict(self):
return {
'letter' : self.letter
,'temp' : self.temp
,'duration' : self.duration
,'FR': self.label.french
,'EN': self.label.english
,'NL': self.label.dutch
}
def getByLetter(self,letter):
global profiles
if letter not in profiles.keys():
return None
else:
return profiles[letter]
# Fonction pour sauvegarder un objet de la classe courante en utilisant JSON : normalement on édite les JSON a la main !
def save(self):
with open(datafiles.dtzfile('profile_'+self.letter), 'w') as f:
#print(json.dumps(self.to_dict()))
json.dump(self.to_dict(),f)
# Fonction pour lire un objet de la classe courante depuis le disque en utilisant JSON
def load():
#filenames = []
try:
for filename in os.listdir(datafiles.DIR_BASE_DTZ):
pext = filename.index(".json")
if pext > 0:
fullpath = os.path.join(datafiles.DIR_BASE_DTZ, filename)
if os.path.isfile(fullpath) and filename.startswith('profile_') :
with open(fullpath, 'r') as f:
objdict = json.load(f)
newDTZ = Heating_Profile(objdict['letter'],objdict['temp'],objdict['duration'],objdict['FR'],objdict['EN'],objdict['NL'])
newDTZ.set_letter(filename[len('profile_'):pext])
print("Load "+str(newDTZ))
except:
traceback.print_exc()
print ('Error accessing '+datafiles.DIR_BASE_DTZ+' directory')
pass
try:
for filename in os.listdir(datafiles.DIR_PRIV_DTZ):
pext = filename.index(".json")
if pext > 0:
fullpath = os.path.join(datafiles.DIR_PRIV_DTZ, filename)
if os.path.isfile(fullpath) and filename.startswith('profile_') :
with open(fullpath, 'r') as f:
objdict = json.load(f)
newDTZ = Heating_Profile(objdict['letter'],objdict['temp'],objdict['duration'],objdict['FR'],objdict['EN'],objdict['NL'])
newDTZ.set_letter(filename[len('profile_'):pext])
print("Load private "+str(newDTZ))
except:
traceback.print_exc()
print ('Error accessing '+datafiles.DIR_PRIV_DTZ+' directory')
pass
def setProfile(letter, menus_param : menus):
global profiles
if letter in profiles.keys():
prof = profiles[letter]
menus_param.store('z', letter)
menus_param.store('P', prof.temp)
menus_param.store('M', prof.duration)
#menus.store('F', prof.letter)
menus_param.save()
# Heating_Profile('T',68.0,15.0,"Thermiser","Thermize","Thermis.")
# Heating_Profile('L',72.0,15.0,"Lait","miLk","meLk")
# Heating_Profile('J',75.0,15.0,"Jus+Crème","Juices+Cream","Saap+Room")
# Heating_Profile('Y',89.0,15.0,"Yaourt","Yogurt","Yoghurt")
# for (letter, prof) in profiles.items():
# with open(datafiles.dtzSharedFile('profile_'+prof.letter), 'w') as f:
# #print(json.dumps(self.to_dict()))
# json.dump(prof.to_dict(),f)
load()