From 3bead59b23672d102fc3056caf3056b38eca5926 Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Sun, 23 Aug 2026 13:04:16 +0200 Subject: [PATCH] Fix move to new messages --- orchestrateur/main.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/orchestrateur/main.py b/orchestrateur/main.py index a1161ad..e0bf694 100644 --- a/orchestrateur/main.py +++ b/orchestrateur/main.py @@ -108,6 +108,15 @@ def on_microwave_change(state: MicrowaveState, field: MicrowaveStateFields): # Send to LoRa device if state changed lora.send_reliable(payloads.lora_microwave_state(state.state), max_retries=5) + if field == MicrowaveStateFields.COOKING_STATE: + update_lcd_microwave_count() + if state.cooking_state in (CookingStates.DONE, CookingStates.STIRRING_REQUIRED, CookingStates.ALERT): + # Trigger buzzer for user attention + beats = 5 if state.cooking_state == CookingStates.ALERT else (1 if state.cooking_state == CookingStates.STIRRING_REQUIRED else 3) + buzzer.buzzer_siren(beatsNb=beats) + elif state.cooking_state == CookingStates.DONE and state.state == MicrowaveState.COOKING: + state.set_state(MicrowaveState.DONE) + print(f"[{state.microwave_id}] Cooking finished. Waiting for user to remove dish.") def set_cloud_alert(state: bool): """Setter for cloud_alert that triggers a display update when changed.""" @@ -322,20 +331,6 @@ async def process_messages_task(): data = msg["data"] if source == "LoRa": - if "new_cooking_state" in data.get("data", {}): - mw_id = data["data"].get("id") - n_state = data["data"].get("new_cooking_state") - print(f"[LoRa] Microwave {mw_id} state changed to: {n_state}") - - microwave_states[mw_id].set_cooking_state(n_state) - update_lcd_microwave_count() # Update the LCD with new microwave count - - if n_state in (CookingStates.DONE, CookingStates.STIRRING_REQUIRED, CookingStates.ALERT): - beats = 5 if n_state == CookingStates.ALERT else (1 if n_state == CookingStates.STIRRING_REQUIRED else 3) - buzzer.buzzer_siren(beatsNb=beats) - if n_state == CookingStates.IDLE and microwave_states.get(mw_id).state == MicrowaveState.COOKING: - microwave_states[mw_id].set_state(MicrowaveState.DONE) - print(f"[{mw_id}] Cooking finished. Waiting for user to remove dish.") if "action" in data.get("data", {}): if type(data["data"]) != dict: print(f"[LoRa] Invalid data format received: {data['data']}")