Compare commits
No commits in common. "bd5d8605a1cd465d74be8b6cbc41d81d089607b3" and "3594c2fc9f08570daedc3ed0a43325dc4e010222" have entirely different histories.
bd5d8605a1
...
3594c2fc9f
@ -1 +1 @@
|
|||||||
Subproject commit 0f5ad2a18a72191e4fbf5ec49c5a41552f0c2296
|
Subproject commit 0620158064ab5bbb932c2afb9f557cf0b18b37e3
|
@ -247,57 +247,3 @@ class audio_status(base):
|
|||||||
|
|
||||||
class remote(base):
|
class remote(base):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class my_ambient(base):
|
|
||||||
KEY_TEMPERATURE = 'temperature'
|
|
||||||
KEY_PRESSURE = 'pressure'
|
|
||||||
KEY_HUMIDITY = 'humidity'
|
|
||||||
#
|
|
||||||
LAST_MSG_WARNING = 20 * 60
|
|
||||||
LAST_MSG_ERROR = 30 * 60
|
|
||||||
|
|
||||||
def __init__(self, mqtt_client: mqtt.mqtt_client, topic):
|
|
||||||
super().__init__(mqtt_client, topic)
|
|
||||||
self.__last_value_rx__ = {
|
|
||||||
self.KEY_HUMIDITY: None,
|
|
||||||
self.KEY_PRESSURE: None,
|
|
||||||
self.KEY_TEMPERATURE: None
|
|
||||||
}
|
|
||||||
|
|
||||||
def __rx__(self, client, userdata, message):
|
|
||||||
try:
|
|
||||||
payload = json.loads(message.payload)
|
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
key = message.topic.split('/')[-1]
|
|
||||||
if key in self.__last_value_rx__:
|
|
||||||
self.__last_value_rx__[key] = time.time()
|
|
||||||
return super().__rx__(client, userdata, message)
|
|
||||||
|
|
||||||
def status(self, key):
|
|
||||||
if key == DID_HEARTBEAT:
|
|
||||||
status = nagios.Nagios.OK
|
|
||||||
msg = ""
|
|
||||||
for key in self.__last_value_rx__:
|
|
||||||
last_value_rx = self.__last_value_rx__[key]
|
|
||||||
if len(msg) != 0:
|
|
||||||
msg += "; "
|
|
||||||
if last_value_rx is None:
|
|
||||||
target_status = nagios.Nagios.UNKNOWN
|
|
||||||
msg += "%s (never)" % key
|
|
||||||
else:
|
|
||||||
dt = time.time() - last_value_rx
|
|
||||||
msg += "%s (%.1f min ago)" % (key, dt / 60)
|
|
||||||
if dt > self.LAST_MSG_ERROR:
|
|
||||||
target_status = nagios.Nagios.ERROR
|
|
||||||
elif dt > self.LAST_MSG_WARNING:
|
|
||||||
target_status = nagios.Nagios.WARNING
|
|
||||||
else:
|
|
||||||
target_status = nagios.Nagios.OK
|
|
||||||
if target_status > status:
|
|
||||||
status = target_status
|
|
||||||
return self.__nagios_return__(DID_HEARTBEAT, status, msg)
|
|
||||||
else:
|
|
||||||
return super().status(key)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user