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} tft_url: ${nextion_update_url}
exit_reparse_on_start: true 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: globals:
- id: baud_rate_original - id: baud_rate_original
type: uint type: uint
@@ -76,11 +90,21 @@ globals:
restore_value: false restore_value: false
initial_value: ${upload_tft_baud_rate} initial_value: ${upload_tft_baud_rate}
- id: tft_branch
type: uint
restore_value: true
initial_value: '0'
- id: tft_is_valid - id: tft_is_valid
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: 'false'
- id: tft_model
type: uint
restore_value: true
initial_value: '0'
- id: tft_upload_try - id: tft_upload_try
type: uint type: uint
restore_value: false restore_value: false
@@ -188,12 +212,11 @@ script:
- id: set_tft_file - id: set_tft_file
mode: restart mode: restart
parameters:
model: string
branch: string
then: then:
- lambda: |- - lambda: |-
static const char *const TAG = "addon_upload_tft.script.set_tft_file"; 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, "A new TFT was selected:");
ESP_LOGD(TAG, " Model: %s", model.c_str()); ESP_LOGD(TAG, " Model: %s", model.c_str());
ESP_LOGD(TAG, " Branch: %s", branch.c_str()); ESP_LOGD(TAG, " Branch: %s", branch.c_str());
@@ -1196,7 +1219,7 @@ script:
- script.wait: report_upload_progress - script.wait: report_upload_progress
select: select:
- id: tft_file - id: tft_file_model
name: ${device_name} Update TFT display - Model name: ${device_name} Update TFT display - Model
platform: template platform: template
options: options:
@@ -1210,14 +1233,14 @@ select:
- "NSPanel US Landscape (CJK languages)" - "NSPanel US Landscape (CJK languages)"
initial_option: "Use nextion_update_url" initial_option: "Use nextion_update_url"
optimistic: true optimistic: true
restore_value: true restore_value: false
internal: false internal: false
entity_category: config entity_category: config
disabled_by_default: false disabled_by_default: false
icon: mdi:file-sync icon: mdi:file-sync
set_action: set_action:
- lambda: set_tft_file->execute(x.c_str(), tft_file_branch->state.c_str()); - lambda: if (tft_file_model->active_index().has_value()) id(tft_model) = tft_file_model->active_index().value();
- script.wait: set_tft_file - script.execute: set_tft_file
- id: tft_file_branch - id: tft_file_branch
name: ${device_name} Update TFT display - Branch name: ${device_name} Update TFT display - Branch
@@ -1228,14 +1251,14 @@ select:
- "dev" - "dev"
initial_option: "main" initial_option: "main"
optimistic: true optimistic: true
restore_value: true restore_value: false
internal: false internal: false
entity_category: config entity_category: config
disabled_by_default: true disabled_by_default: true
icon: mdi:file-sync icon: mdi:file-sync
set_action: set_action:
- lambda: set_tft_file->execute(tft_file->state.c_str(), x.c_str()); - lambda: if (tft_file_branch->active_index().has_value()) id(tft_branch) = tft_file_branch->active_index().value();
- script.wait: set_tft_file - script.execute: set_tft_file
sensor: sensor:
- id: !extend display_mode - 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) - source: github://pr#6051 # Remove this when that PR is released (Hopefully v2024.1.0)
components: components:
- nextion - nextion
refresh: 300s
##### ESPHOME CONFIGURATION ##### ##### ESPHOME CONFIGURATION #####
esphome: esphome:
@@ -34,7 +35,7 @@ esphome:
- priority: 600.0 # This is where most sensors are set up. - priority: 600.0 # This is where most sensors are set up.
then: then:
- lambda: |- - lambda: |-
static const char *const TAG = "on_boot"; static const char *const TAG = "esphome.on_boot";
ESP_LOGD(TAG, "After boot check-up starting"); ESP_LOGD(TAG, "After boot check-up starting");
set_baud_rate->execute(stoi(baud_rate->state), true); set_baud_rate->execute(stoi(baud_rate->state), true);
- select.set: - select.set:

View File

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

Binary file not shown.