Browse Source

Ignore delayed heating valve setpoints - values set by user in the last two seconds

tags/v1.3.0
Dirk Alders 1 year ago
parent
commit
36884d40c1
1 changed files with 30 additions and 2 deletions
  1. 30
    2
      function/modules.py

+ 30
- 2
function/modules.py View File

17
 from function.helpers import day_state
17
 from function.helpers import day_state
18
 import logging
18
 import logging
19
 import task
19
 import task
20
+import time
20
 
21
 
21
 try:
22
 try:
22
     from config import APP_NAME as ROOT_LOGGER_NAME
23
     from config import APP_NAME as ROOT_LOGGER_NAME
152
     AWAY_REDUCTION = 5
153
     AWAY_REDUCTION = 5
153
     SUMMER_TEMPERATURE = 5
154
     SUMMER_TEMPERATURE = 5
154
 
155
 
156
+    class value_timeout_list(object):
157
+        MAX_DELAY = 3
158
+
159
+        def __init__(self):
160
+            self.__data__ = []
161
+            self.__time__ = []
162
+
163
+        def __cleanup__(self):
164
+            now = time.time()
165
+            for i, tm in enumerate(self.__time__):
166
+                if tm + self.MAX_DELAY < now:
167
+                    del (self.__data__[i])
168
+                    del (self.__time__[i])
169
+
170
+        def new(self, item):
171
+            self.__cleanup__()
172
+            self.__data__.append(item)
173
+            self.__time__.append(time.time())
174
+
175
+        def is_valid_value(self, data):
176
+            self.__cleanup__()
177
+            return data not in self.__data__
178
+
155
     def __init__(self, heating_valve, default_temperature, **kwargs):
179
     def __init__(self, heating_valve, default_temperature, **kwargs):
156
         self.heating_valve = heating_valve
180
         self.heating_valve = heating_valve
157
         self.default_temperature = default_temperature
181
         self.default_temperature = default_temperature
158
         #
182
         #
183
+        self.valve_value = self.value_timeout_list()
184
+        #
159
         super().__init__({
185
         super().__init__({
160
             self.KEY_USER_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_USER_TEMPERATURE_SETPOINT, self.default_temperature),
186
             self.KEY_USER_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_USER_TEMPERATURE_SETPOINT, self.default_temperature),
161
             self.KEY_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_TEMPERATURE_SETPOINT, self.default_temperature),
187
             self.KEY_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_TEMPERATURE_SETPOINT, self.default_temperature),
241
         self.set(self.KEY_TEMPERATURE_SETPOINT, data)
267
         self.set(self.KEY_TEMPERATURE_SETPOINT, data)
242
 
268
 
243
     def set_heating_setpoint(self, device, key, data):
269
     def set_heating_setpoint(self, device, key, data):
270
+        self.valve_value.new(data)
244
         self.heating_valve.set_heating_setpoint(data)
271
         self.heating_valve.set_heating_setpoint(data)
245
 
272
 
246
     def get_radiator_setpoint(self, device, key, data):
273
     def get_radiator_setpoint(self, device, key, data):
247
-        if self[self.KEY_BOOST_TIMER] == 0 and not self[self.KEY_AWAY_MODE] and not self[self.KEY_SUMMER_MODE]:
248
-            self.set(self.KEY_USER_TEMPERATURE_SETPOINT, data, block_callback=[self.set_heating_setpoint])
274
+        if self.valve_value.is_valid_value(data):
275
+            if self[self.KEY_BOOST_TIMER] == 0 and not self[self.KEY_AWAY_MODE] and not self[self.KEY_SUMMER_MODE]:
276
+                self.set(self.KEY_USER_TEMPERATURE_SETPOINT, data, block_callback=[self.set_heating_setpoint])
249
 
277
 
250
     def get_radiator_temperature(self, device, key, data):
278
     def get_radiator_temperature(self, device, key, data):
251
         self.set(self.KEY_TEMPERATURE_CURRENT, data)
279
         self.set(self.KEY_TEMPERATURE_CURRENT, data)

Loading…
Cancel
Save