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
 from z_server import config
7
 from z_server import config
8
 from z_server import tcp_socket
8
 from z_server import tcp_socket
9
 from z_server.z_protocol import server as client_prot
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
 from z_server import socket_protocol
11
 from z_server import socket_protocol
12
 import sys
12
 import sys
13
 
13
 
31
         "fun": "FUN_HEA"    # <-- Const, because script is for heat_vlv only
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
         sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, data)
38
         sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, data)
36
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_HEATING_SETPOINT).get_data()
39
         sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_HEATING_SETPOINT).get_data()
37
     elif sys.argv[0].endswith('check_z_heat_vlv_battery'):
40
     elif sys.argv[0].endswith('check_z_heat_vlv_battery'):

+ 1
- 0
check_z_heat_vlv_heartbeat Ver arquivo

1
+check_z_heat_vlv_follow

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

16
     FOLLOW_REQUEST_ERROR = 60       # Seconds, till error comes up, if device does not follow the command
16
     FOLLOW_REQUEST_ERROR = 60       # Seconds, till error comes up, if device does not follow the command
17
     FOLLOW_KEYS = ["current_heating_setpoint", ]
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
     def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
25
     def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
23
         self.topic = topic
26
         self.topic = topic
25
         mqtt_client.add_callback(topic, self.__rx__)
28
         mqtt_client.add_callback(topic, self.__rx__)
26
         mqtt_client.add_callback(topic + '/#', self.__rx__)
29
         mqtt_client.add_callback(topic + '/#', self.__rx__)
27
         #
30
         #
31
+        self.last_device_msg = None
32
+        #
28
         self.__target_storage__ = {}
33
         self.__target_storage__ = {}
29
         self.__state_storage__ = {}
34
         self.__state_storage__ = {}
30
         #
35
         #
45
 
50
 
46
     def status(self, key):
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
         # FOLLOW SETPOINT
68
         # FOLLOW SETPOINT
49
         #
69
         #
50
-        if key in self.FOLLOW_KEYS:
70
+        elif key in self.FOLLOW_KEYS:
51
             tm_s, value_s = self.__state_storage__.get(key, (0, None))
71
             tm_s, value_s = self.__state_storage__.get(key, (0, None))
52
             try:
72
             try:
53
                 tm_t, value_t = self.__target_storage__[key]
73
                 tm_t, value_t = self.__target_storage__[key]
107
 
127
 
108
 
128
 
109
 class brennenstuhl_heatingvalve(base):
129
 class brennenstuhl_heatingvalve(base):
130
+    BATTERY_LVL_WARNING = 10
131
+    BATTERY_LVL_ERROR = 5
132
+
110
     def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
133
     def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
111
         base.__init__(self, mqtt_client, topic)
134
         base.__init__(self, mqtt_client, topic)
112
 
135
 
113
     def __rx__(self, client, userdata, message):
136
     def __rx__(self, client, userdata, message):
114
         payload = json.loads(message.payload)
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
         if "current_heating_setpoint" in payload:
146
         if "current_heating_setpoint" in payload:
116
             if message.topic == self.topic + '/set':
147
             if message.topic == self.topic + '/set':
117
                 self.target("current_heating_setpoint", payload["current_heating_setpoint"])
148
                 self.target("current_heating_setpoint", payload["current_heating_setpoint"])
118
             if message.topic == self.topic:
149
             if message.topic == self.topic:
119
                 self.state("current_heating_setpoint", payload["current_heating_setpoint"])
150
                 self.state("current_heating_setpoint", payload["current_heating_setpoint"])
151
+        #
152
+        # battery level
153
+        #
120
         if "battery" in payload and message.topic == self.topic:
154
         if "battery" in payload and message.topic == self.topic:
121
             self.battery = payload["battery"]
155
             self.battery = payload["battery"]
122
 
156
 

+ 2
- 0
z_server/z_protocol.py Ver arquivo

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

Carregando…
Cancelar
Salvar