From e0f7cb9410b86cd43d9d6e9895619db789d53316 Mon Sep 17 00:00:00 2001 From: Justin Hammond Date: Wed, 4 Dec 2019 16:25:13 +0800 Subject: [PATCH] Add some additional manager methods etc --- .../include/qt-openzwave/qtozwmanager.h | 2 ++ .../include/qt-openzwave/qtozwmanager.rep | 1 + qt-openzwave/include/qtozwmanager_p.h | 2 ++ qt-openzwave/source/qtozwmanager.cpp | 3 +++ qt-openzwave/source/qtozwmanager_p.cpp | 16 +++++++++++++++ qt-ozwdaemon/mqttcommands/enablePoll.cpp | 20 +++++++++++++++++++ qt-ozwdaemon/mqttcommands/enablePoll.h | 17 ++++++++++++++++ qt-ozwdaemon/mqttcommands/getPollInterval.cpp | 19 ++++++++++++++++++ qt-ozwdaemon/mqttcommands/getPollInterval.h | 17 ++++++++++++++++ qt-ozwdaemon/mqttcommands/mqttcommands.cpp | 10 ++++++++++ qt-ozwdaemon/mqttcommands/refreshValue.cpp | 19 ++++++++++++++++++ qt-ozwdaemon/mqttcommands/refreshValue.h | 17 ++++++++++++++++ qt-ozwdaemon/mqttcommands/setPollInterval.cpp | 17 ++++++++++++++++ qt-ozwdaemon/mqttcommands/setPollInterval.h | 17 ++++++++++++++++ .../mqttcommands/syncroniseNodeNeighbors.cpp | 20 +++++++++++++++++++ .../mqttcommands/syncroniseNodeNeighbors.h | 17 ++++++++++++++++ qt-ozwdaemon/mqttpublisher.cpp | 2 -- qt-ozwdaemon/qt-ozwdaemon.pro | 13 ++++++++++-- 18 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 qt-ozwdaemon/mqttcommands/enablePoll.cpp create mode 100644 qt-ozwdaemon/mqttcommands/enablePoll.h create mode 100644 qt-ozwdaemon/mqttcommands/getPollInterval.cpp create mode 100644 qt-ozwdaemon/mqttcommands/getPollInterval.h create mode 100644 qt-ozwdaemon/mqttcommands/refreshValue.cpp create mode 100644 qt-ozwdaemon/mqttcommands/refreshValue.h create mode 100644 qt-ozwdaemon/mqttcommands/setPollInterval.cpp create mode 100644 qt-ozwdaemon/mqttcommands/setPollInterval.h create mode 100644 qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.cpp create mode 100644 qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.h diff --git a/qt-openzwave/include/qt-openzwave/qtozwmanager.h b/qt-openzwave/include/qt-openzwave/qtozwmanager.h index b3ea4e3..c99ab29 100644 --- a/qt-openzwave/include/qt-openzwave/qtozwmanager.h +++ b/qt-openzwave/include/qt-openzwave/qtozwmanager.h @@ -139,6 +139,8 @@ public: void syncroniseNodeNeighbors(quint8 node); + bool refreshValue(quint64); + /* Property Methods */ QDir OZWDatabasePath() { return this->m_ozwdatabasepath; } diff --git a/qt-openzwave/include/qt-openzwave/qtozwmanager.rep b/qt-openzwave/include/qt-openzwave/qtozwmanager.rep index 7be8d10..a25c680 100644 --- a/qt-openzwave/include/qt-openzwave/qtozwmanager.rep +++ b/qt-openzwave/include/qt-openzwave/qtozwmanager.rep @@ -146,6 +146,7 @@ class QTOZWManager { SLOT(QString getLibraryTypeName()) SLOT(quint32 getSendQueueCount()) SLOT(QString getControllerPath()) + SLOT(bool refreshValue(quint64)) SLOT(qint32 getPollInterval()) SLOT(void setPollInterval(qint32 interval, bool intervalBetweenPolls)) diff --git a/qt-openzwave/include/qtozwmanager_p.h b/qt-openzwave/include/qtozwmanager_p.h index a3e8ffb..74401f3 100644 --- a/qt-openzwave/include/qtozwmanager_p.h +++ b/qt-openzwave/include/qtozwmanager_p.h @@ -133,6 +133,8 @@ public Q_SLOTS: void setPollInterval(qint32 interval, bool intervalBetweenPolls); void syncroniseNodeNeighbors(quint8 node); + bool refreshValue(quint64); + /* these slots are called from our OZWNotification Class. Applications should not call them */ void pvt_valueAdded(quint64 vidKey); void pvt_valueRemoved(quint64 vidKey); diff --git a/qt-openzwave/source/qtozwmanager.cpp b/qt-openzwave/source/qtozwmanager.cpp index c22ebec..336c286 100644 --- a/qt-openzwave/source/qtozwmanager.cpp +++ b/qt-openzwave/source/qtozwmanager.cpp @@ -449,6 +449,9 @@ void QTOZWManager::setPollInterval(qint32 interval, bool intervalBetweenPolls) { void QTOZWManager::syncroniseNodeNeighbors(quint8 node) { CALL_DPTR(syncroniseNodeNeighbors(node)); } +bool QTOZWManager::refreshValue(quint64 vidKey) { + CALL_DPTR_RTN(refreshValue(vidKey), bool); +} void QTOZWManager::setOZWDatabasePath(QDir path) { if (path.exists()) diff --git a/qt-openzwave/source/qtozwmanager_p.cpp b/qt-openzwave/source/qtozwmanager_p.cpp index b8e01d5..6ea60e9 100644 --- a/qt-openzwave/source/qtozwmanager_p.cpp +++ b/qt-openzwave/source/qtozwmanager_p.cpp @@ -826,6 +826,22 @@ void QTOZWManager_Internal::syncroniseNodeNeighbors(quint8 node) { return; } +bool QTOZWManager_Internal::refreshValue(quint64 vidKey) { + if (!this->checkHomeId()) + return false; + if (!this->checkValueKey(vidKey)) + return false; + try { + OpenZWave::ValueID vid(this->homeId(), vidKey); + return this->m_manager->RefreshValue(vid); + } catch (OpenZWave::OZWException &e) { + emit this->error(QTOZWManagerErrorCodes::OZWException); + this->setErrorString(e.GetMsg().c_str()); + } + return false; +} + + QTOZW_Nodes *QTOZWManager_Internal::getNodeModel() { return static_cast(this->m_nodeModel); diff --git a/qt-ozwdaemon/mqttcommands/enablePoll.cpp b/qt-ozwdaemon/mqttcommands/enablePoll.cpp new file mode 100644 index 0000000..a6745f7 --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/enablePoll.cpp @@ -0,0 +1,20 @@ +#include "mqttcommands/enablePoll.h" + +MqttCommand_EnablePoll::MqttCommand_EnablePoll(QObject *parent) : + MqttCommand(parent) +{ + this->m_requiredIntFields << "ValueIDKey"; +} +MqttCommand* MqttCommand_EnablePoll::Create(QObject *parent) { + return new MqttCommand_SyncroniseNodeNeighbors(parent); +} + +bool MqttCommand_EnablePoll::processMessage(rapidjson::Document &msg) { + if (!this->checkValue(msg, "ValueIDKey")) { + return this->sendSimpleStatus(false, "Invalid ValueIDKey Number"); + } + + QTOZWManager *mgr = getOZWManager(); + //mgr->syncroniseNodeNeighbors(msg["node"].GetInt()); + return this->sendSimpleStatus(true); +} \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/enablePoll.h b/qt-ozwdaemon/mqttcommands/enablePoll.h new file mode 100644 index 0000000..179e83a --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/enablePoll.h @@ -0,0 +1,17 @@ +#ifndef ENABLEPOLL_H +#define ENABLEPOLL_H + +#include "mqttcommands/mqttcommands.h" + +class MqttCommand_EnablePoll : public MqttCommand { + Q_OBJECT +public: + static MqttCommand *Create(QObject *parent = nullptr); + static QString StaticGetCommand() { return "enablePoll";}; + QString GetCommand() override { return StaticGetCommand(); }; + bool processMessage(rapidjson::Document &) override; +private: + MqttCommand_EnablePoll(QObject *parent = nullptr); +}; + +#endif // ENABLEPOLL_H \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/getPollInterval.cpp b/qt-ozwdaemon/mqttcommands/getPollInterval.cpp new file mode 100644 index 0000000..9578251 --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/getPollInterval.cpp @@ -0,0 +1,19 @@ +#include "mqttcommands/getPollInterval.h" + +MqttCommand_GetPollInterval::MqttCommand_GetPollInterval(QObject *parent) : + MqttCommand(parent) +{ +} +MqttCommand* MqttCommand_GetPollInterval::Create(QObject *parent) { + return new MqttCommand_GetPollInterval(parent); +} + +bool MqttCommand_GetPollInterval::processMessage(rapidjson::Document &msg) { + Q_UNUSED(msg); + QTOZWManager *mgr = getOZWManager(); + rapidjson::Document js; + QT2JS::SetString(js, "status", "ok"); + QT2JS::SetInt64(js, "pollInterval", mgr->getPollInterval()); + emit sendCommandUpdate(GetCommand(), js); + return true; +} \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/getPollInterval.h b/qt-ozwdaemon/mqttcommands/getPollInterval.h new file mode 100644 index 0000000..b9deb3d --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/getPollInterval.h @@ -0,0 +1,17 @@ +#ifndef GETPOLLINTERVAL_H +#define GETPOLLINTERVAL_H + +#include "mqttcommands/mqttcommands.h" + +class MqttCommand_GetPollInterval : public MqttCommand { + Q_OBJECT +public: + static MqttCommand *Create(QObject *parent = nullptr); + static QString StaticGetCommand() { return "getPollInterval";}; + QString GetCommand() override { return StaticGetCommand(); }; + bool processMessage(rapidjson::Document &) override; +private: + MqttCommand_GetPollInterval(QObject *parent = nullptr); +}; + +#endif // GETPOLLINTERVAL_H \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/mqttcommands.cpp b/qt-ozwdaemon/mqttcommands/mqttcommands.cpp index 4fc35e6..a572890 100644 --- a/qt-ozwdaemon/mqttcommands/mqttcommands.cpp +++ b/qt-ozwdaemon/mqttcommands/mqttcommands.cpp @@ -33,6 +33,11 @@ #include "mqttcommands/downloadLatestConfigFileRevision.h" #include "mqttcommands/downloadLatestMFSRevision.h" #include "mqttcommands/setValue.h" +#include "mqttcommands/getPollInterval.h" +#include "mqttcommands/setPollInterval.h" +#include "mqttcommands/syncroniseNodeNeighbors.h" +#include "mqttcommands/enablePoll.h" +#include "mqttcommands/refreshValue.h" Q_LOGGING_CATEGORY(ozwmc, "ozw.mqtt.commands"); @@ -241,6 +246,11 @@ void MqttCommands::setupCommands() { this->Register(MqttCommand_DownloadLatestConfigFileRevision::StaticGetCommand(), &MqttCommand_DownloadLatestConfigFileRevision::Create); this->Register(MqttCommand_DownloadLatestMFSRevision::StaticGetCommand(), &MqttCommand_DownloadLatestMFSRevision::Create); this->Register(MqttCommand_SetValue::StaticGetCommand(), &MqttCommand_SetValue::Create); + this->Register(MqttCommand_GetPollInterval::StaticGetCommand(), &MqttCommand_GetPollInterval::Create); + this->Register(MqttCommand_SetPollInterval::StaticGetCommand(), &MqttCommand_SetPollInterval::Create); + this->Register(MqttCommand_SyncroniseNodeNeighbors::StaticGetCommand(), &MqttCommand_SyncroniseNodeNeighbors::Create); +// this->Register(MqttCommand_EnablePoll::StaticGetCommand(), &MqttCommand_EnablePoll::Create); + this->Register(MqttCommand_RefreshValue::StaticGetCommand(), &MqttCommand_RefreshValue::Create); } void MqttCommands::setupSubscriptions(QMqttClient *mqttclient, QString topTopic) { diff --git a/qt-ozwdaemon/mqttcommands/refreshValue.cpp b/qt-ozwdaemon/mqttcommands/refreshValue.cpp new file mode 100644 index 0000000..21b47f5 --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/refreshValue.cpp @@ -0,0 +1,19 @@ +#include "mqttcommands/refreshValue.h" + +MqttCommand_RefreshValue::MqttCommand_RefreshValue(QObject *parent) : + MqttCommand(parent) +{ + this->m_requiredIntFields << "ValueIDKey"; +} +MqttCommand* MqttCommand_RefreshValue::Create(QObject *parent) { + return new MqttCommand_RefreshValue(parent); +} + +bool MqttCommand_RefreshValue::processMessage(rapidjson::Document &msg) { + if (!this->checkValue(msg, "ValueIDKey")) { + return this->sendSimpleStatus(false, "Invalid ValueIDKey Number"); + } + + QTOZWManager *mgr = getOZWManager(); + return this->sendSimpleStatus(mgr->refreshValue(msg["ValueIDKey"].GetUint64())); +} \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/refreshValue.h b/qt-ozwdaemon/mqttcommands/refreshValue.h new file mode 100644 index 0000000..f4e0b5f --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/refreshValue.h @@ -0,0 +1,17 @@ +#ifndef REFRESHVALUE_H +#define REFRESHVALUE_H + +#include "mqttcommands/mqttcommands.h" + +class MqttCommand_RefreshValue : public MqttCommand { + Q_OBJECT +public: + static MqttCommand *Create(QObject *parent = nullptr); + static QString StaticGetCommand() { return "refreshValue";}; + QString GetCommand() override { return StaticGetCommand(); }; + bool processMessage(rapidjson::Document &) override; +private: + MqttCommand_RefreshValue(QObject *parent = nullptr); +}; + +#endif // REFRESHVALUE_H \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/setPollInterval.cpp b/qt-ozwdaemon/mqttcommands/setPollInterval.cpp new file mode 100644 index 0000000..01f9cc5 --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/setPollInterval.cpp @@ -0,0 +1,17 @@ +#include "mqttcommands/setPollInterval.h" + +MqttCommand_SetPollInterval::MqttCommand_SetPollInterval(QObject *parent) : + MqttCommand(parent) +{ + this->m_requiredIntFields << "interval"; + this->m_requiredBoolFields << "intervalBetweenPoll"; +} +MqttCommand* MqttCommand_SetPollInterval::Create(QObject *parent) { + return new MqttCommand_SetPollInterval(parent); +} + +bool MqttCommand_SetPollInterval::processMessage(rapidjson::Document &msg) { + QTOZWManager *mgr = getOZWManager(); + mgr->setPollInterval(msg["interval"].GetUint(), msg["intervalBetweenPoll"].GetBool()); + return this->sendSimpleStatus(true); +} \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/setPollInterval.h b/qt-ozwdaemon/mqttcommands/setPollInterval.h new file mode 100644 index 0000000..e154e56 --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/setPollInterval.h @@ -0,0 +1,17 @@ +#ifndef SETPOLLINTERVAL_H +#define SETPOLLINTERVAL_H + +#include "mqttcommands/mqttcommands.h" + +class MqttCommand_SetPollInterval : public MqttCommand { + Q_OBJECT +public: + static MqttCommand *Create(QObject *parent = nullptr); + static QString StaticGetCommand() { return "setPollInterval";}; + QString GetCommand() override { return StaticGetCommand(); }; + bool processMessage(rapidjson::Document &) override; +private: + MqttCommand_SetPollInterval(QObject *parent = nullptr); +}; + +#endif // SETPOLLINTERVAL_H \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.cpp b/qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.cpp new file mode 100644 index 0000000..4c0a261 --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.cpp @@ -0,0 +1,20 @@ +#include "mqttcommands/syncroniseNodeNeighbors.h" + +MqttCommand_SyncroniseNodeNeighbors::MqttCommand_SyncroniseNodeNeighbors(QObject *parent) : + MqttCommand(parent) +{ + this->m_requiredIntFields << "node"; +} +MqttCommand* MqttCommand_SyncroniseNodeNeighbors::Create(QObject *parent) { + return new MqttCommand_SyncroniseNodeNeighbors(parent); +} + +bool MqttCommand_SyncroniseNodeNeighbors::processMessage(rapidjson::Document &msg) { + if (!this->checkNode(msg, "node")) { + return this->sendSimpleStatus(false, "Invalid Node Number"); + } + + QTOZWManager *mgr = getOZWManager(); + mgr->syncroniseNodeNeighbors(msg["node"].GetInt()); + return this->sendSimpleStatus(true); +} \ No newline at end of file diff --git a/qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.h b/qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.h new file mode 100644 index 0000000..78ff86c --- /dev/null +++ b/qt-ozwdaemon/mqttcommands/syncroniseNodeNeighbors.h @@ -0,0 +1,17 @@ +#ifndef SYNCNODENEIGHBORS_H +#define SYNCNODENEIGHBORS_H + +#include "mqttcommands/mqttcommands.h" + +class MqttCommand_SyncroniseNodeNeighbors : public MqttCommand { + Q_OBJECT +public: + static MqttCommand *Create(QObject *parent = nullptr); + static QString StaticGetCommand() { return "syncroniseNodeNeighbors";}; + QString GetCommand() override { return StaticGetCommand(); }; + bool processMessage(rapidjson::Document &) override; +private: + MqttCommand_SyncroniseNodeNeighbors(QObject *parent = nullptr); +}; + +#endif // SYNCNODENEIGHBORS_H \ No newline at end of file diff --git a/qt-ozwdaemon/mqttpublisher.cpp b/qt-ozwdaemon/mqttpublisher.cpp index bb970ab..05d804f 100644 --- a/qt-ozwdaemon/mqttpublisher.cpp +++ b/qt-ozwdaemon/mqttpublisher.cpp @@ -303,7 +303,6 @@ bool mqttpublisher::clearStatusUpdate() { QT2JS::removeField(this->m_ozwstatus, "getControllerLibraryVersion"); QT2JS::removeField(this->m_ozwstatus, "getControllerLibraryType"); QT2JS::removeField(this->m_ozwstatus, "getControllerPath"); - QT2JS::removeField(this->m_ozwstatus, "pollInterval"); return true; } @@ -577,7 +576,6 @@ void mqttpublisher::driverReady(quint32 homeID) { QT2JS::SetString(this->m_ozwstatus, "getControllerLibraryVersion", this->getQTOZWManager()->getLibraryVersion()); QT2JS::SetString(this->m_ozwstatus, "getControllerLibraryType", this->getQTOZWManager()->getLibraryTypeName()); QT2JS::SetString(this->m_ozwstatus, "getControllerPath", this->getQTOZWManager()->getControllerPath()); - QT2JS::SetUint(this->m_ozwstatus, "pollInterval", this->getQTOZWManager()->getPollInterval()); QT2JS::SetUint(this->m_ozwstatus, "homeID", homeID); this->sendStatusUpdate(); } diff --git a/qt-ozwdaemon/qt-ozwdaemon.pro b/qt-ozwdaemon/qt-ozwdaemon.pro index 2d07735..148c1ba 100644 --- a/qt-ozwdaemon/qt-ozwdaemon.pro +++ b/qt-ozwdaemon/qt-ozwdaemon.pro @@ -59,7 +59,11 @@ qtHaveModule(mqtt) { mqttcommands/checkLatestMFSRevision.cpp \ mqttcommands/downloadLatestConfigFileRevision.cpp \ mqttcommands/downloadLatestMFSRevision.cpp \ - mqttcommands/setValue.cpp + mqttcommands/setValue.cpp \ + mqttcommands/setPollInterval.cpp \ + mqttcommands/getPollINterval.cpp \ + mqttcommands/syncroniseNodeNeighbors.cpp \ + mqttcommands/refreshValue.cpp HEADERS += mqttpublisher.h \ qtrj.h \ @@ -96,7 +100,12 @@ qtHaveModule(mqtt) { mqttcommands/CheckLatestMFSRevision.h \ mqttcommands/downloadLatestConfigFileRevision.h \ mqttcommands/downloadLatestMFSRevision.h \ - mqttcommands/setValue.h + mqttcommands/setValue.h \ + mqttcommands/setPollInterval.h \ + mqttcommands/getPollInterval.h\ + mqttcommands/syncroniseNodeNeighbors.h \ + mqttcommands/refreshValue.h + } else { warning("MQTT Qt Module Not Found. Not Building MQTT Client Capabilities") }