|
@@ -14,6 +14,10 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
14
|
14
|
class base(object):
|
15
|
15
|
FOLLOW_REQUEST_WARNING = 5 # Seconds, till warning comes up, if device does not follow the command
|
16
|
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
|
22
|
def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
|
19
|
23
|
self.topic = topic
|
|
@@ -23,6 +27,8 @@ class base(object):
|
23
|
27
|
#
|
24
|
28
|
self.__target_storage__ = {}
|
25
|
29
|
self.__state_storage__ = {}
|
|
30
|
+ #
|
|
31
|
+ self.battery = None
|
26
|
32
|
|
27
|
33
|
def __rx__(self, client, userdata, message):
|
28
|
34
|
pass
|
|
@@ -38,21 +44,37 @@ class base(object):
|
38
|
44
|
logger.debug("Device state identified: %s: %s", key, repr(value))
|
39
|
45
|
|
40
|
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
|
80
|
class group(object):
|
|
@@ -95,6 +117,8 @@ class brennenstuhl_heatingvalve(base):
|
95
|
117
|
self.target("current_heating_setpoint", payload["current_heating_setpoint"])
|
96
|
118
|
if message.topic == self.topic:
|
97
|
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
|
124
|
class silvercrest_powerplug(base):
|