From 0f576467e163b9b979509285a7d58c50639a4e13 Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Sun, 23 Aug 2026 16:19:09 +0200 Subject: [PATCH] send_reliably if cooking state update --- micro_ondes/esp_lora/main.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/micro_ondes/esp_lora/main.py b/micro_ondes/esp_lora/main.py index 1ddede2..331006b 100644 --- a/micro_ondes/esp_lora/main.py +++ b/micro_ondes/esp_lora/main.py @@ -49,19 +49,26 @@ PING_PAYLOAD = { "type": deviceTypes.DEVICE_TYPES["MICROWAVE"] } +last_cooking_update = {} + def send_cooking_update(state=None, start_time=None, estimated_remaining_time=None, paused=None): """Sends a flexible COOKING_UPDATE payload containing only populated fields.""" + global last_cooking_update + if not lora: return + + send_reliably = False payload = { "id": DEVICE_ID, "action": LoraCommands.COOKING_UPDATE } - if state is not None: + if state is not None and state != last_cooking_update.get("cooking_state"): payload["cooking_state"] = state + send_reliably = True if estimated_remaining_time is not None: payload["estimated_remaining_time"] = estimated_remaining_time if paused is not None: @@ -70,8 +77,11 @@ def send_cooking_update(state=None, start_time=None, estimated_remaining_time=No # Only transmit if at least one field beyond id and action was provided if len(payload) > 2: log(f"[LoRa] Sending COOKING_UPDATE payload: {payload}") - - lora.send(payload) + last_cooking_update = payload.copy() + if send_reliably: + lora.send_reliable(payload) + else: + lora.send(payload) def on_new_alert(alert: Alert):