mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 01:24:04 +00:00
[Rules] Some minor code improvements (suggests from @uzi18 )
This commit is contained in:
@@ -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,<n>,<value>
|
||||
|
||||
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
|
||||
|
||||
+10
-10
@@ -182,7 +182,7 @@ String rulesProcessingFile(const String& fileName, String& event) {
|
||||
|
||||
switch (static_cast<char>(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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user