multiple onChange and check one ? : sequence

This commit is contained in:
MichaelDvP
2024-06-22 08:33:13 +02:00
parent 649734df43
commit bed7793dab
2 changed files with 24 additions and 6 deletions

View File

@@ -368,7 +368,8 @@ bool WebSchedulerService::command(const char * cmd, const char * data) {
bool WebSchedulerService::onChange(const char * cmd) {
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
if (scheduleItem.active && scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_ONCHANGE && Helpers::toLower(scheduleItem.time) == Helpers::toLower(cmd)) {
if (scheduleItem.active && scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_ONCHANGE
&& Helpers::toLower(scheduleItem.time).find(Helpers::toLower(cmd)) != std::string::npos) {
#ifdef EMESESP_DEBUG
// emsesp::EMSESP::logger().debug(scheduleItem.cmd.c_str());
#endif

View File

@@ -371,16 +371,20 @@ int to_logic(const std::string & s) {
return -1;
}
// number to string
// number to string, remove trailing zeros
std::string to_string(double d) {
if (d == static_cast<int>(d)) {
return std::to_string(static_cast<int>(d));
std::string s = std::to_string(d);
while (!s.empty() && s.back() == '0') {
s.pop_back();
}
return std::to_string(d);
if (!s.empty() && s.back() == '.') {
s.pop_back();
}
return s;
}
// RPN calculator
std::string compute(const std::string & expr) {
std::string calculate(const std::string & expr) {
auto expr_new = emsesp::Helpers::toLower(expr);
// emsesp::EMSESP::logger().info("calculate: %s", expr_new.c_str());
commands(expr_new);
@@ -554,3 +558,16 @@ std::string compute(const std::string & expr) {
}
return stack.back();
}
// check for <expr> ? <expr1> : <expr2>
std::string compute(const std::string & expr) {
auto q = expr.find_first_of("?");
auto p = expr.find_first_of(":", q);
if (p != std::string::npos && q != std::string::npos) {
if (calculate(expr.substr(0, q))[0] == '1') {
return calculate(expr.substr(q + 1, p - q - 1));
} else {
return calculate(expr.substr(p + 1));
}
}
return calculate(expr);
}