|
@@ -4,6 +4,7 @@
|
4
|
4
|
|
5
|
5
|
import config
|
6
|
6
|
import devices
|
|
7
|
+from function.db import get_gui_radiator_data, set_gui_radiator_data
|
7
|
8
|
from function.rooms import room_shelly
|
8
|
9
|
import logging
|
9
|
10
|
import task
|
|
@@ -140,16 +141,22 @@ class radiator_function(object):
|
140
|
141
|
|
141
|
142
|
def __init__(self, mqtt_client, topic_valve, topic_gui, default_temperature):
|
142
|
143
|
self.default_temperature = default_temperature
|
143
|
|
- self.regular_temp_setpoint = self.default_temperature
|
144
|
|
- self.__away_mode__ = False
|
145
|
|
- self.__summer_mode__ = False
|
146
|
|
- #
|
147
|
|
- self.ct = task.periodic(1, self.cyclic_task)
|
148
|
|
- #
|
|
144
|
+ self.boost_timer = None
|
|
145
|
+ # device initialisation
|
149
|
146
|
self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, topic_valve)
|
150
|
147
|
self.gui_heating = devices.nodered_gui_radiator(mqtt_client, topic_gui)
|
151
|
|
- #
|
152
|
|
- self.heating_valve.set_heating_setpoint(self.default_temperature)
|
|
148
|
+ # db-stored data initialisation
|
|
149
|
+ db_data = get_gui_radiator_data(topic_gui)
|
|
150
|
+ self.__away_mode__ = db_data[0] or False
|
|
151
|
+ self.__summer_mode__ = db_data[1] or False
|
|
152
|
+ self.__user_temperature_setpoint__ = db_data[2] or default_temperature
|
|
153
|
+ if self.__away_mode__:
|
|
154
|
+ self.away_mode(None, None, True)
|
|
155
|
+ elif self.__summer_mode__:
|
|
156
|
+ self.summer_mode(None, None, True)
|
|
157
|
+ else:
|
|
158
|
+ self.set_heating_setpoint(None, None, self.__user_temperature_setpoint__)
|
|
159
|
+ # callback initialisation
|
153
|
160
|
self.heating_valve.add_callback(devices.brennenstuhl_heatingvalve.KEY_TEMPERATURE, None, self.gui_heating.set_temperature_mcb)
|
154
|
161
|
self.heating_valve.add_callback(devices.brennenstuhl_heatingvalve.KEY_HEATING_SETPOINT, None, self.get_radiator_setpoint)
|
155
|
162
|
#
|
|
@@ -158,9 +165,8 @@ class radiator_function(object):
|
158
|
165
|
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, self.setpoint_to_default)
|
159
|
166
|
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, self.away_mode)
|
160
|
167
|
self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, self.summer_mode)
|
161
|
|
- #
|
162
|
|
- self.boost_timer = None
|
163
|
|
- #
|
|
168
|
+ # cyclic task initialisation
|
|
169
|
+ self.ct = task.periodic(1, self.cyclic_task)
|
164
|
170
|
self.ct.run()
|
165
|
171
|
|
166
|
172
|
def cyclic_task(self, rt):
|
|
@@ -170,19 +176,23 @@ class radiator_function(object):
|
170
|
176
|
self.boost_timer -= self.ct.cycle_time
|
171
|
177
|
if self.boost_timer <= 0:
|
172
|
178
|
self.cancel_boost()
|
173
|
|
- self.heating_valve.set_heating_setpoint(self.regular_temp_setpoint)
|
|
179
|
+ self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__)
|
|
180
|
+ self.heating_valve.logger.info('Timer expired. returning to regular temperature setpoint %.1f°C.', self.__user_temperature_setpoint__)
|
174
|
181
|
|
175
|
182
|
def cancel_boost(self, device=None, key=None, data=None):
|
176
|
183
|
if self.boost_timer is not None:
|
177
|
|
- self.heating_valve.logger.info('Timer expired. returning to regular temperature setpoint %.1f°C.', self.regular_temp_setpoint)
|
178
|
184
|
self.boost_timer = None
|
179
|
185
|
self.gui_heating.set_timer('-')
|
180
|
186
|
|
181
|
|
- def update_states(self, away_mode=None, summer_mode=None):
|
|
187
|
+ def update_states(self, away_mode=None, summer_mode=None, user_temperature_setpoint=None):
|
182
|
188
|
if away_mode is not None:
|
183
|
189
|
self.__away_mode__ = away_mode
|
184
|
190
|
if summer_mode is not None:
|
185
|
191
|
self.__summer_mode__ = summer_mode
|
|
192
|
+ if user_temperature_setpoint is not None:
|
|
193
|
+ self.__user_temperature_setpoint__ = user_temperature_setpoint
|
|
194
|
+ set_gui_radiator_data(self.gui_heating.topic, self.__away_mode__, self.__summer_mode__, self.__user_temperature_setpoint__)
|
|
195
|
+ #
|
186
|
196
|
self.gui_heating.set_away(self.__away_mode__)
|
187
|
197
|
self.gui_heating.set_summer(self.__summer_mode__)
|
188
|
198
|
self.gui_heating.set_enable(not self.__away_mode__ and not self.__summer_mode__)
|
|
@@ -191,10 +201,10 @@ class radiator_function(object):
|
191
|
201
|
if value is True:
|
192
|
202
|
self.cancel_boost()
|
193
|
203
|
self.update_states(away_mode=value, summer_mode=False)
|
194
|
|
- self.heating_valve.set_heating_setpoint(self.default_temperature - self.AWAY_REDUCTION)
|
|
204
|
+ self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__ - self.AWAY_REDUCTION)
|
195
|
205
|
else:
|
196
|
206
|
self.update_states(away_mode=value)
|
197
|
|
- self.heating_valve.set_heating_setpoint(self.default_temperature)
|
|
207
|
+ self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__)
|
198
|
208
|
|
199
|
209
|
def summer_mode(self, device, key, value):
|
200
|
210
|
if value is True:
|
|
@@ -203,7 +213,7 @@ class radiator_function(object):
|
203
|
213
|
self.heating_valve.set_heating_setpoint(self.SUMMER_TEMPERATURE)
|
204
|
214
|
else:
|
205
|
215
|
self.update_states(summer_mode=value)
|
206
|
|
- self.heating_valve.set_heating_setpoint(self.default_temperature)
|
|
216
|
+ self.heating_valve.set_heating_setpoint(self.__user_temperature_setpoint__)
|
207
|
217
|
|
208
|
218
|
def boost(self, device, key, data):
|
209
|
219
|
if self.boost_timer is None:
|
|
@@ -220,12 +230,13 @@ class radiator_function(object):
|
220
|
230
|
self.set_heating_setpoint(device, key, self.default_temperature)
|
221
|
231
|
|
222
|
232
|
def set_heating_setpoint(self, device, key, data):
|
223
|
|
- self.heating_valve.set_heating_setpoint(data)
|
224
|
233
|
self.cancel_boost()
|
225
|
|
- self.update_states(away_mode=False, summer_mode=False)
|
|
234
|
+ self.update_states(away_mode=False, summer_mode=False, user_temperature_setpoint=data)
|
|
235
|
+ self.heating_valve.set_heating_setpoint(data)
|
226
|
236
|
|
227
|
237
|
def get_radiator_setpoint(self, device, key, data):
|
228
|
|
- self.gui_heating.set_setpoint_temperature(data)
|
229
|
|
- self.update_states()
|
230
|
238
|
if self.boost_timer is None and not self.__away_mode__ and not self.__summer_mode__:
|
231
|
|
- self.regular_temp_setpoint = data
|
|
239
|
+ self.update_states(user_temperature_setpoint=data)
|
|
240
|
+ else:
|
|
241
|
+ self.update_states()
|
|
242
|
+ self.gui_heating.set_setpoint_temperature(data)
|