|
@@ -16,8 +16,11 @@ class base(object):
|
16
|
16
|
FOLLOW_REQUEST_ERROR = 60 # Seconds, till error comes up, if device does not follow the command
|
17
|
17
|
FOLLOW_KEYS = ["current_heating_setpoint", ]
|
18
|
18
|
#
|
19
|
|
- BATTERY_LVL_WARNING = 10
|
20
|
|
- BATTERY_LVL_ERROR = 5
|
|
19
|
+ BATTERY_LVL_WARNING = 20
|
|
20
|
+ BATTERY_LVL_ERROR = 10
|
|
21
|
+ #
|
|
22
|
+ LAST_MSG_WARNING = 6 * 24 * 60 * 60
|
|
23
|
+ LAST_MSG_ERROR = 24 * 24 * 60 * 60
|
21
|
24
|
|
22
|
25
|
def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
|
23
|
26
|
self.topic = topic
|
|
@@ -25,6 +28,8 @@ class base(object):
|
25
|
28
|
mqtt_client.add_callback(topic, self.__rx__)
|
26
|
29
|
mqtt_client.add_callback(topic + '/#', self.__rx__)
|
27
|
30
|
#
|
|
31
|
+ self.last_device_msg = None
|
|
32
|
+ #
|
28
|
33
|
self.__target_storage__ = {}
|
29
|
34
|
self.__state_storage__ = {}
|
30
|
35
|
#
|
|
@@ -45,9 +50,24 @@ class base(object):
|
45
|
50
|
|
46
|
51
|
def status(self, key):
|
47
|
52
|
#
|
|
53
|
+ # HEARTBEAT
|
|
54
|
+ #
|
|
55
|
+ if key == "heartbeat":
|
|
56
|
+ if self.last_device_msg is None:
|
|
57
|
+ return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no data received or unknown monitoring"}
|
|
58
|
+ else:
|
|
59
|
+ dt = time.time() - self.last_device_msg
|
|
60
|
+ dt_disp = dt / 60 / 60
|
|
61
|
+ if dt > self.LAST_MSG_ERROR:
|
|
62
|
+ return {"status": nagios.Nagios.ERROR, "msg": "Last message %.1fh ago" % dt_disp}
|
|
63
|
+ elif dt > self.LAST_MSG_WARNING:
|
|
64
|
+ return {"status": nagios.Nagios.WARNING, "msg": "Last message %.1fh ago" % dt_disp}
|
|
65
|
+ else:
|
|
66
|
+ return {"status": nagios.Nagios.OK, "msg": "Last message %.1fh ago" % dt_disp}
|
|
67
|
+ #
|
48
|
68
|
# FOLLOW SETPOINT
|
49
|
69
|
#
|
50
|
|
- if key in self.FOLLOW_KEYS:
|
|
70
|
+ elif key in self.FOLLOW_KEYS:
|
51
|
71
|
tm_s, value_s = self.__state_storage__.get(key, (0, None))
|
52
|
72
|
try:
|
53
|
73
|
tm_t, value_t = self.__target_storage__[key]
|
|
@@ -107,16 +127,30 @@ class livarno_sw_br_ct(base):
|
107
|
127
|
|
108
|
128
|
|
109
|
129
|
class brennenstuhl_heatingvalve(base):
|
|
130
|
+ BATTERY_LVL_WARNING = 10
|
|
131
|
+ BATTERY_LVL_ERROR = 5
|
|
132
|
+
|
110
|
133
|
def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
|
111
|
134
|
base.__init__(self, mqtt_client, topic)
|
112
|
135
|
|
113
|
136
|
def __rx__(self, client, userdata, message):
|
114
|
137
|
payload = json.loads(message.payload)
|
|
138
|
+ #
|
|
139
|
+ # heartbeat
|
|
140
|
+ #
|
|
141
|
+ if message.topic == self.topic:
|
|
142
|
+ self.last_device_msg = time.time()
|
|
143
|
+ #
|
|
144
|
+ # follow setpoint
|
|
145
|
+ #
|
115
|
146
|
if "current_heating_setpoint" in payload:
|
116
|
147
|
if message.topic == self.topic + '/set':
|
117
|
148
|
self.target("current_heating_setpoint", payload["current_heating_setpoint"])
|
118
|
149
|
if message.topic == self.topic:
|
119
|
150
|
self.state("current_heating_setpoint", payload["current_heating_setpoint"])
|
|
151
|
+ #
|
|
152
|
+ # battery level
|
|
153
|
+ #
|
120
|
154
|
if "battery" in payload and message.topic == self.topic:
|
121
|
155
|
self.battery = payload["battery"]
|
122
|
156
|
|