mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
merge Michael's changes
This commit is contained in:
@@ -40,7 +40,12 @@ std::deque<Token> exprToTokens(const std::string & expr) {
|
|||||||
if (*p) {
|
if (*p) {
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
const auto s = std::string(b, p);
|
auto s = std::string(b, p);
|
||||||
|
auto n = s.find("\"\"");
|
||||||
|
while (n != std::string::npos) {
|
||||||
|
s.erase(n, 2);
|
||||||
|
n = s.find("\"\"");
|
||||||
|
}
|
||||||
tokens.emplace_back(Token::Type::String, s, -3);
|
tokens.emplace_back(Token::Type::String, s, -3);
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
--p;
|
--p;
|
||||||
@@ -333,7 +338,7 @@ bool isnum(const std::string & s) {
|
|||||||
std::string commands(std::string & expr, bool quotes) {
|
std::string commands(std::string & expr, bool quotes) {
|
||||||
auto expr_new = emsesp::Helpers::toLower(expr);
|
auto expr_new = emsesp::Helpers::toLower(expr);
|
||||||
for (uint8_t device = 0; device < emsesp::EMSdevice::DeviceType::UNKNOWN; device++) {
|
for (uint8_t device = 0; device < emsesp::EMSdevice::DeviceType::UNKNOWN; device++) {
|
||||||
const char * d = emsesp::EMSdevice::device_type_2_device_name(device);
|
std::string d = (std::string)emsesp::EMSdevice::device_type_2_device_name(device) + "/";
|
||||||
auto f = expr_new.find(d);
|
auto f = expr_new.find(d);
|
||||||
while (f != std::string::npos) {
|
while (f != std::string::npos) {
|
||||||
// entity names are alphanumeric or _
|
// entity names are alphanumeric or _
|
||||||
@@ -375,6 +380,14 @@ std::string commands(std::string & expr, bool quotes) {
|
|||||||
f = expr_new.find(d, e);
|
f = expr_new.find(d, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (quotes) {
|
||||||
|
// remove double quotes
|
||||||
|
auto f = expr.find("\"\"");
|
||||||
|
while (f != std::string::npos) {
|
||||||
|
expr.erase(f, 2);
|
||||||
|
f = expr.find("\"\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +429,7 @@ std::string to_hex(uint32_t i) {
|
|||||||
// RPN calculator
|
// RPN calculator
|
||||||
std::string calculate(const std::string & expr) {
|
std::string calculate(const std::string & expr) {
|
||||||
std::string expr_new = expr;
|
std::string expr_new = expr;
|
||||||
commands(expr_new);
|
// commands(expr_new);
|
||||||
|
|
||||||
const auto tokens = exprToTokens(expr_new);
|
const auto tokens = exprToTokens(expr_new);
|
||||||
// for debugging only
|
// for debugging only
|
||||||
@@ -651,6 +664,7 @@ std::string calculate(const std::string & expr) {
|
|||||||
// check for multiple instances of <cond> ? <expr1> : <expr2>
|
// check for multiple instances of <cond> ? <expr1> : <expr2>
|
||||||
std::string compute(const std::string & expr) {
|
std::string compute(const std::string & expr) {
|
||||||
std::string expr_new = expr;
|
std::string expr_new = expr;
|
||||||
|
commands(expr_new); // replace ems-esp commands with values
|
||||||
|
|
||||||
// search json with url:
|
// search json with url:
|
||||||
auto f = expr_new.find_first_of('{');
|
auto f = expr_new.find_first_of('{');
|
||||||
|
|||||||
@@ -353,6 +353,7 @@ bool WebSchedulerService::command(const char * name, const std::string & command
|
|||||||
std::string value = doc["value"] | data.c_str(); // extract value if its in the command, or take the data
|
std::string value = doc["value"] | data.c_str(); // extract value if its in the command, or take the data
|
||||||
std::string method = doc["method"] | "GET"; // default GET
|
std::string method = doc["method"] | "GET"; // default GET
|
||||||
|
|
||||||
|
commands(value, false);
|
||||||
// if there is data, force a POST
|
// if there is data, force a POST
|
||||||
int httpResult = 0;
|
int httpResult = 0;
|
||||||
if (value.length() || method == "post") { // we have all lowercase
|
if (value.length() || method == "post") { // we have all lowercase
|
||||||
@@ -546,10 +547,9 @@ void WebSchedulerService::scheduler_task(void * pvParameters) {
|
|||||||
// hard coded tests
|
// hard coded tests
|
||||||
#if defined(EMSESP_TEST)
|
#if defined(EMSESP_TEST)
|
||||||
void WebSchedulerService::load_test_data() {
|
void WebSchedulerService::load_test_data() {
|
||||||
static bool already_added = false;
|
|
||||||
if (!already_added) {
|
|
||||||
update([&](WebScheduler & webScheduler) {
|
update([&](WebScheduler & webScheduler) {
|
||||||
// webScheduler.scheduleItems.clear();
|
webScheduler.scheduleItems.clear(); // delete all existing schedules
|
||||||
|
|
||||||
// test 1
|
// test 1
|
||||||
auto si = ScheduleItem();
|
auto si = ScheduleItem();
|
||||||
si.active = true;
|
si.active = true;
|
||||||
@@ -575,11 +575,9 @@ void WebSchedulerService::load_test_data() {
|
|||||||
si.retry_cnt = 0xFF; // no startup retries
|
si.retry_cnt = 0xFF; // no startup retries
|
||||||
|
|
||||||
webScheduler.scheduleItems.push_back(si);
|
webScheduler.scheduleItems.push_back(si);
|
||||||
already_added = true;
|
|
||||||
|
|
||||||
return StateUpdateResult::CHANGED; // persist the changes
|
return StateUpdateResult::CHANGED; // persist the changes
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user