Don't retry upload unless is a nextion failure

This commit is contained in:
Edward Firmo
2024-02-06 11:12:43 +01:00
parent 6b03d7c44f
commit 7629fa086b

View File

@@ -115,6 +115,11 @@ globals:
restore_value: false restore_value: false
initial_value: '"${nextion_update_url}"' initial_value: '"${nextion_update_url}"'
- id: tft_upload_result
type: esphome::nextion::Nextion::TFTUploadResult
restore_value: false
initial_value: 'esphome::nextion::Nextion::TFTUploadResult::Unknown'
script: script:
- id: nextion_uart_command - id: nextion_uart_command
mode: queued mode: queued
@@ -149,11 +154,8 @@ script:
- lambda: |- - lambda: |-
static const char *const TAG = "addon_upload_tft.script.nextion_upload"; static const char *const TAG = "addon_upload_tft.script.nextion_upload";
ESP_LOGD(TAG, "Starting TFT upload..."); ESP_LOGD(TAG, "Starting TFT upload...");
esphome::nextion::Nextion::TFTUploadResult upload_result = disp1->upload_tft(); id(tft_upload_result) = disp1->upload_tft();
if (upload_result == esphome::nextion::Nextion::TFTUploadResult::OK) ESP_LOGD(TAG, "TFT upload: %s", esphome::nextion::Nextion::TFTUploadResultToString(id(tft_upload_result)));
App.safe_reboot();
else
ESP_LOGE(TAG, "TFT upload failed: %s", esphome::nextion::Nextion::TFTUploadResultToString(upload_result));
- id: open_upload_dialog - id: open_upload_dialog
mode: restart mode: restart
@@ -486,6 +488,7 @@ script:
- lambda: |- - lambda: |-
char update_msg[128]; char update_msg[128];
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps", id(tft_upload_attempt), tf_uart->get_baud_rate()); sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps", id(tft_upload_attempt), tf_uart->get_baud_rate());
id(tft_upload_result) = esphome::nextion::Nextion::TFTUploadResult::Unknown;
report_upload_progress->execute(update_msg); report_upload_progress->execute(update_msg);
- script.wait: report_upload_progress - script.wait: report_upload_progress
- wait_until: - wait_until:
@@ -496,9 +499,21 @@ script:
- script.wait: nextion_upload - script.wait: nextion_upload
- lambda: |- - lambda: |-
char update_msg[128]; char update_msg[128];
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps failed!", id(tft_upload_attempt), tf_uart->get_baud_rate()); sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps returned: %s", id(tft_upload_attempt),
tf_uart->get_baud_rate(), esphome::nextion::Nextion::TFTUploadResultToString(id(tft_upload_result)));
report_upload_progress->execute(update_msg); report_upload_progress->execute(update_msg);
- script.wait: report_upload_progress - script.wait: report_upload_progress
- if:
condition:
not:
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::Unknown;
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::UploadInProgress;
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::NextionError_PreparationFailed;
- lambda: return id(tft_upload_result) == esphome::nextion::Nextion::TFTUploadResult::NextionError_InvalidResponse;
then:
- delay: 5s
- lambda: |-
App.safe_reboot();
select: select:
- id: tft_file_branch - id: tft_file_branch