mirror of
https://github.com/Fishwaldo/qt-openzwave.git
synced 2025-07-23 05:28:27 +00:00
tests for required fields on commands and some logging updates
This commit is contained in:
parent
3d7c8db9e4
commit
5e1b41e212
34 changed files with 291 additions and 130 deletions
|
@ -30,7 +30,7 @@ DEFINES += QTOPENZWAVE_LIBRARY
|
|||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
DEFINES += QT_DEPRECATED_WARNINGS QT_MESSAGELOGCONTEXT
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
|
@ -88,6 +88,7 @@ unix {
|
|||
target.path = /usr/local/lib
|
||||
INSTALLS += target
|
||||
QMAKE_CXXFLAGS += -g1
|
||||
QMAKE_LFLAGS += -rdynamic
|
||||
}
|
||||
#LIBS += -L../../open-zwave -lopenzwave
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ QTOpenZwave::QTOpenZwave
|
|||
qRegisterMetaTypeStreamOperators<NotificationTypes::QTOZW_Notification_Controller_Cmd>("NotificationTypes::QTOZW_Notification_Controller_Cmd");
|
||||
|
||||
|
||||
qSetMessagePattern("%{category} %{message}");
|
||||
// qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz t}] %{category} %{file}:%{line}:%{function}: %{message}");
|
||||
qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz t}] [%{category}] [%{type}]: %{message}");
|
||||
}
|
||||
|
||||
QTOZWManager *QTOpenZwave::GetManager
|
||||
|
|
|
@ -92,12 +92,12 @@ void QTOZW_Log_Internal::Write(OpenZWave::LogLevel _level, uint8 const _nodeId,
|
|||
}
|
||||
case OpenZWave::LogLevel_Warning: {
|
||||
qtozwlevel = LogLevels::Warning;
|
||||
qCCritical(libopenzwave) << "Warning - Node:" << _nodeId << lineBuf;
|
||||
qCWarning(libopenzwave) << "Warning - Node:" << _nodeId << lineBuf;
|
||||
break;
|
||||
}
|
||||
case OpenZWave::LogLevel_Alert: {
|
||||
qtozwlevel = LogLevels::Alert;
|
||||
qCCritical(libopenzwave) << "Alert - Node:" << _nodeId << lineBuf;
|
||||
qCWarning(libopenzwave) << "Alert - Node:" << _nodeId << lineBuf;
|
||||
break;
|
||||
}
|
||||
case OpenZWave::LogLevel_Info: {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "qtozwdaemon.h"
|
||||
#ifdef HAVE_MQTT
|
||||
#include "mqttpublisher.h"
|
||||
#warning "MQTT Enabled"
|
||||
#endif
|
||||
|
||||
void handler(int sig) {
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_IsNodeFailed::MqttCommand_IsNodeFailed(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_IsNodeFailed::Create(QObject *parent) {
|
||||
return new MqttCommand_IsNodeFailed(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_IsNodeFailed::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->IsNodeFailed(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
MqttCommand_AddNode::MqttCommand_AddNode(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredBoolFields << "secure";
|
||||
}
|
||||
MqttCommand* MqttCommand_AddNode::Create(QObject *parent) {
|
||||
return new MqttCommand_AddNode(parent);
|
||||
|
@ -11,7 +12,7 @@ MqttCommand* MqttCommand_AddNode::Create(QObject *parent) {
|
|||
bool MqttCommand_AddNode::processMessage(QJsonDocument msg) {
|
||||
Q_UNUSED(msg);
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->addNode(false)) {
|
||||
if (mgr->addNode(msg["secure"].toBool())) {
|
||||
QJsonObject js;
|
||||
js["status"] = "ok";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#include "mqttcommands/addNodeSecure.h"
|
||||
|
||||
MqttCommand_AddNodeSecure::MqttCommand_AddNodeSecure(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
}
|
||||
MqttCommand* MqttCommand_AddNodeSecure::Create(QObject *parent) {
|
||||
return new MqttCommand_AddNodeSecure(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_AddNodeSecure::processMessage(QJsonDocument msg) {
|
||||
Q_UNUSED(msg);
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->addNode(true)) {
|
||||
QJsonObject js;
|
||||
js["status"] = "ok";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return true;
|
||||
}
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef ADDNODESECURE_H
|
||||
#define ADDNODESECURE_H
|
||||
|
||||
#include "mqttcommands/mqttcommands.h"
|
||||
|
||||
class MqttCommand_AddNodeSecure : public MqttCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static MqttCommand *Create(QObject *parent = nullptr);
|
||||
static QString StaticGetCommand() { return "AddNodeSecure";};
|
||||
QString GetCommand() override { return StaticGetCommand(); };
|
||||
bool processMessage(QJsonDocument) override;
|
||||
private:
|
||||
MqttCommand_AddNodeSecure(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // PING_H
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_AssignReturnRoute::MqttCommand_AssignReturnRoute(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_AssignReturnRoute::Create(QObject *parent) {
|
||||
return new MqttCommand_AssignReturnRoute(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_AssignReturnRoute::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->assignReturnRoute(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,21 @@
|
|||
MqttCommand_CheckLatestConfigFileRevision::MqttCommand_CheckLatestConfigFileRevision(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_CheckLatestConfigFileRevision::Create(QObject *parent) {
|
||||
return new MqttCommand_CheckLatestConfigFileRevision(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_CheckLatestConfigFileRevision::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->checkLatestConfigFileRevision(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,21 @@
|
|||
MqttCommand_DeleteAllReturnRoute::MqttCommand_DeleteAllReturnRoute(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_DeleteAllReturnRoute::Create(QObject *parent) {
|
||||
return new MqttCommand_DeleteAllReturnRoute(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_DeleteAllReturnRoute::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->deleteAllReturnRoute(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_DownloadLatestConfigFileRevision::MqttCommand_DownloadLatestConfigFileRevision(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_DownloadLatestConfigFileRevision::Create(QObject *parent) {
|
||||
return new MqttCommand_DownloadLatestConfigFileRevision(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_DownloadLatestConfigFileRevision::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->downloadLatestConfigFileRevision(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_HasNodeFailed::MqttCommand_HasNodeFailed(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_HasNodeFailed::Create(QObject *parent) {
|
||||
return new MqttCommand_HasNodeFailed(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_HasNodeFailed::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->hasNodeFailed(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
MqttCommand_HealNetwork::MqttCommand_HealNetwork(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "doreturnroute";
|
||||
this->m_requiredBoolFields << "doreturnroute";
|
||||
}
|
||||
MqttCommand* MqttCommand_HealNetwork::Create(QObject *parent) {
|
||||
return new MqttCommand_HealNetwork(parent);
|
||||
|
|
|
@ -3,13 +3,21 @@
|
|||
MqttCommand_HealNetworkNode::MqttCommand_HealNetworkNode(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node" << "doreturnroute";
|
||||
this->m_requiredIntFields << "node";
|
||||
this->m_requiredBoolFields << "doreturnroute";
|
||||
}
|
||||
MqttCommand* MqttCommand_HealNetworkNode::Create(QObject *parent) {
|
||||
return new MqttCommand_HealNetworkNode(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_HealNetworkNode::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
mgr->healNetworkNode(msg["node"].toInt(), msg["doreturnroute"].toBool());
|
||||
QJsonObject js;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "mqttcommands/healNetworkNode.h"
|
||||
#include "mqttcommands/healNetwork.h"
|
||||
#include "mqttcommands/addNode.h"
|
||||
#include "mqttcommands/addNodeSecure.h"
|
||||
#include "mqttcommands/removeNode.h"
|
||||
#include "mqttcommands/removeFailedNode.h"
|
||||
#include "mqttcommands/hasNodeFailed.h"
|
||||
|
@ -30,6 +29,7 @@
|
|||
#include "mqttcommands/downloadLatestConfigFileRevision.h"
|
||||
#include "mqttcommands/downloadLatestMFSRevision.h"
|
||||
|
||||
Q_LOGGING_CATEGORY(ozwmc, "ozw.mqtt.commands");
|
||||
|
||||
MqttCommand::MqttCommand(QObject *parent) :
|
||||
QObject(parent)
|
||||
|
@ -38,7 +38,7 @@ MqttCommand::MqttCommand(QObject *parent) :
|
|||
|
||||
void MqttCommand::Setup(QMqttSubscription *subscription) {
|
||||
this->m_subscription = subscription;
|
||||
qDebug() << "Subscription Setup for " << this->m_subscription->topic();
|
||||
qCDebug(ozwmc) << "Subscription Setup for " << this->m_subscription->topic();
|
||||
connect(this->m_subscription, &QMqttSubscription::messageReceived, this, &MqttCommand::messageReceived);
|
||||
connect(this, &MqttCommand::sendCommandUpdate, getMqttPublisher(), &mqttpublisher::sendCommandUpdate);
|
||||
}
|
||||
|
@ -59,34 +59,88 @@ mqttpublisher *MqttCommand::getMqttPublisher() {
|
|||
}
|
||||
|
||||
void MqttCommand::messageReceived(QMqttMessage msg) {
|
||||
qDebug() << "Got "<< msg.topic().name()<< " Message: " << msg.payload();
|
||||
qCDebug(ozwmc) << "Got "<< msg.topic().name()<< " Message: " << msg.payload();
|
||||
QJsonParseError jerrormsg;
|
||||
QJsonDocument jmsg = QJsonDocument::fromJson(msg.payload(), &jerrormsg);
|
||||
if (jmsg.isNull()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = jerrormsg.errorString();
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qWarning() << "Json Parse Error for " << GetCommand() << ": " << jerrormsg.errorString() << ": " << msg.payload();
|
||||
qCWarning(ozwmc) << "Json Parse Error for " << GetCommand() << ": " << jerrormsg.errorString() << ": " << msg.payload();
|
||||
return;
|
||||
}
|
||||
QString field;
|
||||
foreach (field, this->m_requiredFields) {
|
||||
foreach (field, this->m_requiredIntFields) {
|
||||
if (jmsg[field].isUndefined()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = QString("Missing Field ").append(field);
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qWarning() << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
|
||||
qCWarning(ozwmc) << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
|
||||
return;
|
||||
}
|
||||
if (!jmsg[field].isDouble()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = QString("Incorrect Field Type: ").append(field).append(": Not Integer");
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qCWarning(ozwmc) << "Incorrect Field Type (Int) for " << GetCommand() << ": " << field << ": " << jmsg[field].type() << msg.payload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (field, this->m_requiredStringFields) {
|
||||
if (jmsg[field].isUndefined()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = QString("Missing Field ").append(field);
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qCWarning(ozwmc) << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
|
||||
return;
|
||||
}
|
||||
if (!jmsg[field].isString()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = QString("Incorrect Field Type: ").append(field).append(": Not String");
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qCWarning(ozwmc) << "Incorrect Field Type (String) for " << GetCommand() << ": " << field << ": " << jmsg[field].type() << msg.payload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (field, this->m_requiredBoolFields) {
|
||||
if (jmsg[field].isUndefined()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = QString("Missing Field ").append(field);
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qCWarning(ozwmc) << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
|
||||
return;
|
||||
}
|
||||
if (!jmsg[field].isBool()) {
|
||||
QJsonObject js;
|
||||
js["Error"] = QString("Incorrect Field Type: ").append(field).append(": Not Bool");
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
qCWarning(ozwmc) << "Incorrect Field Type (Bool) for " << GetCommand() << ": " << field << ": " << jmsg[field].type() << msg.payload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->processMessage(jmsg)) {
|
||||
qInfo() << "Processed Message for " << GetCommand() << ": " << msg.payload();
|
||||
qCInfo(ozwmc) << "Processed Message for " << GetCommand() << ": " << msg.payload();
|
||||
return;
|
||||
} else {
|
||||
qWarning() << "Message Processing for " << GetCommand() << " failed: " << msg.payload();
|
||||
qCWarning(ozwmc) << "Message Processing for " << GetCommand() << " failed: " << msg.payload();
|
||||
}
|
||||
}
|
||||
|
||||
bool MqttCommand::checkNode(QJsonDocument jmsg, QString field) {
|
||||
quint8 node = jmsg[field].toInt();
|
||||
if (node == 0 || node == 255) {
|
||||
qCWarning(ozwmc) << "Invalid Node in field " << field << " for message " << jmsg.toJson();
|
||||
return false;
|
||||
}
|
||||
if (this->getMqttPublisher()->isValidNode(node)) {
|
||||
return true;
|
||||
}
|
||||
qCWarning(ozwmc) << "Invalid Node in field " << field << " for message " << jmsg.toJson();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MqttCommands::MqttCommands(QObject *parent) :
|
||||
|
@ -96,7 +150,7 @@ MqttCommands::MqttCommands(QObject *parent) :
|
|||
}
|
||||
|
||||
void MqttCommands::Register(QString command, pfnCreateCommand_t _create) {
|
||||
qDebug() << "Registering Command " << command;
|
||||
qCDebug(ozwmc) << "Registering Command " << command;
|
||||
this->m_commands.insert(command, _create);
|
||||
}
|
||||
|
||||
|
@ -116,7 +170,6 @@ void MqttCommands::setupCommands() {
|
|||
this->Register(MqttCommand_HealNetworkNode::StaticGetCommand(), &MqttCommand_HealNetworkNode::Create);
|
||||
this->Register(MqttCommand_HealNetwork::StaticGetCommand(), &MqttCommand_HealNetwork::Create);
|
||||
this->Register(MqttCommand_AddNode::StaticGetCommand(), &MqttCommand_AddNode::Create);
|
||||
this->Register(MqttCommand_AddNodeSecure::StaticGetCommand(), &MqttCommand_AddNodeSecure::Create);
|
||||
this->Register(MqttCommand_RemoveNode::StaticGetCommand(), &MqttCommand_RemoveNode::Create);
|
||||
this->Register(MqttCommand_RemoveFailedNode::StaticGetCommand(), &MqttCommand_RemoveFailedNode::Create);
|
||||
this->Register(MqttCommand_HasNodeFailed::StaticGetCommand(), &MqttCommand_HasNodeFailed::Create);
|
||||
|
@ -136,7 +189,7 @@ void MqttCommands::setupCommands() {
|
|||
void MqttCommands::setupSubscriptions(QMqttClient *mqttclient, QString topTopic) {
|
||||
QMap<QString, pfnCreateCommand_t>::iterator it;
|
||||
for (it = this->m_commands.begin(); it != this->m_commands.end(); it++) {
|
||||
qDebug() << "Creating Subscription for " << it.key();
|
||||
qCDebug(ozwmc) << "Creating Subscription for " << it.key();
|
||||
pfnCreateCommand_t cmd = it.value();
|
||||
MqttCommand *command = cmd(this->parent());
|
||||
QMqttSubscription *subscription = mqttclient->subscribe(QMqttTopicFilter(topTopic.arg(it.key().toLower())));
|
||||
|
|
|
@ -28,7 +28,10 @@ protected:
|
|||
MqttCommand(QObject *parent = nullptr);
|
||||
QTOZWManager *getOZWManager();
|
||||
mqttpublisher *getMqttPublisher();
|
||||
QVector<QString> m_requiredFields;
|
||||
bool checkNode(QJsonDocument, QString);
|
||||
QVector<QString> m_requiredStringFields;
|
||||
QVector<QString> m_requiredIntFields;
|
||||
QVector<QString> m_requiredBoolFields;
|
||||
|
||||
private:
|
||||
QMqttSubscription *m_subscription;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
MqttCommand_Open::MqttCommand_Open(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "serialport";
|
||||
this->m_requiredStringFields << "serialport";
|
||||
}
|
||||
MqttCommand* MqttCommand_Open::Create(QObject *parent) {
|
||||
return new MqttCommand_Open(parent);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
MqttCommand_Ping::MqttCommand_Ping(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "ping";
|
||||
this->m_requiredStringFields << "ping";
|
||||
}
|
||||
MqttCommand* MqttCommand_Ping::Create(QObject *parent) {
|
||||
return new MqttCommand_Ping(parent);
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RefreshNodeInfo::MqttCommand_RefreshNodeInfo(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RefreshNodeInfo::Create(QObject *parent) {
|
||||
return new MqttCommand_RefreshNodeInfo(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RefreshNodeInfo::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->refreshNodeInfo(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RemoveFailedNode::MqttCommand_RemoveFailedNode(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RemoveFailedNode::Create(QObject *parent) {
|
||||
return new MqttCommand_RemoveFailedNode(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RemoveFailedNode::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->removeFailedNode(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_ReplaceFailedNode::MqttCommand_ReplaceFailedNode(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_ReplaceFailedNode::Create(QObject *parent) {
|
||||
return new MqttCommand_ReplaceFailedNode(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_ReplaceFailedNode::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->replaceFailedNode(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RequestAllConfigParam::MqttCommand_RequestAllConfigParam(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RequestAllConfigParam::Create(QObject *parent) {
|
||||
return new MqttCommand_RequestAllConfigParam(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RequestAllConfigParam::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
mgr->requestAllConfigParam(msg["node"].toInt());
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RequestConfigParam::MqttCommand_RequestConfigParam(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node" << "param";
|
||||
this->m_requiredIntFields << "node" << "param";
|
||||
}
|
||||
MqttCommand* MqttCommand_RequestConfigParam::Create(QObject *parent) {
|
||||
return new MqttCommand_RequestConfigParam(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RequestConfigParam::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
mgr->requestConfigParam(msg["node"].toInt(), msg["param"].toInt());
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RequestNetworkUpdate::MqttCommand_RequestNetworkUpdate(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "MqttCommand_RequestNetworkUpdate";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RequestNetworkUpdate::Create(QObject *parent) {
|
||||
return new MqttCommand_RequestNetworkUpdate(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RequestNetworkUpdate::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->requestNetworkUpdate(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RequestNodeDynamic::MqttCommand_RequestNodeDynamic(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RequestNodeDynamic::Create(QObject *parent) {
|
||||
return new MqttCommand_RequestNodeDynamic(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RequestNodeDynamic::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->requestNodeDynamic(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RequestNodeNeighborUpdate::MqttCommand_RequestNodeNeighborUpdate(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RequestNodeNeighborUpdate::Create(QObject *parent) {
|
||||
return new MqttCommand_RequestNodeNeighborUpdate(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RequestNodeNeighborUpdate::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->requestNodeNeighborUpdate(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_RequestNodeState::MqttCommand_RequestNodeState(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_RequestNodeState::Create(QObject *parent) {
|
||||
return new MqttCommand_RequestNodeState(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_RequestNodeState::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->requestNodeState(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_SendNodeInformation::MqttCommand_SendNodeInformation(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node";
|
||||
this->m_requiredIntFields << "node";
|
||||
}
|
||||
MqttCommand* MqttCommand_SendNodeInformation::Create(QObject *parent) {
|
||||
return new MqttCommand_SendNodeInformation(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_SendNodeInformation::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
if (mgr->sendNodeInformation(msg["node"].toInt())) {
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
MqttCommand_TestNetwork::MqttCommand_TestNetwork(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "count";
|
||||
this->m_requiredIntFields << "count";
|
||||
}
|
||||
MqttCommand* MqttCommand_TestNetwork::Create(QObject *parent) {
|
||||
return new MqttCommand_TestNetwork(parent);
|
||||
|
|
|
@ -3,13 +3,20 @@
|
|||
MqttCommand_TestNetworkNode::MqttCommand_TestNetworkNode(QObject *parent) :
|
||||
MqttCommand(parent)
|
||||
{
|
||||
this->m_requiredFields << "node" << "count";
|
||||
this->m_requiredIntFields << "node" << "count";
|
||||
}
|
||||
MqttCommand* MqttCommand_TestNetworkNode::Create(QObject *parent) {
|
||||
return new MqttCommand_TestNetworkNode(parent);
|
||||
}
|
||||
|
||||
bool MqttCommand_TestNetworkNode::processMessage(QJsonDocument msg) {
|
||||
if (!this->checkNode(msg, "node")) {
|
||||
QJsonObject js;
|
||||
js["status"] = "failed";
|
||||
js["Error"] = "Invalid Node Number";
|
||||
emit sendCommandUpdate(GetCommand(), js);
|
||||
return false;
|
||||
}
|
||||
QTOZWManager *mgr = getOZWManager();
|
||||
mgr->testNetworkNode(msg["node"].toInt(), msg["count"].toInt());
|
||||
QJsonObject js;
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
#include "mqttpublisher.h"
|
||||
#include "mqttcommands/mqttcommands.h"
|
||||
|
||||
Q_LOGGING_CATEGORY(ozwmp, "ozw.mqtt.publisher");
|
||||
Q_LOGGING_CATEGORY(ozwmpnode, "ozw.mqtt.publisher.node");
|
||||
Q_LOGGING_CATEGORY(ozwmpvalue, "ozw.mqtt.publisher.value");
|
||||
|
||||
|
||||
|
||||
mqttNodeModel::mqttNodeModel(QObject *parent)
|
||||
{
|
||||
|
||||
|
@ -13,6 +19,13 @@ QVariant mqttNodeModel::getNodeData(quint8 node, NodeColumns col) {
|
|||
return this->data(this->index(row, col), Qt::DisplayRole);
|
||||
}
|
||||
|
||||
bool mqttNodeModel::isValidNode(quint8 node) {
|
||||
if (this->getNodeRow(node) == -1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool mqttNodeModel::populateJsonObject(QJsonObject *jsonobject, quint8 node, QTOZWManager *mgr) {
|
||||
for (int i = 0; i < this->columnCount(QModelIndex()); i++) {
|
||||
QVariant data = this->getNodeData(node, static_cast<NodeColumns>(i));
|
||||
|
@ -39,7 +52,7 @@ bool mqttNodeModel::populateJsonObject(QJsonObject *jsonobject, quint8 node, QTO
|
|||
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::UInt) {
|
||||
jsonobject->insert(metaEnum.valueToKey(i), data.toInt());
|
||||
} else {
|
||||
qWarning() << "Can't Convert " << data.type() << "(" << metaEnum.valueToKey(i) << ") to store in JsonObject: " << node;
|
||||
qCWarning(ozwmpvalue) << "Can't Convert " << data.type() << "(" << metaEnum.valueToKey(i) << ") to store in JsonObject: " << node;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -123,7 +136,7 @@ bool mqttValueIDModel::populateJsonObject(QJsonObject *jsonobject, quint64 vidKe
|
|||
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::ULongLong) {
|
||||
jsonobject->insert(metaEnum.valueToKey(i), static_cast<qint64>(data.toULongLong()));
|
||||
} else {
|
||||
qWarning() << "mqttValueIDModel::populateJsonObject: Can't Convert " << data.type() << "(" << metaEnum.valueToKey(i) << ") to store in JsonObject: " << vidKey;
|
||||
qCWarning(ozwmpvalue) << "mqttValueIDModel::populateJsonObject: Can't Convert " << data.type() << "(" << metaEnum.valueToKey(i) << ") to store in JsonObject: " << vidKey;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -194,11 +207,11 @@ QJsonValue mqttValueIDModel::encodeValue(quint64 vidKey) {
|
|||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Raw: {
|
||||
qWarning() << "Raw ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
qCWarning(ozwmpvalue) << "Raw ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Schedule: {
|
||||
qWarning() << "Raw ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
qCWarning(ozwmpvalue) << "Raw ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Short: {
|
||||
|
@ -210,7 +223,7 @@ QJsonValue mqttValueIDModel::encodeValue(quint64 vidKey) {
|
|||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::TypeCount: {
|
||||
qWarning() << "Unhandled ValueID Type" << type << "in mqttValueIdModel::encodeValue" << vidKey << this->getValueData(vidKey, mqttValueIDModel::ValueIdColumns::Label).toString();
|
||||
qCWarning(ozwmpvalue) << "Unhandled ValueID Type" << type << "in mqttValueIdModel::encodeValue" << vidKey << this->getValueData(vidKey, mqttValueIDModel::ValueIdColumns::Label).toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +252,7 @@ mqttpublisher::mqttpublisher(QObject *parent) : QObject(parent)
|
|||
const QString content = QDateTime::currentDateTime().toString()
|
||||
+ QLatin1String(" PingResponse")
|
||||
+ QLatin1Char('\n');
|
||||
qDebug() << content;
|
||||
qCDebug(ozwmp) << content;
|
||||
});
|
||||
|
||||
this->m_client->setWillTopic(getTopic(MQTT_OZW_STATUS_TOPIC));
|
||||
|
@ -328,6 +341,11 @@ void mqttpublisher::doStats() {
|
|||
|
||||
}
|
||||
|
||||
bool mqttpublisher::isValidNode(quint8 node) {
|
||||
return this->m_nodeModel->isValidNode(node);
|
||||
}
|
||||
|
||||
|
||||
QString mqttpublisher::getTopic(QString topic) {
|
||||
return QString(MQTT_OZW_TOP_TOPIC).arg(settings.value("Instance", 1).toInt()).append(topic);
|
||||
}
|
||||
|
@ -404,7 +422,7 @@ void mqttpublisher::updateLogStateChange()
|
|||
const QString content = QDateTime::currentDateTime().toString()
|
||||
+ QLatin1String(": State Change: " )
|
||||
+ QString::number(m_client->state());
|
||||
qDebug() << content;
|
||||
qCDebug(ozwmp) << content;
|
||||
if (this->m_client->state() == QMqttClient::ClientState::Connected) {
|
||||
this->m_client->subscribe(QMqttTopicFilter("/OpenZWave/commands"));
|
||||
this->m_commands->setupSubscriptions(this->m_client, this->getCommandTopic());
|
||||
|
@ -414,11 +432,11 @@ void mqttpublisher::updateLogStateChange()
|
|||
|
||||
void mqttpublisher::brokerDisconnected()
|
||||
{
|
||||
qDebug() << "Disconnnected";
|
||||
qCDebug(ozwmp) << "Disconnnected";
|
||||
}
|
||||
|
||||
void mqttpublisher::handleMessage(const QByteArray &message, const QMqttTopicName &topic) {
|
||||
qDebug() << "Received: " << topic.name() << ":" << message;
|
||||
qCDebug(ozwmp) << "Received: " << topic.name() << ":" << message;
|
||||
}
|
||||
|
||||
|
||||
|
@ -435,7 +453,7 @@ bool mqttpublisher::sendNodeUpdate(quint8 node) {
|
|||
bool mqttpublisher::sendValueUpdate(quint64 vidKey) {
|
||||
quint8 node = this->m_valueModel->getValueData(vidKey, QTOZW_ValueIds::Node).value<quint8>();
|
||||
if (node == 0) {
|
||||
qWarning() << "sendValueUpdate: Can't find Node for Value: " << vidKey;
|
||||
qCWarning(ozwmp) << "sendValueUpdate: Can't find Node for Value: " << vidKey;
|
||||
return false;
|
||||
}
|
||||
this->m_client->publish(QMqttTopicName(getValueTopic(MQTT_OZW_VID_TOPIC, node, vidKey)), QJsonDocument(this->m_values[vidKey]).toJson(), 0, true);
|
||||
|
@ -454,7 +472,7 @@ bool mqttpublisher::delNodeTopic(quint8 node) {
|
|||
bool mqttpublisher::delValueTopic(quint64 vidKey) {
|
||||
quint8 node = this->m_valueModel->getValueData(vidKey, QTOZW_ValueIds::Node).value<quint8>();
|
||||
if (node == 0) {
|
||||
qWarning() << "delValueTopic: Can't find Node for Value: " << vidKey;
|
||||
qCWarning(ozwmp) << "delValueTopic: Can't find Node for Value: " << vidKey;
|
||||
return false;
|
||||
}
|
||||
this->m_client->publish(QMqttTopicName(getValueTopic(MQTT_OZW_VID_TOPIC, node, vidKey)), NULL, 0, false);
|
||||
|
@ -463,55 +481,55 @@ bool mqttpublisher::delValueTopic(quint64 vidKey) {
|
|||
|
||||
|
||||
void mqttpublisher::ready() {
|
||||
qDebug() << "Publishing Event ready:";
|
||||
qCDebug(ozwmp) << "Publishing Event ready:";
|
||||
this->m_ozwstatus["Status"] = "Ready";
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::valueAdded(quint64 vidKey) {
|
||||
qDebug() << "Publishing Event valueAdded:" << vidKey;
|
||||
qCDebug(ozwmp) << "Publishing Event valueAdded:" << vidKey;
|
||||
this->m_valueModel->populateJsonObject(&this->m_values[vidKey], vidKey, this->m_qtozwdeamon->getManager());
|
||||
this->m_values[vidKey]["Event"] = "valueAdded";
|
||||
this->sendValueUpdate(vidKey);
|
||||
}
|
||||
void mqttpublisher::valueRemoved(quint64 vidKey) {
|
||||
qDebug() << "Publishing Event valueRemoved:" << vidKey;
|
||||
qCDebug(ozwmp) << "Publishing Event valueRemoved:" << vidKey;
|
||||
this->delValueTopic(vidKey);
|
||||
}
|
||||
void mqttpublisher::valueChanged(quint64 vidKey) {
|
||||
qDebug() << "Publishing Event valueChanged:" << vidKey;
|
||||
qCDebug(ozwmp) << "Publishing Event valueChanged:" << vidKey;
|
||||
this->m_values[vidKey]["Event"] = "valueChanged";
|
||||
this->m_values[vidKey]["Value"] = this->m_valueModel->encodeValue(vidKey);
|
||||
this->sendValueUpdate(vidKey);
|
||||
|
||||
}
|
||||
void mqttpublisher::valueRefreshed(quint64 vidKey) {
|
||||
qDebug() << "Publishing Event valueRefreshed:" << vidKey;
|
||||
qCDebug(ozwmp) << "Publishing Event valueRefreshed:" << vidKey;
|
||||
this->m_values[vidKey]["Event"] = "valueRefreshed";
|
||||
this->m_values[vidKey]["Value"] = this->m_valueModel->encodeValue(vidKey);
|
||||
this->sendValueUpdate(vidKey);
|
||||
}
|
||||
void mqttpublisher::nodeNew(quint8 node) {
|
||||
qDebug() << "Publishing Event NodeNew:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event NodeNew:" << node;
|
||||
this->m_nodeModel->populateJsonObject(&this->m_nodes[node], node, this->m_qtozwdeamon->getManager());
|
||||
this->m_nodes[node]["Event"] = "nodeNew";
|
||||
this->sendNodeUpdate(node);
|
||||
}
|
||||
void mqttpublisher::nodeAdded(quint8 node) {
|
||||
qDebug() << "Publishing Event NodeAdded:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event NodeAdded:" << node;
|
||||
this->m_nodeModel->populateJsonObject(&this->m_nodes[node], node, this->m_qtozwdeamon->getManager());
|
||||
this->m_nodes[node]["Event"] = "nodeAdded";
|
||||
this->sendNodeUpdate(node);
|
||||
}
|
||||
void mqttpublisher::nodeRemoved(quint8 node) {
|
||||
qDebug() << "Publishing Event nodeRemoved:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event nodeRemoved:" << node;
|
||||
this->delNodeTopic(node);
|
||||
}
|
||||
void mqttpublisher::nodeReset(quint8 node) {
|
||||
qDebug() << "Publishing Event nodeReset:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event nodeReset:" << node;
|
||||
this->delNodeTopic(node);
|
||||
}
|
||||
void mqttpublisher::nodeNaming(quint8 node) {
|
||||
qDebug() << "Publishing Event nodeNaming:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event nodeNaming:" << node;
|
||||
this->m_nodes[node]["Event"] = "nodeNaming";
|
||||
this->sendNodeUpdate(node);
|
||||
}
|
||||
|
@ -523,64 +541,64 @@ void mqttpublisher::nodeEvent(quint8 node, quint8 event) {
|
|||
*/
|
||||
}
|
||||
void mqttpublisher::nodeProtocolInfo(quint8 node) {
|
||||
qDebug() << "Publishing Event nodeProtocolInfo:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event nodeProtocolInfo:" << node;
|
||||
this->m_nodeModel->populateJsonObject(&this->m_nodes[node], node, this->m_qtozwdeamon->getManager());
|
||||
this->m_nodes[node]["Event"] = "nodeProtocolInfo";
|
||||
this->sendNodeUpdate(node);
|
||||
}
|
||||
void mqttpublisher::nodeEssentialNodeQueriesComplete(quint8 node) {
|
||||
qDebug() << "Publishing Event nodeEssentialNodeQueriesComplete:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event nodeEssentialNodeQueriesComplete:" << node;
|
||||
this->m_nodeModel->populateJsonObject(&this->m_nodes[node], node, this->m_qtozwdeamon->getManager());
|
||||
this->m_nodes[node]["Event"] = "nodeEssentialNodeQueriesComplete";
|
||||
this->sendNodeUpdate(node);
|
||||
}
|
||||
void mqttpublisher::nodeQueriesComplete(quint8 node) {
|
||||
qDebug() << "Publishing Event nodeQueriesComplete:" << node;
|
||||
qCDebug(ozwmp) << "Publishing Event nodeQueriesComplete:" << node;
|
||||
this->m_nodeModel->populateJsonObject(&this->m_nodes[node], node, this->m_qtozwdeamon->getManager());
|
||||
this->m_nodes[node]["Event"] = "nodeQueriesComplete";
|
||||
this->sendNodeUpdate(node);
|
||||
}
|
||||
void mqttpublisher::driverReady(quint32 homeID) {
|
||||
qDebug() << "Publishing Event driverReady:" << homeID;
|
||||
qCDebug(ozwmp) << "Publishing Event driverReady:" << homeID;
|
||||
this->m_ozwstatus["Status"] = "driverReady";
|
||||
this->m_ozwstatus["homeID"] = QJsonValue(static_cast<int>(homeID));
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::driverFailed(quint32 homeID) {
|
||||
qDebug() << "Publishing Event driverFailed:" << homeID;
|
||||
qCDebug(ozwmp) << "Publishing Event driverFailed:" << homeID;
|
||||
this->m_ozwstatus["Status"] = "driverFailed";
|
||||
this->m_ozwstatus["homeID"] = QJsonValue(static_cast<int>(homeID));
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::driverReset(quint32 homeID) {
|
||||
qDebug() << "Publishing Event driverReset:" << homeID;
|
||||
qCDebug(ozwmp) << "Publishing Event driverReset:" << homeID;
|
||||
this->m_ozwstatus["Status"] = "driverReset";
|
||||
this->m_ozwstatus["homeID"] = QJsonValue(static_cast<int>(homeID));
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::driverRemoved(quint32 homeID) {
|
||||
qDebug() << "Publishing Event driverRemoved:" << homeID;
|
||||
qCDebug(ozwmp) << "Publishing Event driverRemoved:" << homeID;
|
||||
this->m_ozwstatus["Status"] = "driverRemoved";
|
||||
this->m_ozwstatus["homeID"] = QJsonValue(static_cast<int>(homeID));
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::driverAllNodesQueriedSomeDead() {
|
||||
qDebug() << "Publishing Event driverAllNodesQueriedSomeDead:" ;
|
||||
qCDebug(ozwmp) << "Publishing Event driverAllNodesQueriedSomeDead:" ;
|
||||
this->m_ozwstatus["Status"] = "driverAllNodesQueriedSomeDead";
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::driverAllNodesQueried() {
|
||||
qDebug() << "Publishing Event driverAllNodesQueried:" ;
|
||||
qCDebug(ozwmp) << "Publishing Event driverAllNodesQueried:" ;
|
||||
this->m_ozwstatus["Status"] = "driverAllNodesQueried";
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::driverAwakeNodesQueried() {
|
||||
qDebug() << "Publishing Event driverAwakeNodesQueried:" ;
|
||||
qCDebug(ozwmp) << "Publishing Event driverAwakeNodesQueried:" ;
|
||||
this->m_ozwstatus["Status"] = "driverAwakeNodesQueried";
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::controllerCommand(quint8 node, NotificationTypes::QTOZW_Notification_Controller_Cmd command, NotificationTypes::QTOZW_Notification_Controller_State state, NotificationTypes::QTOZW_Notification_Controller_Error error) {
|
||||
qDebug() << "Publishing Event controllerCommand" << node << command << state << error;
|
||||
qCDebug(ozwmp) << "Publishing Event controllerCommand" << node << command << state << error;
|
||||
QJsonObject js;
|
||||
if (node > 0)
|
||||
js["Node"] = node;
|
||||
|
@ -593,7 +611,7 @@ void mqttpublisher::controllerCommand(quint8 node, NotificationTypes::QTOZW_Noti
|
|||
|
||||
switch(command) {
|
||||
case NotificationTypes::Ctrl_Cmd_None: {
|
||||
qWarning() << "Got a controllerCommand Event with no Controller Command" << command << state << error;
|
||||
qCWarning(ozwmp) << "Got a controllerCommand Event with no Controller Command" << command << state << error;
|
||||
break;
|
||||
}
|
||||
case NotificationTypes::Ctrl_Cmd_AddNode: {
|
||||
|
@ -673,7 +691,7 @@ void mqttpublisher::controllerCommand(quint8 node, NotificationTypes::QTOZW_Noti
|
|||
};
|
||||
}
|
||||
void mqttpublisher::ozwNotification(quint8 node, NotificationTypes::QTOZW_Notification_Code event) {
|
||||
qDebug() << "Publishing Event ozwNotification";
|
||||
qCDebug(ozwmp) << "Publishing Event ozwNotification";
|
||||
QJsonObject js;
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<NotificationTypes::QTOZW_Notification_Code>();
|
||||
js["Node"] = node;
|
||||
|
@ -681,7 +699,7 @@ void mqttpublisher::ozwNotification(quint8 node, NotificationTypes::QTOZW_Notifi
|
|||
this->sendCommandUpdate("Notification", js);
|
||||
}
|
||||
void mqttpublisher::ozwUserAlert(quint8 node, NotificationTypes::QTOZW_Notification_User event, quint8 retry) {
|
||||
qDebug() << "Publishing Event ozwNotification";
|
||||
qCDebug(ozwmp) << "Publishing Event ozwNotification";
|
||||
QJsonObject js;
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<NotificationTypes::QTOZW_Notification_User>();
|
||||
js["Node"] = node;
|
||||
|
@ -692,25 +710,25 @@ void mqttpublisher::ozwUserAlert(quint8 node, NotificationTypes::QTOZW_Notificat
|
|||
this->sendCommandUpdate("UserAlert", js);
|
||||
}
|
||||
void mqttpublisher::manufacturerSpecificDBReady() {
|
||||
qDebug() << "Publishing Event manufacturerSpecificDBReady";
|
||||
qCDebug(ozwmp) << "Publishing Event manufacturerSpecificDBReady";
|
||||
this->m_ozwstatus["ManufacturerSpecificDBReady"] = true;
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
|
||||
void mqttpublisher::starting() {
|
||||
qDebug() << "Publishing Event starting";
|
||||
qCDebug(ozwmp) << "Publishing Event starting";
|
||||
this->m_ozwstatus["Status"] = "starting";
|
||||
this->sendStatusUpdate();
|
||||
}
|
||||
void mqttpublisher::started(quint32 homeID) {
|
||||
qDebug() << "Publishing Event started";
|
||||
qCDebug(ozwmp) << "Publishing Event started";
|
||||
this->m_ozwstatus["Status"] = "started";
|
||||
this->m_ozwstatus["homeID"] = QJsonValue(static_cast<int>(homeID));
|
||||
this->sendStatusUpdate();
|
||||
this->m_statsTimer.start(10000);
|
||||
}
|
||||
void mqttpublisher::stopped(quint32 homeID) {
|
||||
qDebug() << "Publishing Event stopped";
|
||||
qCDebug(ozwmp) << "Publishing Event stopped";
|
||||
this->m_ozwstatus["Status"] = "stopped";
|
||||
this->m_ozwstatus["homeID"] = QJsonValue(static_cast<int>(homeID));
|
||||
this->sendStatusUpdate();
|
||||
|
|
|
@ -21,13 +21,14 @@ class MqttCommands;
|
|||
#define MQTT_OZW_COMMAND_TOPIC "command/%1/"
|
||||
#define MQTT_OZW_RESPONSE_TOPIC "event/%1/"
|
||||
|
||||
|
||||
class mqttNodeModel : public QTOZW_Nodes {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit mqttNodeModel(QObject *parent = nullptr);
|
||||
|
||||
QVariant getNodeData(quint8, NodeColumns);
|
||||
bool populateJsonObject(QJsonObject *, quint8, QTOZWManager *);
|
||||
bool isValidNode(quint8);
|
||||
};
|
||||
|
||||
class mqttValueIDModel : public QTOZW_ValueIds {
|
||||
|
@ -45,7 +46,9 @@ class mqttpublisher : public QObject
|
|||
public:
|
||||
explicit mqttpublisher(QObject *parent = nullptr);
|
||||
void setOZWDaemon(qtozwdaemon *ozwdaemon);
|
||||
|
||||
QTOZWManager *getQTOZWManager();
|
||||
void sendCommandUpdate(QString, QJsonObject);
|
||||
bool isValidNode(quint8 node);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
@ -80,11 +83,6 @@ public slots:
|
|||
void stopped(quint32 homeID);
|
||||
// void error(QTOZWErrorCodes errorcode);
|
||||
|
||||
|
||||
QTOZWManager *getQTOZWManager();
|
||||
void sendCommandUpdate(QString, QJsonObject);
|
||||
|
||||
|
||||
private slots:
|
||||
void updateLogStateChange();
|
||||
void brokerDisconnected();
|
||||
|
|
|
@ -11,7 +11,7 @@ CONFIG -= app_bundle
|
|||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
DEFINES += QT_DEPRECATED_WARNINGS QT_MESSAGELOGCONTEXT
|
||||
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
|
@ -38,7 +38,6 @@ qtHaveModule(mqtt) {
|
|||
mqttcommands/healNetworkNode.cpp \
|
||||
mqttcommands/healNetwork.cpp \
|
||||
mqttcommands/addNode.cpp \
|
||||
mqttcommands/addNodeSecure.cpp \
|
||||
mqttcommands/removeNode.cpp \
|
||||
mqttcommands/removeFailedNode.cpp \
|
||||
mqttcommands/hasNodeFailed.cpp \
|
||||
|
@ -71,7 +70,6 @@ qtHaveModule(mqtt) {
|
|||
mqttcommands/healNetworkNode.h \
|
||||
mqttcommands/healNetwork.h \
|
||||
mqttcommands/addNode.h \
|
||||
mqttcommands/addNodeSecure.h \
|
||||
mqttcommands/removeNode.h \
|
||||
mqttcommands/removeFailedNode.h \
|
||||
mqttcommands/hasNodeFailed.h \
|
||||
|
@ -113,6 +111,7 @@ unix {
|
|||
LIBS += -lresolv -L../qt-openzwave/ -lqt-openzwave -L../qt-openzwavedatabase/ -lqt-openzwavedatabase
|
||||
INCLUDEPATH += ../qt-openzwavedatabase/include/
|
||||
QMAKE_CXXFLAGS += -g1
|
||||
QMAKE_LFLAGS += -rdynamic
|
||||
}
|
||||
win32 {
|
||||
LIBS += -lDnsapi -L../qt-openzwave/$$BUILDTYPE/ -lqt-openzwave1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue