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