Sfoglia il codice sorgente

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

tags/v1.3.0
Dirk Alders 1 anno fa
parent
commit
36884d40c1
1 ha cambiato i file con 30 aggiunte e 2 eliminazioni
  1. 30
    2
      function/modules.py

+ 30
- 2
function/modules.py Vedi File

@@ -17,6 +17,7 @@ import devices
17 17
 from function.helpers import day_state
18 18
 import logging
19 19
 import task
20
+import time
20 21
 
21 22
 try:
22 23
     from config import APP_NAME as ROOT_LOGGER_NAME
@@ -152,10 +153,35 @@ class heating_function(common_base):
152 153
     AWAY_REDUCTION = 5
153 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 179
     def __init__(self, heating_valve, default_temperature, **kwargs):
156 180
         self.heating_valve = heating_valve
157 181
         self.default_temperature = default_temperature
158 182
         #
183
+        self.valve_value = self.value_timeout_list()
184
+        #
159 185
         super().__init__({
160 186
             self.KEY_USER_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_USER_TEMPERATURE_SETPOINT, self.default_temperature),
161 187
             self.KEY_TEMPERATURE_SETPOINT: kwargs.get(self.KEY_TEMPERATURE_SETPOINT, self.default_temperature),
@@ -241,11 +267,13 @@ class heating_function(common_base):
241 267
         self.set(self.KEY_TEMPERATURE_SETPOINT, data)
242 268
 
243 269
     def set_heating_setpoint(self, device, key, data):
270
+        self.valve_value.new(data)
244 271
         self.heating_valve.set_heating_setpoint(data)
245 272
 
246 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 278
     def get_radiator_temperature(self, device, key, data):
251 279
         self.set(self.KEY_TEMPERATURE_CURRENT, data)

Loading…
Annulla
Salva