Skip sending implicit new state
This commit is contained in:
@@ -346,6 +346,7 @@ async def lora_process_task():
|
||||
if alert:
|
||||
alert.timestamp = data.get("timestamp", time.time())
|
||||
alert_manager.add_alert(alert)
|
||||
microwave_state = MicrowaveState.ALERT
|
||||
|
||||
elif action == LoraCommands.MICROVAVE_STATE_UPDATE:
|
||||
new_state = data.get("new_microwave_state")
|
||||
|
||||
@@ -104,7 +104,7 @@ def on_microwave_change(state: MicrowaveState, field: MicrowaveStateFields):
|
||||
if field != MicrowaveStateFields.STATE: # No external screen or lcd uses this field, so we can skip updates for it
|
||||
notify_display_update()
|
||||
|
||||
if field == MicrowaveStateFields.STATE and state.state in (MicrowaveState.IDLE, MicrowaveState.DONE, MicrowaveState.ANALYZING, MicrowaveState.WAITING_FOR_CLOUD, MicrowaveState.ALERT):
|
||||
if field == MicrowaveStateFields.STATE and state.state in (MicrowaveState.IDLE, MicrowaveState.DONE, MicrowaveState.ANALYZING, MicrowaveState.WAITING_FOR_CLOUD):
|
||||
# Send to LoRa device if state changed
|
||||
lora.send_reliable(payloads.lora_microwave_state(state.state), max_retries=5)
|
||||
|
||||
@@ -472,7 +472,7 @@ async def on_new_alert(alert: Alert):
|
||||
|
||||
response.raise_for_status()
|
||||
res_json = response.json()
|
||||
print(f"[Alert Handling] Alert sent to cloud: {alert_dict}, Response: {res_json}")
|
||||
log(f"[Alert Handling] Alert sent to cloud: {alert_dict}, Response: {res_json}")
|
||||
|
||||
if not alert.redistributed: # If not redistributed from microwaves
|
||||
# Send the alert to the lora device
|
||||
@@ -480,7 +480,6 @@ async def on_new_alert(alert: Alert):
|
||||
print(f"[Alert Handling] Sending alert to LoRa device: {payload}")
|
||||
if lora.send_reliable(payload):
|
||||
microwave_states["2"].set_cooking_state(CookingStates.ALERT)
|
||||
buzzer.buzzer_siren(beatsNb=5)
|
||||
|
||||
# --- HARDWARE CONTROLLERS ---
|
||||
def _stop_hardware(microwave_id: str):
|
||||
@@ -669,7 +668,7 @@ async def request_cloud_cooking_plan(microwave_id, sensors_data):
|
||||
microwave_states[microwave_id].set_state(MicrowaveState.DONE)
|
||||
|
||||
if not res_json['is_safe']: # The cooking area is not safe, raise an alert
|
||||
alert = Alert(AlertType.COOKING_SAFETY, res_json['warning_message'])
|
||||
alert = Alert(AlertType.COOKING_SAFETY, res_json['warning_message'], redistributed=False)
|
||||
alert_manager.add_alert(alert)
|
||||
else:
|
||||
alert = Alert(AlertType.ERROR, f"Cloud API error for microwave {microwave_id}: {res_json['error']}")
|
||||
|
||||
Reference in New Issue
Block a user