Ver código fonte

Zigbee heating valve heartbeat check implemented

master
Dirk Alders 1 ano atrás
pai
commit
a2d4306fa6

+ 5
- 2
check_z_heat_vlv_follow Ver arquivo

@@ -7,7 +7,7 @@ import time
7 7
 from z_server import config
8 8
 from z_server import tcp_socket
9 9
 from z_server.z_protocol import server as client_prot
10
-from z_server.z_protocol import DID_FOLLOWS_HEATING_SETPOINT, DID_BATTERY_LEVEL
10
+from z_server.z_protocol import DID_FOLLOWS_HEATING_SETPOINT, DID_BATTERY_LEVEL, DID_HEARTBEAT
11 11
 from z_server import socket_protocol
12 12
 import sys
13 13
 
@@ -31,7 +31,10 @@ if __name__ == '__main__':
31 31
         "fun": "FUN_HEA"    # <-- Const, because script is for heat_vlv only
32 32
     }
33 33
     #
34
-    if sys.argv[0].endswith('check_z_heat_vlv_follow'):
34
+    if sys.argv[0].endswith('check_z_heat_vlv_heartbeat'):
35
+        sp.send(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, data)
36
+        sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_HEARTBEAT).get_data()
37
+    elif sys.argv[0].endswith('check_z_heat_vlv_follow'):
35 38
         sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, data)
36 39
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_HEATING_SETPOINT).get_data()
37 40
     elif sys.argv[0].endswith('check_z_heat_vlv_battery'):

+ 1
- 0
check_z_heat_vlv_heartbeat Ver arquivo

@@ -0,0 +1 @@
1
+check_z_heat_vlv_follow

+ 37
- 3
z_server/devices/__init__.py Ver arquivo

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

+ 2
- 0
z_server/z_protocol.py Ver arquivo

@@ -4,6 +4,7 @@ import socket_protocol
4 4
 
5 5
 DID_FOLLOWS_HEATING_SETPOINT = 'current_heating_setpoint'
6 6
 DID_BATTERY_LEVEL = 'battery'
7
+DID_HEARTBEAT = 'heartbeat'
7 8
 
8 9
 
9 10
 class server(socket_protocol.pure_json_protocol):
@@ -18,6 +19,7 @@ class server(socket_protocol.pure_json_protocol):
18 19
         if not self.__comm_inst__.IS_CLIENT:
19 20
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, self.device_status)
20 21
             self.register_callback(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, self.device_status)
22
+            self.register_callback(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, self.device_status)
21 23
 
22 24
     def device_status(self, msg):
23 25
         if msg.get_status() == socket_protocol.STATUS_OKAY:

Carregando…
Cancelar
Salvar