Review on_boot script

This commit is contained in:
Edward Firmo
2023-11-10 18:55:20 +01:00
parent 69a13a9745
commit 1857be65c2
2 changed files with 26 additions and 32 deletions

View File

@@ -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());