start working on SetValue Command

This commit is contained in:
Justin Hammond 2019-11-06 17:19:44 +08:00
parent 5e1b41e212
commit ed26e74448
5 changed files with 58 additions and 8 deletions

View file

@ -28,6 +28,7 @@
#include "mqttcommands/checkLatestMFSRevision.h"
#include "mqttcommands/downloadLatestConfigFileRevision.h"
#include "mqttcommands/downloadLatestMFSRevision.h"
#include "mqttcommands/setValue.h"
Q_LOGGING_CATEGORY(ozwmc, "ozw.mqtt.commands");
@ -140,7 +141,26 @@ bool MqttCommand::checkNode(QJsonDocument jmsg, QString field) {
return false;
}
bool MqttCommand::checkValue(QJsonDocument jmsg, QString field) {
quint64 vidKey = jmsg[field].toInt();
if (vidKey == 0) {
qCWarning(ozwmc) << "Invalid VidKey in field " << field << " for message " << jmsg.toJson();
return false;
}
if (this->getMqttPublisher()->isValidValueID(vidKey)) {
return true;
}
qCWarning(ozwmc) << "Invalid VidKey in field " << field << " for message " << jmsg.toJson();
return false;
}
QVariant MqttCommand::getValueData(quint64 vidKey, QTOZW_ValueIds::ValueIdColumns col) {
return this->getMqttPublisher()->getValueData(vidKey, col);
}
bool MqttCommand::setValue(quint64 vidKey, QVariant data) {
return this->getMqttPublisher()->setValue(vidKey, data);
}
MqttCommands::MqttCommands(QObject *parent) :
@ -184,6 +204,7 @@ void MqttCommands::setupCommands() {
this->Register(MqttCommand_CheckLatestMFSRevision::StaticGetCommand(), &MqttCommand_CheckLatestMFSRevision::Create);
this->Register(MqttCommand_DownloadLatestConfigFileRevision::StaticGetCommand(), &MqttCommand_DownloadLatestConfigFileRevision::Create);
this->Register(MqttCommand_DownloadLatestMFSRevision::StaticGetCommand(), &MqttCommand_DownloadLatestMFSRevision::Create);
this->Register(MqttCommand_SetValue::StaticGetCommand(), &MqttCommand_SetValue::Create);
}
void MqttCommands::setupSubscriptions(QMqttClient *mqttclient, QString topTopic) {

View file

@ -9,6 +9,7 @@
#include <qt-openzwave/qtopenzwave.h>
#include <qt-openzwave/qtozwmanager.h>
#include <qt-openzwave/qtozwvalueidmodel.h>
#include "mqttpublisher.h"
@ -29,6 +30,9 @@ protected:
QTOZWManager *getOZWManager();
mqttpublisher *getMqttPublisher();
bool checkNode(QJsonDocument, QString);
bool checkValue(QJsonDocument, QString);
QVariant getValueData(quint64, QTOZW_ValueIds::ValueIdColumns);
bool setValue(quint64, QVariant);
QVector<QString> m_requiredStringFields;
QVector<QString> m_requiredIntFields;
QVector<QString> m_requiredBoolFields;

View file

@ -89,6 +89,12 @@ QVariant mqttValueIDModel::getValueData(quint64 vidKey, ValueIdColumns col) {
return this->data(this->index(row, col), Qt::DisplayRole);
}
bool mqttValueIDModel::isValidValueID(quint64 vidKey) {
if (this->getValueRow(vidKey) == -1)
return false;
return true;
}
bool mqttValueIDModel::populateJsonObject(QJsonObject *jsonobject, quint64 vidKey, QTOZWManager *mgr) {
for (int i = 0; i < ValueIdColumns::ValueIdCount; i++) {
@ -143,8 +149,6 @@ bool mqttValueIDModel::populateJsonObject(QJsonObject *jsonobject, quint64 vidKe
}
}
return true;
}
@ -230,6 +234,10 @@ QJsonValue mqttValueIDModel::encodeValue(quint64 vidKey) {
return value;
}
bool mqttValueIDModel::setData(quint64 vidKey, QVariant data) {
return QTOZW_ValueIds::setData(this->index(this->getValueRow(vidKey), QTOZW_ValueIds::ValueIdColumns::Value), data, Qt::EditRole);
}
mqttpublisher::mqttpublisher(QObject *parent) : QObject(parent)
@ -344,6 +352,16 @@ void mqttpublisher::doStats() {
bool mqttpublisher::isValidNode(quint8 node) {
return this->m_nodeModel->isValidNode(node);
}
bool mqttpublisher::isValidValueID(quint64 vidKey) {
return this->m_valueModel->isValidValueID(vidKey);
}
QVariant mqttpublisher::getValueData(quint64 vidKey, mqttValueIDModel::ValueIdColumns col) {
return this->m_valueModel->getValueData(vidKey, col);
}
bool mqttpublisher::setValue(quint64 vidKey, QVariant data) {
return this->m_valueModel->setData(vidKey, data);
}
QString mqttpublisher::getTopic(QString topic) {

View file

@ -38,6 +38,8 @@ public:
QVariant getValueData(quint64, ValueIdColumns);
bool populateJsonObject(QJsonObject *, quint64, QTOZWManager *);
QJsonValue encodeValue(quint64);
bool isValidValueID(quint64);
bool setData(quint64, QVariant);
};
class mqttpublisher : public QObject
@ -49,6 +51,9 @@ public:
QTOZWManager *getQTOZWManager();
void sendCommandUpdate(QString, QJsonObject);
bool isValidNode(quint8 node);
bool isValidValueID(quint64 vidKey);
QVariant getValueData(quint64, mqttValueIDModel::ValueIdColumns);
bool setValue(quint64, QVariant);
signals:
public slots:

View file

@ -51,7 +51,8 @@ qtHaveModule(mqtt) {
mqttcommands/checkLatestConfigFileRevision.cpp \
mqttcommands/checkLatestMFSRevision.cpp \
mqttcommands/downloadLatestConfigFileRevision.cpp \
mqttcommands/downloadLatestMFSRevision.cpp
mqttcommands/downloadLatestMFSRevision.cpp \
mqttcommands/setValue.cpp
HEADERS += mqttpublisher.h \
mqttcommands/mqttcommands.h \
@ -83,7 +84,8 @@ qtHaveModule(mqtt) {
mqttcommands/checkLatestConfigFileRevision.h \
mqttcommands/CheckLatestMFSRevision.h \
mqttcommands/downloadLatestConfigFileRevision.h \
mqttcommands/downloadLatestMFSRevision.h
mqttcommands/downloadLatestMFSRevision.h \
mqttcommands/setValue.h
} else {
warning("MQTT Qt Module Not Found. Not Building MQTT Client Capabilities")
}