Add some additional manager methods etc

This commit is contained in:
Justin Hammond 2019-12-04 16:25:13 +08:00
parent 8c8da7fc03
commit e0f7cb9410
18 changed files with 225 additions and 4 deletions

View file

@ -139,6 +139,8 @@ public:
void syncroniseNodeNeighbors(quint8 node);
bool refreshValue(quint64);
/* Property Methods */
QDir OZWDatabasePath() { return this->m_ozwdatabasepath; }

View file

@ -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))

View file

@ -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);

View file

@ -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())

View file

@ -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<QTOZW_Nodes *>(this->m_nodeModel);

View file

@ -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);
}

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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) {

View file

@ -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()));
}

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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();
}

View file

@ -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")
}