Browse Source

Zigbee heating valve follow check improved, battery check added

master
Dirk Alders 1 year ago
parent
commit
33042e3f3c
4 changed files with 54 additions and 20 deletions
  1. 1
    0
      check_z_heat_vlv_battery
  2. 10
    3
      check_z_heat_vlv_follow
  3. 39
    15
      z_server/devices/__init__.py
  4. 4
    2
      z_server/z_protocol.py

+ 1
- 0
check_z_heat_vlv_battery View File

1
+check_z_heat_vlv_follow

check_z_heat_vlv → check_z_heat_vlv_follow View File

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
10
+from z_server.z_protocol import DID_FOLLOWS_HEATING_SETPOINT, DID_BATTERY_LEVEL
11
 from z_server import socket_protocol
11
 from z_server import socket_protocol
12
 import sys
12
 import sys
13
 
13
 
30
         "roo": args.roo,
30
         "roo": args.roo,
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
-    sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, data)
34
     #
33
     #
35
-    sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_HEATING_SETPOINT).get_data()
34
+    if sys.argv[0].endswith('check_z_heat_vlv_follow'):
35
+        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()
37
+    elif sys.argv[0].endswith('check_z_heat_vlv_battery'):
38
+        sp.send(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, data)
39
+        sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_BATTERY_LEVEL).get_data()
40
+    else:
41
+        sys.stderr.write('No action for command called "%s"\n' % sys.argv[0])
42
+        sys.exit(100)
36
     nagios.Nagios().exit(**sp_data)
43
     nagios.Nagios().exit(**sp_data)

+ 39
- 15
z_server/devices/__init__.py View File

14
 class base(object):
14
 class base(object):
15
     FOLLOW_REQUEST_WARNING = 5      # Seconds, till warning comes up, if device does not follow the command
15
     FOLLOW_REQUEST_WARNING = 5      # Seconds, till warning 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
16
     FOLLOW_REQUEST_ERROR = 60       # Seconds, till error comes up, if device does not follow the command
17
+    FOLLOW_KEYS = ["current_heating_setpoint", ]
18
+    #
19
+    BATTERY_LVL_WARNING = 10
20
+    BATTERY_LVL_ERROR = 5
17
 
21
 
18
     def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
22
     def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
19
         self.topic = topic
23
         self.topic = topic
23
         #
27
         #
24
         self.__target_storage__ = {}
28
         self.__target_storage__ = {}
25
         self.__state_storage__ = {}
29
         self.__state_storage__ = {}
30
+        #
31
+        self.battery = None
26
 
32
 
27
     def __rx__(self, client, userdata, message):
33
     def __rx__(self, client, userdata, message):
28
         pass
34
         pass
38
         logger.debug("Device state identified: %s: %s", key, repr(value))
44
         logger.debug("Device state identified: %s: %s", key, repr(value))
39
 
45
 
40
     def status(self, key):
46
     def status(self, key):
41
-        tm_s, value_s = self.__state_storage__.get(key, (0, None))
42
-        try:
43
-            tm_t, value_t = self.__target_storage__[key]
44
-        except KeyError:
45
-            if value_s is not None:
46
-                return {"status": nagios.Nagios.WARNING, "msg": "Current temperature setpoint %.1f°C (age=%.1fs), but never received a setpoint" % (value_s, time.time()-tm_s)}
47
-            return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no data received or unknown monitoring"}
48
-        else:
49
-            tm = time.time()
50
-            dt = tm - tm_t
51
-            if value_t != value_s and dt > self.FOLLOW_REQUEST_ERROR:
52
-                return {"status": nagios.Nagios.ERROR, "msg": "Requested setpoint unequal valve setpoint since %.1fs" % dt}
53
-            elif value_t != value_s and dt > self.FOLLOW_REQUEST_WARNING:
54
-                return {"status": nagios.Nagios.WARNING, "msg": "Requested setpoint unequal valve setpoint since %.1fs" % dt}
55
-            return {"status": nagios.Nagios.OK, "msg": "Requested setpoint equal valve setpoint"}
47
+        #
48
+        # FOLLOW SETPOINT
49
+        #
50
+        if key in self.FOLLOW_KEYS:
51
+            tm_s, value_s = self.__state_storage__.get(key, (0, None))
52
+            try:
53
+                tm_t, value_t = self.__target_storage__[key]
54
+            except KeyError:
55
+                if value_s is not None:
56
+                    return {"status": nagios.Nagios.WARNING, "msg": "Current temperature setpoint %.1f°C (age=%.1fs), but never received a setpoint" % (value_s, time.time()-tm_s)}
57
+                return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no data received or unknown monitoring"}
58
+            else:
59
+                tm = time.time()
60
+                dt = tm - tm_t
61
+                if value_t != value_s and dt > self.FOLLOW_REQUEST_ERROR:
62
+                    return {"status": nagios.Nagios.ERROR, "msg": "Requested setpoint unequal valve setpoint since %.1f°C (age=%.1fs)" % (value_s, time.time()-tm_s)}
63
+                elif value_t != value_s and dt > self.FOLLOW_REQUEST_WARNING:
64
+                    return {"status": nagios.Nagios.WARNING, "msg": "Requested setpoint unequal valve setpoint since %.1f°C (age=%.1fs)" % (value_s, time.time()-tm_s)}
65
+                return {"status": nagios.Nagios.OK, "msg": "Requested setpoint equal valve setpoint %.1f°C (age=%.1fs)" % (value_s, time.time()-tm_s)}
66
+        #
67
+        # BATTERY
68
+        #
69
+        elif key == "battery":
70
+            if self.battery is None:
71
+                return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no data received or unknown monitoring"}
72
+            elif self.battery < self.BATTERY_LVL_ERROR:
73
+                return {"status": nagios.Nagios.ERROR, "msg": "Battery level critical low (%.1f%%)" % self.battery}
74
+            elif self.battery < self.BATTERY_LVL_WARNING:
75
+                return {"status": nagios.Nagios.WARNING, "msg": "Battery level low (%.1f%%)" % self.battery}
76
+            else:
77
+                return {"status": nagios.Nagios.OK, "msg": "Battery okay (%.1f%%)" % self.battery}
56
 
78
 
57
 
79
 
58
 class group(object):
80
 class group(object):
95
                 self.target("current_heating_setpoint", payload["current_heating_setpoint"])
117
                 self.target("current_heating_setpoint", payload["current_heating_setpoint"])
96
             if message.topic == self.topic:
118
             if message.topic == self.topic:
97
                 self.state("current_heating_setpoint", payload["current_heating_setpoint"])
119
                 self.state("current_heating_setpoint", payload["current_heating_setpoint"])
120
+        if "battery" in payload and message.topic == self.topic:
121
+            self.battery = payload["battery"]
98
 
122
 
99
 
123
 
100
 class silvercrest_powerplug(base):
124
 class silvercrest_powerplug(base):

+ 4
- 2
z_server/z_protocol.py View File

3
 # from devdi.topic import topic_by_props
3
 # from devdi.topic import topic_by_props
4
 
4
 
5
 DID_FOLLOWS_HEATING_SETPOINT = 'current_heating_setpoint'
5
 DID_FOLLOWS_HEATING_SETPOINT = 'current_heating_setpoint'
6
+DID_BATTERY_LEVEL = 'battery'
6
 
7
 
7
 
8
 
8
 class server(socket_protocol.pure_json_protocol):
9
 class server(socket_protocol.pure_json_protocol):
15
         #              DID_FOLLOWS_HEATING_SETPOINT, 'current_heating_setpoint')
16
         #              DID_FOLLOWS_HEATING_SETPOINT, 'current_heating_setpoint')
16
         #
17
         #
17
         if not self.__comm_inst__.IS_CLIENT:
18
         if not self.__comm_inst__.IS_CLIENT:
18
-            self.register_callback(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, self.follow_heating_setpoint)
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_BATTERY_LEVEL, self.device_status)
19
 
21
 
20
-    def follow_heating_setpoint(self, msg):
22
+    def device_status(self, msg):
21
         if msg.get_status() == socket_protocol.STATUS_OKAY:
23
         if msg.get_status() == socket_protocol.STATUS_OKAY:
22
             try:
24
             try:
23
                 dev = self.__devices__.get_str(**msg.get_data())
25
                 dev = self.__devices__.get_str(**msg.get_data())

Loading…
Cancel
Save