From 83e9d20f780d3eef6bcec8befcac2292aac4a81e Mon Sep 17 00:00:00 2001 From: Gijs Noorlander Date: Sun, 15 Sep 2019 22:30:11 +0200 Subject: [PATCH] [Rules] Some minor code improvements (suggests from @uzi18 ) --- docs/source/Rules/Rules.rst | 18 +++++++++--------- src/ESPEasyRules.ino | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/source/Rules/Rules.rst b/docs/source/Rules/Rules.rst index c3412c375..e440d723b 100644 --- a/docs/source/Rules/Rules.rst +++ b/docs/source/Rules/Rules.rst @@ -240,7 +240,7 @@ remember to add them after the code and always begin with "//": endon Referring values ---------------- +---------------- Rules and some plugins can use references to other (dynamic) values within ESPeasy. @@ -265,18 +265,18 @@ N.B. these references to task values only yield a value when the task is enabled Special task names ------------------ -You must not use the task names ``Plugin``, ``VAR`` ``INT`` as these hae special meaning. +You must not use the task names ``Plugin``, ``var`` ``int`` as these have special meaning. ``Plugin`` can be used in a so called ``PLUGIN_REQUEST``, for example: ``[Plugin#GPIO#Pinstate#N]`` to get the pin state of a GPIO pin. -``Var`` and ``INT`` are used for internal variables. +``Var`` and ``int`` are used for internal variables. The variables set with the ``Let`` command will be available in rules -as ``VAR#N`` or ``INT#N`` where ``N`` is 1..16. -For example: ``Let,10,[VAR#9]`` +as ``var#N`` or ``int#N`` where ``N`` is 1..16. +For example: ``Let,10,[var#9]`` -N.B. ``INT`` and ``VAR`` use the same variable, only ``INT`` does round them to 0 decimals. -N.B.2 ``INT`` is added in build 20190916. +N.B. ``int`` and ``var`` use the same variable, only ``int`` does round them to 0 decimals. +N.B.2 ``int`` is added in build 20190916. ``Clock``, ``Rules`` and ``System`` etc. are not recommended either since they are used in event names. @@ -495,8 +495,8 @@ A really great feature to use is the 16 internal variables. You set them like th Let,, Where n can be 1 to 16 and the value an float. To use the values in strings you can -either use the ``%v7%`` syntax or ``[VAR#7]``. BUT for formulas you need to use the square -brackets in order for it to compute, i.e. ``[VAR#12]``. +either use the ``%v7%`` syntax or ``[var#7]``. BUT for formulas you need to use the square +brackets in order for it to compute, i.e. ``[var#12]``. Averaging filters diff --git a/src/ESPEasyRules.ino b/src/ESPEasyRules.ino index 790f987f5..dac7d4f07 100644 --- a/src/ESPEasyRules.ino +++ b/src/ESPEasyRules.ino @@ -182,7 +182,7 @@ String rulesProcessingFile(const String& fileName, String& event) { switch (static_cast(data)) { - case 10: // "\n" + case '\n': { // Line end, parse rule if (!line.startsWith(F("//")) && (line.length() > 0)) { @@ -198,10 +198,10 @@ String rulesProcessingFile(const String& fileName, String& event) { commentFound = false; break; } - case 13: // "\r", Just skip this character + case '\r': // Just skip this character break; case '\t': // tab - case 32: // space + case ' ': // space { // Strip leading spaces. if (firstNonSpaceRead) { @@ -248,16 +248,15 @@ void replace_EventValueN_Argv(String& line, const String& argString, unsigned in String eventvalue; eventvalue.reserve(16); - eventvalue = F("%eventvalue"); - eventvalue += argc; + eventvalue = F("%eventvalue"); + + if (argc != 0) { + eventvalue += argc; + } eventvalue += '%'; String tmpParam; if (GetArgv(argString.c_str(), tmpParam, argc)) { - if (argc == 1) { - // For compatibility reasons also replace %eventvalue% - line.replace(F("%eventvalue%"), tmpParam); - } line.replace(eventvalue, tmpParam); } } @@ -293,9 +292,10 @@ void parseCompleteNonCommentLine(String& line, String& event, String& log, if (equalsPos > 0) { // Replace %eventvalueX% with the actual value of the event. + // For compatibility reasons also replace %eventvalue% (argc = 0) String argString = event.substring(equalsPos + 1); - for (unsigned int argc = 1; argc <= 4; ++argc) { + for (unsigned int argc = 0; argc <= 4; ++argc) { replace_EventValueN_Argv(line, argString, argc); } }