send_reliably if cooking state update
This commit is contained in:
@@ -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,7 +77,10 @@ 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}")
|
||||
|
||||
last_cooking_update = payload.copy()
|
||||
if send_reliably:
|
||||
lora.send_reliable(payload)
|
||||
else:
|
||||
lora.send(payload)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user