Change TFT selector's saving on power cycle

This commit is contained in:
Edward Firmo
2024-01-04 02:50:29 +01:00
parent e0d821a7ed
commit 602bc03d02
4 changed files with 36 additions and 12 deletions

View File

@@ -65,6 +65,20 @@ display:
tft_url: ${nextion_update_url}
exit_reparse_on_start: true
esphome:
on_boot:
- priority: 605.0
then:
- lambda: |-
static const char *const TAG = "addon_upload_tft.esphome.on_boot";
ESP_LOGD(TAG, "Restoring TFT file selectors");
- select.set_index:
id: tft_file_branch
index: !lambda return id(tft_branch);
- select.set_index:
id: tft_file_model
index: !lambda return id(tft_model);
globals:
- id: baud_rate_original
type: uint
@@ -76,11 +90,21 @@ globals:
restore_value: false
initial_value: ${upload_tft_baud_rate}
- id: tft_branch
type: uint
restore_value: true
initial_value: '0'
- id: tft_is_valid
type: bool
restore_value: false
initial_value: 'false'
- id: tft_model
type: uint
restore_value: true
initial_value: '0'
- id: tft_upload_try
type: uint
restore_value: false
@@ -188,12 +212,11 @@ script:
- id: set_tft_file
mode: restart
parameters:
model: string
branch: string
then:
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.set_tft_file";
std::string model = tft_file_model->state;
std::string branch = tft_file_branch->state;
ESP_LOGD(TAG, "A new TFT was selected:");
ESP_LOGD(TAG, " Model: %s", model.c_str());
ESP_LOGD(TAG, " Branch: %s", branch.c_str());
@@ -1196,7 +1219,7 @@ script:
- script.wait: report_upload_progress
select:
- id: tft_file
- id: tft_file_model
name: ${device_name} Update TFT display - Model
platform: template
options:
@@ -1210,14 +1233,14 @@ select:
- "NSPanel US Landscape (CJK languages)"
initial_option: "Use nextion_update_url"
optimistic: true
restore_value: true
restore_value: false
internal: false
entity_category: config
disabled_by_default: false
icon: mdi:file-sync
set_action:
- lambda: set_tft_file->execute(x.c_str(), tft_file_branch->state.c_str());
- script.wait: set_tft_file
- lambda: if (tft_file_model->active_index().has_value()) id(tft_model) = tft_file_model->active_index().value();
- script.execute: set_tft_file
- id: tft_file_branch
name: ${device_name} Update TFT display - Branch
@@ -1228,14 +1251,14 @@ select:
- "dev"
initial_option: "main"
optimistic: true
restore_value: true
restore_value: false
internal: false
entity_category: config
disabled_by_default: true
icon: mdi:file-sync
set_action:
- lambda: set_tft_file->execute(tft_file->state.c_str(), x.c_str());
- script.wait: set_tft_file
- lambda: if (tft_file_branch->active_index().has_value()) id(tft_branch) = tft_file_branch->active_index().value();
- script.execute: set_tft_file
sensor:
- id: !extend display_mode

View File

@@ -22,6 +22,7 @@ external_components:
- source: github://pr#6051 # Remove this when that PR is released (Hopefully v2024.1.0)
components:
- nextion
refresh: 300s
##### ESPHOME CONFIGURATION #####
esphome:
@@ -34,7 +35,7 @@ esphome:
- priority: 600.0 # This is where most sensors are set up.
then:
- lambda: |-
static const char *const TAG = "on_boot";
static const char *const TAG = "esphome.on_boot";
ESP_LOGD(TAG, "After boot check-up starting");
set_baud_rate->execute(stoi(baud_rate->state), true);
- select.set:

View File

@@ -62,7 +62,7 @@ script:
select:
- id: !extend tft_file
- id: !extend tft_file_model
platform: template
options:
- "NSPanel Blank"

Binary file not shown.