add value list support

This commit is contained in:
John
2023-06-03 10:45:08 +02:00
parent 5825975d48
commit 699f056381
4 changed files with 63 additions and 1 deletions
+28
View File
@@ -1111,6 +1111,34 @@ void MqttHandler::run() {
}
values.set("step", ostr.str());
}
if (dataType->isNumeric() && field->isList() && !values["field_values-entry"].empty()) {
auto vl = (dynamic_cast<const ValueListDataField*>(field))->getList();
string entryFormat = values["field_values-entry"];
string::size_type pos = -1;
while ((pos = entryFormat.find('$', pos+1)) != std::string::npos) {
if (entryFormat.substr(pos+1, 4) == "text" || entryFormat.substr(pos+1, 5) == "value") {
entryFormat.replace(pos, 1, "%");
}
}
entryFormat.replace(0, 0, "entry = ");
string result = values["field_values-prefix"];
bool first = true;
for (const auto& it : vl) {
StringReplacers entry;
entry.parseLine(entryFormat);
entry.set("value", it.first);
entry.set("text", it.second);
entry.reduce();
if (first) {
first = false;
} else {
result += values["field_values-separator"];
}
result += entry.get("entry", false, false);
}
result += values["field_values-suffix"];
values.set("field_values", result);
}
if (!m_typeSwitches.empty()) {
values.reduce(true);
str = values.get("type_switch-by", false, false);
+4
View File
@@ -551,6 +551,10 @@ class ValueListDataField : public SingleDataField {
// @copydoc
void dump(bool prependFieldSeparator, OutputFormat outputFormat, ostream* output) const override;
/**
* @return the value=text assignments.
*/
const map<unsigned int, string>& getList() const { return m_values; }
protected:
// @copydoc