summaryrefslogtreecommitdiff
path: root/server/src/luaquerymapper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/luaquerymapper.cc')
-rw-r--r--server/src/luaquerymapper.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc
index 7ee43ff..fdb1248 100644
--- a/server/src/luaquerymapper.cc
+++ b/server/src/luaquerymapper.cc
@@ -162,6 +162,39 @@ void LUAQueryMapper::error(std::string message) throw(Exception)
throw Exception("ERROR in LUAQueryMapper: " + message);
}
+std::string LUAQueryMapper::automap(const std::string &name)
+{
+ std::string group;
+ std::string groupcheck = "if(";
+
+ for(size_t i = 0; i < name.length(); i++) {
+ group += name[i];
+ if(name[i] == '.') groupcheck += " and " + group;
+ else groupcheck += name[i];
+ }
+ groupcheck += " and " + name + ".value and " + name + ".timestamp and " + name + ".source";
+ groupcheck += ")\n";
+
+ std::string automapstring =
+ "-- Returning 0, 0 invalidates the result\n"
+ "value = 0\n"
+ "timestamp = 0\n"
+ "source = 0\n"
+ "\n"
+ + groupcheck +
+ "then\n"
+ " value = " + name + ".value\n"
+ " timestamp = " + name + ".timestamp\n"
+ " source = " + name + ".source\n"
+ "end\n"
+ "return value, timestamp, source\n";
+
+ PRACRO_DEBUG(widget, "Automap:\n%s\n", automapstring.c_str());
+
+ return automapstring;
+}
+
+
#ifdef TEST_LUAQUERYMAPPER
int main()