Selaa lähdekoodia

Permanent setpoint sending disabled and time limited retries added to valve class

tags/v1.3.0
Dirk Alders 10 kuukautta sitten
vanhempi
commit
6638f2de69
2 muutettua tiedostoa jossa 33 lisäystä ja 5 poistoa
  1. 33
    0
      devices/brennenstuhl.py
  2. 0
    5
      function/modules.py

+ 33
- 0
devices/brennenstuhl.py Näytä tiedosto

@@ -3,6 +3,8 @@
3 3
 #
4 4
 from devices.base import base
5 5
 import json
6
+import task
7
+import time
6 8
 
7 9
 
8 10
 class brennenstuhl_heatingvalve(base):
@@ -42,6 +44,10 @@ class brennenstuhl_heatingvalve(base):
42 44
     KEY_VALVE_DETECTION = "valve_detection"
43 45
     KEY_WINDOW_DETECTION = "window_detection"
44 46
     #
47
+    RETRY_CYCLE_TIME = 2.5
48
+    MAX_TX_RETRIES = 20
49
+    RETRY_TIMEOUT = RETRY_CYCLE_TIME * MAX_TX_RETRIES
50
+    #
45 51
     TX_TYPE = base.TX_DICT
46 52
     #
47 53
     RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
@@ -51,11 +57,38 @@ class brennenstuhl_heatingvalve(base):
51 57
         super().__init__(mqtt_client, topic)
52 58
         self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
53 59
                               self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
60
+        self.add_callback(self.KEY_HEATING_SETPOINT, None, self.__valave_temp_rx__)
61
+        self.__tx_temperature__ = None
62
+        self.__rx_temperature__ = None
63
+        self.__tx_timestamp__ = 0
64
+        #
65
+        self.task = task.periodic(self.RETRY_CYCLE_TIME, self.__task__)
66
+        self.task.run()
54 67
 
55 68
     def __state_logging__(self, inst, key, data):
56 69
         if key in [self.KEY_HEATING_SETPOINT, self.KEY_CHILD_LOCK, self.KEY_WINDOW_DETECTION, self.KEY_VALVE_DETECTION]:
57 70
             self.logger.info("State change of '%s' to '%s'", key, repr(data))
58 71
 
72
+    def send_command(self, key, data):
73
+        if key == self.KEY_HEATING_SETPOINT:
74
+            self.__tx_temperature__ = data
75
+            self.__tx_timestamp__ = time.time()
76
+        base.send_command(self, key, data)
77
+
78
+    def __valave_temp_rx__(self, inst, key, data):
79
+        if key == self.KEY_HEATING_SETPOINT:
80
+            self.__rx_temperature__ = data
81
+
82
+    def __task__(self, rt):
83
+        if self.__tx_temperature__ is not None and self.__tx_timestamp__ is not None:   # Already send a setpoint
84
+            if self.__tx_temperature__ != self.__rx_temperature__:                      # Setpoint and valve feedback are unequal
85
+                if time.time() - self.__tx_timestamp__ < self.RETRY_TIMEOUT:            # Timeout condition allows resend of setpoint
86
+                    self.logger.warning("Setpoint not yet acknoledged by device. Sending setpoint again")
87
+                    self.set_heating_setpoint(self.__tx_temperature__)
88
+                    return
89
+            else:
90
+                self.__tx_timestamp__ = None                                            # Disable resend logic, if setpoint and valve setpoint are equal
91
+
59 92
     #
60 93
     # RX
61 94
     #

+ 0
- 5
function/modules.py Näytä tiedosto

@@ -208,17 +208,12 @@ class heating_function(common_base):
208 208
         # cyclic task initialisation
209 209
         self.ct = task.periodic(1, self.cyclic_task)
210 210
         self.ct.run()
211
-        self.ct2 = task.periodic(15 * 60, self.cyclic_task_tx_setpoint)
212
-        self.ct2.run()
213 211
 
214 212
     def timer_expired(self, device, data, key):
215 213
         self.set(self.KEY_TEMPERATURE_SETPOINT, self[self.KEY_USER_TEMPERATURE_SETPOINT])
216 214
         self.heating_valve.logger.info('Timer expired. returning to regular temperature setpoint %.1f°C.',
217 215
                                        self[self.KEY_TEMPERATURE_SETPOINT])
218 216
 
219
-    def cyclic_task_tx_setpoint(self, rt):
220
-        self.heating_valve.set_heating_setpoint(self.get(self.KEY_TEMPERATURE_SETPOINT))
221
-
222 217
     def cyclic_task(self, rt):
223 218
         timer_value = self[self.KEY_BOOST_TIMER] - self.ct.cycle_time
224 219
         if self[self.KEY_BOOST_TIMER] <= 0:

Loading…
Peruuta
Tallenna