Review on_boot script
This commit is contained in:
@@ -38,6 +38,7 @@ button:
|
||||
api:
|
||||
services:
|
||||
##### SERVICE TO UPDATE THE TFT FILE from URL #####
|
||||
##### It will use the default url if url is empty or "default"
|
||||
- service: upload_tft_url
|
||||
variables:
|
||||
url: string
|
||||
@@ -46,21 +47,16 @@ api:
|
||||
static const char *const TAG = "service.upload_tft_url";
|
||||
ESP_LOGVV(TAG, "Starting...");
|
||||
|
||||
auto toLowerAndTrim(const std::string& input) -> std::string {
|
||||
std::string result = input;
|
||||
// Convert to lowercase
|
||||
std::transform(result.begin(), result.end(), result.begin(),
|
||||
[](unsigned char c){ return std::tolower(c); });
|
||||
std::string clean_url = url;
|
||||
// Convert to lowercase
|
||||
std::transform(clean_url.begin(), clean_url.end(), clean_url.begin(),
|
||||
[](unsigned char c){ return std::tolower(c); });
|
||||
// Trim trailing spaces
|
||||
auto endPos = clean_url.find_last_not_of(" \t");
|
||||
if (std::string::npos != endPos) {
|
||||
clean_url = clean_url.substr(0, endPos + 1);
|
||||
}
|
||||
|
||||
// Trim trailing spaces
|
||||
auto endPos = result.find_last_not_of(" \t");
|
||||
if (std::string::npos != endPos) {
|
||||
result = result.substr(0, endPos + 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
std::string clean_url = toLowerAndTrim(url.c_str());
|
||||
if ( clean_url.empty() or clean_url == "default") url = "${nextion_update_url}";
|
||||
upload_tft->execute(url.c_str());
|
||||
|
||||
|
||||
@@ -6,11 +6,6 @@
|
||||
#####################################################################################################
|
||||
|
||||
substitutions:
|
||||
|
||||
################## Defaults ##################
|
||||
# Just in case user forgets to set something #
|
||||
##############################################
|
||||
|
||||
##### DON'T CHANGE THIS #####
|
||||
version: "4.1dev6"
|
||||
#############################
|
||||
@@ -1463,6 +1458,9 @@ text_sensor:
|
||||
if (display_mode_float > 0) id(display_mode) = int(display_mode_float);
|
||||
}
|
||||
|
||||
// Contruct page boot
|
||||
page_boot->execute(true);
|
||||
|
||||
// Detect TFT version
|
||||
if (doc.containsKey("version"))
|
||||
{
|
||||
@@ -2061,6 +2059,7 @@ script:
|
||||
framework = "esp-idf";
|
||||
#endif
|
||||
ESP_LOGD(TAG, "Framework: %s", framework.c_str());
|
||||
ESP_LOGD(TAG, "Baud rate: %" PRIu32, id(tf_uart).get_baud_rate());
|
||||
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
@@ -2069,7 +2068,8 @@ script:
|
||||
{"tft", id(version_tft).c_str()},
|
||||
{"esphome", "${version}"},
|
||||
{"blueprint", id(version_blueprint).c_str()},
|
||||
{"framework", framework.c_str()}
|
||||
{"framework", framework.c_str()},
|
||||
{"baud_rate", to_string(id(tf_uart).get_baud_rate())}
|
||||
});
|
||||
|
||||
- id: page_changed
|
||||
@@ -2199,19 +2199,17 @@ script:
|
||||
static const char *const TAG = "script.page_boot";
|
||||
if (construct_page) {
|
||||
ESP_LOGV(TAG, "Construct boot page");
|
||||
if (current_page->state == "boot") {
|
||||
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("framework", framework.c_str()); // ESPHome framework
|
||||
disp1->show_component("bt_reboot");
|
||||
}
|
||||
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("framework", framework.c_str()); // ESPHome framework
|
||||
disp1->show_component("bt_reboot");
|
||||
}
|
||||
|
||||
- id: page_buttonpage
|
||||
|
||||
Reference in New Issue
Block a user