From 97e72fdd56a808ecd037667e552bd52d9faf5599 Mon Sep 17 00:00:00 2001 From: gjkoolen Date: Mon, 10 Mar 2025 20:28:46 +0100 Subject: [PATCH] Support empty string Als er geen tijd wordt gespecificeerd, dan krijg je voortaan geen error melding meer. --- src/GlucoseCheck.py | 1 + src/TeleBot.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GlucoseCheck.py b/src/GlucoseCheck.py index a207a49..f87b9d8 100644 --- a/src/GlucoseCheck.py +++ b/src/GlucoseCheck.py @@ -126,6 +126,7 @@ def on_message(client, userdata, msg): #This runs everytime a mqtt message global last_bolus_time global last_bolus_type args = msg.payload.decode() + print(f"incoming /g command {args}") args_list = args.split(" ") if not args: #Empty string diff --git a/src/TeleBot.py b/src/TeleBot.py index c640e03..b42e419 100644 --- a/src/TeleBot.py +++ b/src/TeleBot.py @@ -35,12 +35,12 @@ async def subscribe(update: Update, context: ContextTypes.DEFAULT_TYPE): # #Mqtt.publish(send_topic,1) async def gluc_eat(update: Update, context: CallbackContext): #Runs on /ge command - args = "e " + ' '.join(context.args) #Joins message into string split by spaces and adds e to the front + args = "e" if not context.args else "e " + ' '.join(context.args) #Joins message into string split by spaces and adds e to the front current_user = User[str(update.effective_chat.id)].name #Checks wich user sends the message Mqtt.publish(send_topic_glucose + current_user.lower(), args) #Sends message with current_user added to the end of topic async def gluc_comp(update: Update, context: CallbackContext): #Runs on /gc command - args = "c " + ' '.join(context.args) #Joins message into string split by spaces and adds c to the front + args = "c" if not context.args else "c " + ' '.join(context.args) #Joins message into string split by spaces and adds c to the front current_user = User[str(update.effective_chat.id)].name #Checks wich user sends the message Mqtt.publish(send_topic_glucose + current_user.lower(), args) #Sends message with current_user added to the end of topic