|
@@ -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
|
#
|