Skip to content

Commit

Permalink
MQTT producer: produce min/max/default values if available
Browse files Browse the repository at this point in the history
  • Loading branch information
chriadam committed Oct 30, 2023
1 parent a2017d2 commit 7b63d59
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/qt/ve_qitems_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,23 @@ void VeQItemMqttProducer::parseMessage(const QString &path, const QByteArray &me
item->produceValue(QVariant(), VeQItem::Offline);
} else {
// otherwise, update the value in the item.
// TODO: text / min / max / default ??
const QJsonObject payload = QJsonDocument::fromJson(message).object();
const QVariant variant = payload.value(QStringLiteral("value")).toVariant();
item->produceValue(variant.isNull() ? QVariant() : variant, // work around QJsonValue always using std::nullptr_t even for literal null values.
const QVariant min = payload.value(QStringLiteral("min")).toVariant();
if (!min.isNull() && min.isValid()) {
item->itemProduceProperty("min", min);
}
const QVariant max = payload.value(QStringLiteral("max")).toVariant();
if (!max.isNull() && max.isValid()) {
item->itemProduceProperty("max", max);
}
const QVariant def = payload.value(QStringLiteral("default")).toVariant();
if (!def.isNull() && def.isValid()) {
item->itemProduceProperty("default", def);
}
const QVariant value = payload.value(QStringLiteral("value")).toVariant();
item->produceValue(value.isNull() ? QVariant() : value, // work around QJsonValue always using std::nullptr_t even for literal null values.
VeQItem::Synchronized); // ensure the value is marked as "seen".
Q_EMIT messageReceived(path, variant);
Q_EMIT messageReceived(path, value);
}
}

Expand Down

0 comments on commit 7b63d59

Please sign in to comment.