From 3191ef06fca342724395e5aec28d7ac31ef9d2d6 Mon Sep 17 00:00:00 2001 From: Matteo Giaccone Date: Tue, 31 Oct 2023 14:46:03 +0100 Subject: [PATCH] Fix when MQTT message doesn't have time e.g. when adding users --- TelegramBot/main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/TelegramBot/main.py b/TelegramBot/main.py index 2b58f06..1f2e7cd 100644 --- a/TelegramBot/main.py +++ b/TelegramBot/main.py @@ -378,13 +378,14 @@ def on_mqtt_message(client, userdata, message): logging.error(e) return - message_time = int(_json.get('time')) + if _json.get('time'): + message_time = int(_json.get('time')) - # we skip multiple messages with the same timestamp - if message_time == last_mqtt_message: - same_timestamp_as_previous_message = True + # we skip multiple messages with the same timestamp + if message_time == last_mqtt_message: + same_timestamp_as_previous_message = True - last_mqtt_message = message_time + last_mqtt_message = message_time _type = _json.get('type') _access = _json.get('access')