Reduce variables stored to flash
This commit is contained in:
@@ -90,20 +90,20 @@ globals:
|
|||||||
restore_value: false
|
restore_value: false
|
||||||
initial_value: ${upload_tft_baud_rate}
|
initial_value: ${upload_tft_baud_rate}
|
||||||
|
|
||||||
- id: tft_branch
|
#- id: tft_branch
|
||||||
type: uint
|
# type: uint
|
||||||
restore_value: true
|
# restore_value: true
|
||||||
initial_value: '0'
|
# 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
|
#- id: tft_model
|
||||||
type: uint
|
# type: uint
|
||||||
restore_value: true
|
# restore_value: true
|
||||||
initial_value: '0'
|
# initial_value: '0'
|
||||||
|
|
||||||
- id: tft_upload_attempt
|
- id: tft_upload_attempt
|
||||||
type: uint
|
type: uint
|
||||||
@@ -216,15 +216,15 @@ script:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
static const char *const TAG = "addon_upload_tft.script.restore_settings";
|
static const char *const TAG = "addon_upload_tft.script.restore_settings";
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Restoring TFT file branch selector to index %u", id(tft_branch));
|
// ESP_LOGD(TAG, "Restoring TFT file branch selector to index %u", id(tft_branch));
|
||||||
auto tft_file_branch_call = id(tft_file_branch).make_call();
|
// auto tft_file_branch_call = id(tft_file_branch).make_call();
|
||||||
tft_file_branch_call.set_index(id(tft_branch));
|
// tft_file_branch_call.set_index(id(tft_branch));
|
||||||
tft_file_branch_call.perform();
|
// tft_file_branch_call.perform();
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Restoring TFT file model selector to index %u", id(tft_model));
|
// ESP_LOGD(TAG, "Restoring TFT file model selector to index %u", id(tft_model));
|
||||||
auto tft_file_model_call = id(tft_file_model).make_call();
|
// auto tft_file_model_call = id(tft_file_model).make_call();
|
||||||
tft_file_model_call.set_index(id(tft_model));
|
// tft_file_model_call.set_index(id(tft_model));
|
||||||
tft_file_model_call.perform();
|
// tft_file_model_call.perform();
|
||||||
|
|
||||||
- id: set_tft_file
|
- id: set_tft_file
|
||||||
mode: restart
|
mode: restart
|
||||||
@@ -241,10 +241,10 @@ script:
|
|||||||
ESP_LOGD(TAG, "TFT URL set:");
|
ESP_LOGD(TAG, "TFT URL set:");
|
||||||
ESP_LOGD(TAG, " Branch: %s", branch.c_str());
|
ESP_LOGD(TAG, " Branch: %s", branch.c_str());
|
||||||
ESP_LOGD(TAG, " Model: %s", model.c_str());
|
ESP_LOGD(TAG, " Model: %s", model.c_str());
|
||||||
if (id(is_restored_settings) and tft_file_branch->active_index().has_value())
|
// if (id(is_restored_settings) and tft_file_branch->active_index().has_value())
|
||||||
id(tft_branch) = tft_file_branch->active_index().value();
|
// id(tft_branch) = tft_file_branch->active_index().value();
|
||||||
if (id(is_restored_settings) and tft_file_model->active_index().has_value())
|
// if (id(is_restored_settings) and tft_file_model->active_index().has_value())
|
||||||
id(tft_model) = tft_file_model->active_index().value();
|
// id(tft_model) = tft_file_model->active_index().value();
|
||||||
|
|
||||||
if (id(is_uploading_tft))
|
if (id(is_uploading_tft))
|
||||||
ESP_LOGW(TAG, " TFT Upload in progress.");
|
ESP_LOGW(TAG, " TFT Upload in progress.");
|
||||||
@@ -1227,7 +1227,7 @@ select:
|
|||||||
- "dev"
|
- "dev"
|
||||||
initial_option: "v${version}"
|
initial_option: "v${version}"
|
||||||
optimistic: true
|
optimistic: true
|
||||||
restore_value: true
|
restore_value: false
|
||||||
internal: true
|
internal: true
|
||||||
entity_category: config
|
entity_category: config
|
||||||
disabled_by_default: true
|
disabled_by_default: true
|
||||||
|
|||||||
@@ -453,12 +453,12 @@ api:
|
|||||||
reset_timer: bool
|
reset_timer: bool
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
if (current_page->state == "screensaver") disp1->goto_page(id(wakeup_page_id));
|
if (current_page->state == "screensaver") disp1->goto_page(wakeup_page_name->state.c_str());
|
||||||
if (reset_timer)
|
if (reset_timer)
|
||||||
timer_reset_all->execute(id(page_names)[id(wakeup_page_id)].c_str());
|
timer_reset_all->execute(wakeup_page_name->state.c_str());
|
||||||
else {
|
else {
|
||||||
timer_sleep->execute(id(page_names)[id(wakeup_page_id)].c_str(), int(timeout_sleep->state));
|
timer_sleep->execute(wakeup_page_name->state.c_str(), int(timeout_sleep->state));
|
||||||
timer_dim->execute(id(page_names)[id(wakeup_page_id)].c_str(), int(timeout_dim->state));
|
timer_dim->execute(wakeup_page_name->state.c_str(), int(timeout_dim->state));
|
||||||
}
|
}
|
||||||
|
|
||||||
#### Service to set the entities ####
|
#### Service to set the entities ####
|
||||||
@@ -732,12 +732,6 @@ display:
|
|||||||
|
|
||||||
##### START - GLOBALS CONFIGURATION #####
|
##### START - GLOBALS CONFIGURATION #####
|
||||||
globals:
|
globals:
|
||||||
##### Wake-up page id #####
|
|
||||||
- id: wakeup_page_id
|
|
||||||
type: uint
|
|
||||||
restore_value: true
|
|
||||||
initial_value: '0'
|
|
||||||
|
|
||||||
##### Wi-Fi timeout #####
|
##### Wi-Fi timeout #####
|
||||||
- id: wifi_timeout
|
- id: wifi_timeout
|
||||||
type: uint
|
type: uint
|
||||||
@@ -762,12 +756,6 @@ globals:
|
|||||||
restore_value: false
|
restore_value: false
|
||||||
initial_value: 'false'
|
initial_value: 'false'
|
||||||
|
|
||||||
##### Is settings restored ####
|
|
||||||
- id: is_restored_settings
|
|
||||||
type: bool
|
|
||||||
restore_value: false
|
|
||||||
initial_value: 'false'
|
|
||||||
|
|
||||||
##### Is boot sequence completed? #####
|
##### Is boot sequence completed? #####
|
||||||
- id: setup_sequence_completed
|
- id: setup_sequence_completed
|
||||||
type: bool
|
type: bool
|
||||||
@@ -937,6 +925,11 @@ globals:
|
|||||||
"confirm"
|
"confirm"
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
- id: framework
|
||||||
|
type: uint8_t
|
||||||
|
restore_value: false
|
||||||
|
initial_value: '0' # 0 = unknown, 1 = Arduino, 2 = ESP-IDF
|
||||||
|
|
||||||
##### START - BINARY SENSOR CONFIGURATION #####
|
##### START - BINARY SENSOR CONFIGURATION #####
|
||||||
binary_sensor:
|
binary_sensor:
|
||||||
|
|
||||||
@@ -1073,11 +1066,32 @@ binary_sensor:
|
|||||||
|
|
||||||
##### START - BUTTON CONFIGURATION #####
|
##### START - BUTTON CONFIGURATION #####
|
||||||
button:
|
button:
|
||||||
|
###### Factory Reset button #####
|
||||||
|
- name: ${name} Factory reset
|
||||||
|
platform: factory_reset
|
||||||
|
id: nspanel_factory_reset
|
||||||
|
internal: false
|
||||||
|
disabled_by_default: true
|
||||||
|
icon: mdi:restart-alert
|
||||||
|
|
||||||
###### REBOOT BUTTON #####
|
###### REBOOT BUTTON #####
|
||||||
- name: ${name} Restart
|
- name: ${name} Restart
|
||||||
platform: restart
|
platform: restart
|
||||||
id: restart_nspanel
|
id: restart_nspanel
|
||||||
|
|
||||||
|
###### Power cycle Nextion Display ######
|
||||||
|
- name: ${name} Nextion display - Power cycle
|
||||||
|
id: screen_power_cycle
|
||||||
|
platform: template
|
||||||
|
internal: false
|
||||||
|
disabled_by_default: true
|
||||||
|
icon: mdi:power-cycle
|
||||||
|
entity_category: diagnostic
|
||||||
|
on_press:
|
||||||
|
- switch.turn_off: screen_power
|
||||||
|
- delay: 1s
|
||||||
|
- switch.turn_on: screen_power
|
||||||
|
|
||||||
##### START - NUMBER CONFIGURATION #####
|
##### START - NUMBER CONFIGURATION #####
|
||||||
number:
|
number:
|
||||||
##### SCREEN BRIGHTNESS #####
|
##### SCREEN BRIGHTNESS #####
|
||||||
@@ -1270,9 +1284,7 @@ select:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
static const char *const TAG = "select.wakeup_page_name";
|
static const char *const TAG = "select.wakeup_page_name";
|
||||||
ESP_LOGD(TAG, "New wake-up page selected: %s", x.c_str());
|
ESP_LOGD(TAG, "New wake-up page selected: %s", x.c_str());
|
||||||
if (id(is_restored_settings))
|
page_screensaver->execute();
|
||||||
set_page_id->execute("wakeup_page_id", x.c_str());
|
|
||||||
- script.execute: page_screensaver
|
|
||||||
|
|
||||||
##### START - SENSOR CONFIGURATION #####
|
##### START - SENSOR CONFIGURATION #####
|
||||||
sensor:
|
sensor:
|
||||||
@@ -1488,7 +1500,7 @@ switch:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
if (id(setup_sequence_completed)) {
|
if (id(setup_sequence_completed)) {
|
||||||
nextion_init->publish_state(disp1->is_setup());
|
nextion_init->publish_state(disp1->is_setup());
|
||||||
disp1->goto_page(id(wakeup_page_id));
|
disp1->goto_page(wakeup_page_name->state.c_str());
|
||||||
}
|
}
|
||||||
on_turn_off:
|
on_turn_off:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
@@ -1521,6 +1533,26 @@ switch:
|
|||||||
##### START - TEXT SENSOR CONFIGURATION #####
|
##### START - TEXT SENSOR CONFIGURATION #####
|
||||||
text_sensor:
|
text_sensor:
|
||||||
|
|
||||||
|
##### Device name - Used for the Blueprint to identify service names when device is renamed
|
||||||
|
- id: device_name
|
||||||
|
name: ${name} Device name
|
||||||
|
internal: false
|
||||||
|
platform: template
|
||||||
|
lambda: |-
|
||||||
|
return {"${name}"};
|
||||||
|
filters:
|
||||||
|
- to_lower:
|
||||||
|
- lambda: |-
|
||||||
|
std::replace(x.begin(), x.end(), ' ', '_');
|
||||||
|
return x;
|
||||||
|
- substitute:
|
||||||
|
- "- -> _"
|
||||||
|
- "___ -> _"
|
||||||
|
- "__ -> _"
|
||||||
|
- "__ -> _"
|
||||||
|
- "__ -> _"
|
||||||
|
- "__ -> _"
|
||||||
|
|
||||||
##### Entity Id of the entity displayed on the detailed pages
|
##### Entity Id of the entity displayed on the detailed pages
|
||||||
- name: ${name} Detailed Entity
|
- name: ${name} Detailed Entity
|
||||||
id: detailed_entity
|
id: detailed_entity
|
||||||
@@ -1938,9 +1970,9 @@ script:
|
|||||||
- rtttl.play:
|
- rtttl.play:
|
||||||
rtttl: 'two short:d=4,o=5,b=100:16e6,16e6'
|
rtttl: 'two short:d=4,o=5,b=100:16e6,16e6'
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
ESP_LOGD("script.global_settings", "Jump to wake-up page: %s", id(page_names)[id(wakeup_page_id)].c_str());
|
ESP_LOGD("script.global_settings", "Jump to wake-up page: %s", wakeup_page_name->state.c_str());
|
||||||
disp1->goto_page(id(wakeup_page_id));
|
disp1->goto_page(wakeup_page_name->state.c_str());
|
||||||
timer_reset_all->execute(id(page_names)[id(wakeup_page_id)].c_str());
|
timer_reset_all->execute(wakeup_page_name->state.c_str());
|
||||||
|
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
ESP_LOGV("script.global_settings", "Finished");
|
ESP_LOGV("script.global_settings", "Finished");
|
||||||
@@ -2051,14 +2083,9 @@ script:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
static const char *const TAG = "script.page_blank";
|
static const char *const TAG = "script.page_blank";
|
||||||
ESP_LOGV(TAG, "Construct blank page");
|
ESP_LOGV(TAG, "Construct blank page");
|
||||||
std::string framework = "unknown";
|
|
||||||
#ifdef ARDUINO
|
|
||||||
framework = "arduino";
|
|
||||||
#elif defined(USE_ESP_IDF)
|
|
||||||
framework = "esp-idf";
|
|
||||||
#endif
|
|
||||||
disp1->set_component_text_printf("esp_version", "ESP: ${version}"); // ESPHome version
|
disp1->set_component_text_printf("esp_version", "ESP: ${version}"); // ESPHome version
|
||||||
disp1->set_component_text_printf("framework", framework.c_str()); // ESPHome framework
|
disp1->set_component_text_printf("framework", "%s", id(framework) == 1 ? "Arduino" :
|
||||||
|
(id(framework) == 2 ? "ESP-IDF" : "Unknown")); // ESPHome framework
|
||||||
disp1->send_command_printf("tm_esphome.en=0");
|
disp1->send_command_printf("tm_esphome.en=0");
|
||||||
|
|
||||||
- id: page_boot
|
- id: page_boot
|
||||||
@@ -2069,15 +2096,11 @@ script:
|
|||||||
ESP_LOGV(TAG, "Construct boot page");
|
ESP_LOGV(TAG, "Construct boot page");
|
||||||
set_brightness->execute(100);
|
set_brightness->execute(100);
|
||||||
|
|
||||||
std::string framework = "unknown";
|
|
||||||
#ifdef ARDUINO
|
|
||||||
framework = "arduino";
|
|
||||||
#elif defined(USE_ESP_IDF)
|
|
||||||
framework = "esp-idf";
|
|
||||||
#endif
|
|
||||||
disp1->set_component_text_printf("esph_version", "${version}"); // ESPHome version
|
disp1->set_component_text_printf("esph_version", "${version}"); // ESPHome version
|
||||||
disp1->set_component_text_printf("framework", framework.c_str()); // ESPHome framework
|
disp1->set_component_text_printf("framework", "%s", id(framework) == 1 ? "Arduino" :
|
||||||
disp1->show_component("bt_reboot");
|
(id(framework) == 2 ? "ESP-IDF" : "Unknown")); // ESPHome framework
|
||||||
|
disp1->send_command_printf("tm_esphome.en=0");
|
||||||
|
// disp1->show_component("bt_reboot");
|
||||||
|
|
||||||
- id: page_buttonpage
|
- id: page_buttonpage
|
||||||
mode: restart
|
mode: restart
|
||||||
@@ -2270,7 +2293,8 @@ script:
|
|||||||
if (current_page->state == "screensaver" and not id(is_uploading_tft)) {
|
if (current_page->state == "screensaver" and not id(is_uploading_tft)) {
|
||||||
static const char *const TAG = "script.page_screensaver";
|
static const char *const TAG = "script.page_screensaver";
|
||||||
ESP_LOGV(TAG, "Updating screensaver page");
|
ESP_LOGV(TAG, "Updating screensaver page");
|
||||||
disp1->send_command_printf("back_page_id=%i", id(wakeup_page_id));
|
set_page_id->execute("back_page_id", wakeup_page_name->state.c_str());
|
||||||
|
// disp1->send_command_printf("back_page_id=%i", id(wakeup_page_id));
|
||||||
if (id(screensaver_display_time)) {
|
if (id(screensaver_display_time)) {
|
||||||
disp1->show_component("text");
|
disp1->show_component("text");
|
||||||
set_component_color->execute("screensaver.text",id(screensaver_display_time_color));
|
set_component_color->execute("screensaver.text",id(screensaver_display_time_color));
|
||||||
@@ -2445,16 +2469,22 @@ script:
|
|||||||
static const char *const TAG = "script.restore_settings";
|
static const char *const TAG = "script.restore_settings";
|
||||||
ESP_LOGD(TAG, "Restoring settings");
|
ESP_LOGD(TAG, "Restoring settings");
|
||||||
|
|
||||||
|
#ifdef ARDUINO
|
||||||
|
id(framework) = 1;
|
||||||
|
#elif defined(USE_ESP_IDF)
|
||||||
|
id(framework) = 2;
|
||||||
|
#endif
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Restoring baud rate");
|
ESP_LOGV(TAG, "Restoring baud rate");
|
||||||
set_baud_rate->execute(stoi(baud_rate->state), true);
|
set_baud_rate->execute(stoi(baud_rate->state), true);
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Restoring wake-up page selector");
|
// ESP_LOGV(TAG, "Restoring wake-up page selector");
|
||||||
auto wakeup_page_name_call = id(wakeup_page_name).make_call();
|
// auto wakeup_page_name_call = id(wakeup_page_name).make_call();
|
||||||
wakeup_page_name_call.set_option(id(page_names)[id(wakeup_page_id)]);
|
// wakeup_page_name_call.set_option(id(page_names)[id(wakeup_page_id)]);
|
||||||
wakeup_page_name_call.perform();
|
// wakeup_page_name_call.perform();
|
||||||
|
|
||||||
|
// id(is_restored_settings) = true;
|
||||||
ESP_LOGV(TAG, "Finishing");
|
ESP_LOGV(TAG, "Finishing");
|
||||||
id(is_restored_settings) = true;
|
|
||||||
|
|
||||||
- id: service_call_alarm_control_panel
|
- id: service_call_alarm_control_panel
|
||||||
mode: restart
|
mode: restart
|
||||||
@@ -2679,9 +2709,6 @@ script:
|
|||||||
|
|
||||||
uint detected_page_id = pageIndex(page.c_str());
|
uint detected_page_id = pageIndex(page.c_str());
|
||||||
ESP_LOGV(TAG, "%s=%i", variable.c_str(), detected_page_id);
|
ESP_LOGV(TAG, "%s=%i", variable.c_str(), detected_page_id);
|
||||||
if (variable == "wakeup_page_id")
|
|
||||||
id(wakeup_page_id) = detected_page_id;
|
|
||||||
else
|
|
||||||
disp1->send_command_printf("%s=%i", variable.c_str(), detected_page_id);
|
disp1->send_command_printf("%s=%i", variable.c_str(), detected_page_id);
|
||||||
|
|
||||||
- id: setup_sequence
|
- id: setup_sequence
|
||||||
@@ -2829,7 +2856,7 @@ script:
|
|||||||
state: boot
|
state: boot
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
if (current_page->state == "boot") disp1->goto_page(id(wakeup_page_id));
|
if (current_page->state == "boot") disp1->goto_page(wakeup_page_name->state.c_str());
|
||||||
else: # Unknown TFT
|
else: # Unknown TFT
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
static const char *const TAG = "script.setup_sequence";
|
static const char *const TAG = "script.setup_sequence";
|
||||||
@@ -3200,14 +3227,15 @@ script:
|
|||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
size_t total_heap_size = ESP.getHeapSize();
|
size_t total_heap_size = ESP.getHeapSize();
|
||||||
size_t free_heap_size = ESP.getFreeHeap();
|
size_t free_heap_size = ESP.getFreeHeap();
|
||||||
ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size, int(round(((float)free_heap_size / total_heap_size) * 100.0f)));
|
|
||||||
ESP_LOGI(TAG, " Framework: arduino");
|
|
||||||
#elif defined(USE_ESP_IDF)
|
#elif defined(USE_ESP_IDF)
|
||||||
size_t total_heap_size = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
|
size_t total_heap_size = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
|
||||||
size_t free_heap_size = esp_get_free_heap_size();
|
size_t free_heap_size = esp_get_free_heap_size();
|
||||||
ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size, int(round(((float)free_heap_size / total_heap_size) * 100.0f)));
|
|
||||||
ESP_LOGI(TAG, " Framework: esp-idf");
|
|
||||||
#endif
|
#endif
|
||||||
|
if (total_heap_size != 0)
|
||||||
|
ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size,
|
||||||
|
int(round(((float)free_heap_size / total_heap_size) * 100.0f)));
|
||||||
|
ESP_LOGI(TAG, " Framework: %s", id(framework) == 1 ? "Arduino" :
|
||||||
|
(id(framework) == 2 ? "ESP-IDF" : "Unknown")); // ESPHome framework
|
||||||
|
|
||||||
// Report UART
|
// Report UART
|
||||||
ESP_LOGI(TAG, "UART:");
|
ESP_LOGI(TAG, "UART:");
|
||||||
|
|||||||
Reference in New Issue
Block a user