|
@@ -14,7 +14,7 @@ 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", ]
|
|
17
|
+ FOLLOW_KEY = None
|
18
|
18
|
#
|
19
|
19
|
BATTERY_LVL_WARNING = 15
|
20
|
20
|
BATTERY_LVL_ERROR = 5
|
|
@@ -36,7 +36,30 @@ class base(object):
|
36
|
36
|
self.battery = None
|
37
|
37
|
|
38
|
38
|
def __rx__(self, client, userdata, message):
|
39
|
|
- pass
|
|
39
|
+ try:
|
|
40
|
+ payload = json.loads(message.payload)
|
|
41
|
+ except json.decoder.JSONDecodeError:
|
|
42
|
+ pass
|
|
43
|
+ else:
|
|
44
|
+ if type(payload) is dict:
|
|
45
|
+ #
|
|
46
|
+ # heartbeat
|
|
47
|
+ #
|
|
48
|
+ if message.topic == self.topic:
|
|
49
|
+ self.last_device_msg = time.time()
|
|
50
|
+ #
|
|
51
|
+ # follow setpoint
|
|
52
|
+ #
|
|
53
|
+ if self.FOLLOW_KEY is not None and self.FOLLOW_KEY in payload:
|
|
54
|
+ if message.topic == self.topic + '/set':
|
|
55
|
+ self.target(self.FOLLOW_KEY, payload[self.FOLLOW_KEY])
|
|
56
|
+ if message.topic == self.topic:
|
|
57
|
+ self.state(self.FOLLOW_KEY, payload[self.FOLLOW_KEY])
|
|
58
|
+ #
|
|
59
|
+ # battery level
|
|
60
|
+ #
|
|
61
|
+ if "battery" in payload and message.topic == self.topic:
|
|
62
|
+ self.battery = payload["battery"]
|
40
|
63
|
|
41
|
64
|
def target(self, key, value):
|
42
|
65
|
tm_t, value_t = self.__target_storage__.get(key, (0, None))
|
|
@@ -67,22 +90,24 @@ class base(object):
|
67
|
90
|
#
|
68
|
91
|
# FOLLOW SETPOINT
|
69
|
92
|
#
|
70
|
|
- elif key in self.FOLLOW_KEYS:
|
71
|
|
- tm_s, value_s = self.__state_storage__.get(key, (0, None))
|
|
93
|
+ elif key == 'follow_setpoint':
|
|
94
|
+ if self.FOLLOW_KEY is None:
|
|
95
|
+ return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exist, but does not follow any setpoint."}
|
|
96
|
+ tm_s, value_s = self.__state_storage__.get(self.FOLLOW_KEY, (0, None))
|
72
|
97
|
try:
|
73
|
|
- tm_t, value_t = self.__target_storage__[key]
|
|
98
|
+ tm_t, value_t = self.__target_storage__[self.FOLLOW_KEY]
|
74
|
99
|
except KeyError:
|
75
|
100
|
if value_s is not None:
|
76
|
|
- return {"status": nagios.Nagios.WARNING, "msg": "Current temperature setpoint %.1f°C (age=%.1fs), but never received a setpoint" % (value_s, time.time()-tm_s)}
|
77
|
|
- return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no data received or unknown monitoring"}
|
|
101
|
+ return {"status": nagios.Nagios.WARNING, "msg": "Current temperature setpoint %.1f°C (age=%.1fmin), but never received a setpoint" % (value_s, (time.time()-tm_s)/60)}
|
|
102
|
+ return {"status": nagios.Nagios.UNKNOWN, "msg": "Device exists, but no data received"}
|
78
|
103
|
else:
|
79
|
104
|
tm = time.time()
|
80
|
105
|
dt = tm - tm_t
|
81
|
106
|
if value_t != value_s and dt > self.FOLLOW_REQUEST_ERROR:
|
82
|
|
- return {"status": nagios.Nagios.ERROR, "msg": "Requested setpoint unequal valve setpoint since %.1f°C (age=%.1fs)" % (value_s, time.time()-tm_s)}
|
|
107
|
+ return {"status": nagios.Nagios.ERROR, "msg": "Requested setpoint unequal valve setpoint %.1f°C since %.1fmin" % (value_s, (time.time()-tm_s)/60)}
|
83
|
108
|
elif value_t != value_s and dt > self.FOLLOW_REQUEST_WARNING:
|
84
|
|
- return {"status": nagios.Nagios.WARNING, "msg": "Requested setpoint unequal valve setpoint since %.1f°C (age=%.1fs)" % (value_s, time.time()-tm_s)}
|
85
|
|
- return {"status": nagios.Nagios.OK, "msg": "Requested setpoint equal valve setpoint %.1f°C (age=%.1fs)" % (value_s, time.time()-tm_s)}
|
|
109
|
+ return {"status": nagios.Nagios.WARNING, "msg": "Requested setpoint unequal valve setpoint %.1f°C since %.1fmin" % (value_s, (time.time()-tm_s))}
|
|
110
|
+ return {"status": nagios.Nagios.OK, "msg": "Requested setpoint equal valve setpoint %.1f°C" % value_s}
|
86
|
111
|
#
|
87
|
112
|
# BATTERY
|
88
|
113
|
#
|
|
@@ -119,22 +144,7 @@ class tradfri_sw_br_ct(base):
|
119
|
144
|
|
120
|
145
|
|
121
|
146
|
class tradfri_button(base):
|
122
|
|
- def __rx__(self, client, userdata, message):
|
123
|
|
- try:
|
124
|
|
- payload = json.loads(message.payload)
|
125
|
|
- except json.decoder.JSONDecodeError:
|
126
|
|
- logger.warning("JSON decode error %s", self.topic)
|
127
|
|
- else:
|
128
|
|
- #
|
129
|
|
- # heartbeat
|
130
|
|
- #
|
131
|
|
- if message.topic == self.topic:
|
132
|
|
- self.last_device_msg = time.time()
|
133
|
|
- #
|
134
|
|
- # battery level
|
135
|
|
- #
|
136
|
|
- if "battery" in payload and message.topic == self.topic:
|
137
|
|
- self.battery = payload["battery"]
|
|
147
|
+ pass
|
138
|
148
|
|
139
|
149
|
|
140
|
150
|
class livarno_sw_br_ct(base):
|
|
@@ -144,31 +154,7 @@ class livarno_sw_br_ct(base):
|
144
|
154
|
class brennenstuhl_heatingvalve(base):
|
145
|
155
|
BATTERY_LVL_WARNING = 4
|
146
|
156
|
BATTERY_LVL_ERROR = 3
|
147
|
|
-
|
148
|
|
- def __rx__(self, client, userdata, message):
|
149
|
|
- try:
|
150
|
|
- payload = json.loads(message.payload)
|
151
|
|
- except json.decoder.JSONDecodeError:
|
152
|
|
- logger.warning("JSON decode error %s", self.topic)
|
153
|
|
- else:
|
154
|
|
- #
|
155
|
|
- # heartbeat
|
156
|
|
- #
|
157
|
|
- if message.topic == self.topic:
|
158
|
|
- self.last_device_msg = time.time()
|
159
|
|
- #
|
160
|
|
- # follow setpoint
|
161
|
|
- #
|
162
|
|
- if "current_heating_setpoint" in payload:
|
163
|
|
- if message.topic == self.topic + '/set':
|
164
|
|
- self.target("current_heating_setpoint", payload["current_heating_setpoint"])
|
165
|
|
- if message.topic == self.topic:
|
166
|
|
- self.state("current_heating_setpoint", payload["current_heating_setpoint"])
|
167
|
|
- #
|
168
|
|
- # battery level
|
169
|
|
- #
|
170
|
|
- if "battery" in payload and message.topic == self.topic:
|
171
|
|
- self.battery = payload["battery"]
|
|
157
|
+ FOLLOW_KEY = "current_heating_setpoint"
|
172
|
158
|
|
173
|
159
|
|
174
|
160
|
class silvercrest_powerplug(base):
|
|
@@ -176,22 +162,7 @@ class silvercrest_powerplug(base):
|
176
|
162
|
|
177
|
163
|
|
178
|
164
|
class silvercrest_motion_sensor(base):
|
179
|
|
- def __rx__(self, client, userdata, message):
|
180
|
|
- try:
|
181
|
|
- payload = json.loads(message.payload)
|
182
|
|
- except json.decoder.JSONDecodeError:
|
183
|
|
- logger.warning("JSON decode error %s", self.topic)
|
184
|
|
- else:
|
185
|
|
- #
|
186
|
|
- # heartbeat
|
187
|
|
- #
|
188
|
|
- if message.topic == self.topic:
|
189
|
|
- self.last_device_msg = time.time()
|
190
|
|
- #
|
191
|
|
- # battery level
|
192
|
|
- #
|
193
|
|
- if "battery" in payload and message.topic == self.topic:
|
194
|
|
- self.battery = payload["battery"]
|
|
165
|
+ pass
|
195
|
166
|
|
196
|
167
|
|
197
|
168
|
class my_powerplug(base):
|