Node/Value Deletion - WIP

This commit is contained in:
Justin Hammond 2019-11-12 20:08:50 +08:00
parent 69a6cfb0d0
commit 77f792cb00
13 changed files with 81 additions and 44 deletions

View file

@ -76,6 +76,7 @@ public:
/* OpenZWave::Manager methods */
bool open(QString serialPort);
bool close();
bool refreshNodeInfo(quint8 _node);
bool requestNodeState(quint8 _node);
bool requestNodeDynamic(quint8 _node);

View file

@ -93,6 +93,7 @@ class QTOZWManager {
SIGNAL(error(QTOZWManagerErrorCodes errorcode))
SLOT(bool open(QString serialPort))
SLOT(bool close())
SLOT(bool refreshNodeInfo(quint8 _node))
SLOT(bool requestNodeState(quint8 _node))
SLOT(bool requestNodeDynamic(quint8 _node))

View file

@ -69,6 +69,7 @@ public:
public Q_SLOTS:
bool open(QString serialPort);
bool close();
bool refreshNodeInfo(quint8 _node);
bool requestNodeState(quint8 _node);
bool requestNodeDynamic(quint8 _node);
@ -164,7 +165,7 @@ private:
QVector<quint8> m_validNodes;
QVector<quint64> m_validValues;
QMap<quint8, QMap<quint8, bool > > m_associationDefaultsSet;
QString m_SerialPort;
};

View file

@ -94,17 +94,15 @@ void QTOZW_Associations_internal::setGroupFlags(quint8 _nodeID, quint8 _groupIDX
};
void QTOZW_Associations_internal::delNode(quint8 _nodeID) {
for (int i = 0; i <= rowCount(QModelIndex()); i++) {
if (this->m_associationData[i][associationColumns::NodeID] == _nodeID) {
qCDebug(associationModel) << "Removing Node " << this->m_associationData[i][associationColumns::NodeID] << i;
this->beginRemoveRows(QModelIndex(), i, i);
this->m_associationData.remove(i);
for (int j = i+1; i <= rowCount(QModelIndex()); j++) {
this->m_associationData[i] = this->m_associationData[j];
}
this->m_associationData.remove(rowCount(QModelIndex()));
QMap<qint32, QMap<QTOZW_Associations::associationColumns, QVariant> >::Iterator it;
for (it = this->m_associationData.begin(); it != this->m_associationData.end();) {
if (it.value()[associationColumns::NodeID] == _nodeID) {
qCDebug(associationModel) << "Removing Node " << it.value()[associationColumns::NodeID] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
it = this->m_associationData.erase(it);
this->endRemoveRows();
continue;
} else {
it++;
}
}
}

View file

@ -284,6 +284,9 @@ void QTOZWManager::connectSignals() {
bool QTOZWManager::open(QString serialPort) {
CALL_DPTR_RTN(open(serialPort), bool);
}
bool QTOZWManager::close() {
CALL_DPTR_RTN(close(), bool);
}
bool QTOZWManager::refreshNodeInfo(quint8 _node) {
CALL_DPTR_RTN(refreshNodeInfo(_node), bool);
}

View file

@ -144,7 +144,24 @@ bool QTOZWManager_Internal::open(QString SerialPort)
return false;
}
qCDebug(manager) << "AddDriver Completed";
this->m_SerialPort = SerialPort;
return true;
}
bool QTOZWManager_Internal::close() {
try {
if (this->m_manager->RemoveDriver(this->m_SerialPort.toStdString())) {
qCDebug(manager) << "Driver Removed for " << this->m_SerialPort;
} else {
qCWarning(manager) << "Couldn't Remove Driver for " << this->m_SerialPort;
}
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
qCWarning(manager) << "Failed to Remove Driver: " << QString(e.GetMsg().c_str());
return false;
}
this->m_SerialPort = QString();
return true;
}
@ -876,10 +893,10 @@ void QTOZWManager_Internal::pvt_valueAdded(quint64 vidKey)
void QTOZWManager_Internal::pvt_valueRemoved(quint64 vidKey)
{
qCDebug(notifications) << "Notification pvt_valueRemoved: " << vidKey;
emit this->valueRemoved(vidKey);
if (this->m_validValues.contains(vidKey))
this->m_validValues.removeAll(vidKey);
this->m_valueModel->delValue(vidKey);
emit this->valueRemoved(vidKey);
}
void QTOZWManager_Internal::pvt_valueChanged(quint64 vidKey)
{
@ -1322,6 +1339,13 @@ void QTOZWManager_Internal::pvt_driverReady(quint32 _homeID)
void QTOZWManager_Internal::pvt_driverFailed(quint32 _homeID)
{
qCDebug(notifications) << "Notification pvt_driverFailed " << _homeID;
QVector<quint64> valueList(this->m_validValues);
for (QVector<quint64>::Iterator it = valueList.begin(); it != valueList.end(); it++)
this->pvt_valueRemoved(*it);
QVector<quint8> nodeList(this->m_validNodes);
for (QVector<quint8>::iterator it = nodeList.begin(); it != nodeList.end(); it++)
this->pvt_nodeRemoved(*it);
this->m_associationsModel->resetModel();
this->m_valueModel->resetModel();
this->m_nodeModel->resetModel();
@ -1332,6 +1356,13 @@ void QTOZWManager_Internal::pvt_driverFailed(quint32 _homeID)
void QTOZWManager_Internal::pvt_driverReset(quint32 _homeID)
{
qCDebug(notifications) << "Notification pvt_driverReset " << _homeID;
QVector<quint64> valueList(this->m_validValues);
for (QVector<quint64>::Iterator it = valueList.begin(); it != valueList.end(); it++)
this->pvt_valueRemoved(*it);
QVector<quint8> nodeList(this->m_validNodes);
for (QVector<quint8>::iterator it = nodeList.begin(); it != nodeList.end(); it++)
this->pvt_nodeRemoved(*it);
this->m_associationsModel->resetModel();
this->m_valueModel->resetModel();
this->m_nodeModel->resetModel();
@ -1342,6 +1373,13 @@ void QTOZWManager_Internal::pvt_driverReset(quint32 _homeID)
void QTOZWManager_Internal::pvt_driverRemoved(quint32 _homeID)
{
qCDebug(notifications) << "Notification pvt_driverRemoved " << _homeID;
QVector<quint64> valueList(this->m_validValues);
for (QVector<quint64>::Iterator it = valueList.begin(); it != valueList.end(); it++)
this->pvt_valueRemoved(*it);
QVector<quint8> nodeList(this->m_validNodes);
for (QVector<quint8>::iterator it = nodeList.begin(); it != nodeList.end(); it++)
this->pvt_nodeRemoved(*it);
this->m_associationsModel->resetModel();
this->m_valueModel->resetModel();
this->m_nodeModel->resetModel();

View file

@ -88,21 +88,17 @@ void QTOZW_Nodes_internal::setNodeFlags(quint8 _nodeID, QTOZW_Nodes::nodeFlags _
}
void QTOZW_Nodes_internal::delNode(quint8 _nodeID) {
QMap<int32_t, QMap<NodeColumns, QVariant> >::iterator it;
QMap<int32_t, QMap<NodeColumns, QVariant> > newNodeMap;
int32_t newrow = 0;
for (it = this->m_nodeData.begin(); it != this->m_nodeData.end(); ++it) {
for (it = this->m_nodeData.begin(); it != this->m_nodeData.end();) {
if (it.value()[QTOZW_Nodes::NodeColumns::NodeID] == _nodeID) {
qCDebug(nodeModel) << "Removing Node " << it.value()[QTOZW_Nodes::NodeColumns::NodeID] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
this->m_nodeData.erase(it);
it = this->m_nodeData.erase(it);
this->endRemoveRows();
continue;
} else {
newNodeMap[newrow] = it.value();
newrow++;
it++;
}
}
this->m_nodeData.swap(newNodeMap);
}
void QTOZW_Nodes_internal::resetModel() {

View file

@ -51,15 +51,6 @@ void OZWNotification::processNotification
Q_UNUSED(_context);
//qDebug() << QString(_notification->GetAsString().c_str());
//qDebug() << _notification;
#if 0
void valueAdded(quint64 vidKey);
void valueRemoved(quint64 vidKey);
void valueChanged(quint64 vidKey);
void valueRefreshed(quint64 vidKey);
void valuePollingEnabled(quint64 vidKey);
void valuePollingDisabled(quint64 vidKey);
#endif
switch( _notification->GetType() )
{
case OpenZWave::Notification::Type_ValueAdded:

View file

@ -85,39 +85,32 @@ void QTOZW_ValueIds_internal::setValueFlags(quint64 _vidKey, QTOZW_ValueIds::Val
void QTOZW_ValueIds_internal::delValue(quint64 _vidKey) {
QMap<int32_t, QMap<ValueIdColumns, QVariant> >::iterator it;
QMap<int32_t, QMap<ValueIdColumns, QVariant> > newValueMap;
int32_t newrow = 0;
for (it = this->m_valueData.begin(); it != this->m_valueData.end(); ++it) {
for (it = this->m_valueData.begin(); it != this->m_valueData.end();) {
if (it.value()[QTOZW_ValueIds::ValueIdColumns::ValueIDKey] == _vidKey) {
qCDebug(valueModel) << "Removing Value " << it.value()[QTOZW_ValueIds::ValueIdColumns::Label] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
this->m_valueData.erase(it);
it = this->m_valueData.erase(it);
this->endRemoveRows();
continue;
} else {
newValueMap[newrow] = it.value();
newrow++;
it++;
}
}
this->m_valueData.swap(newValueMap);
}
void QTOZW_ValueIds_internal::delNodeValues(quint8 _node) {
QMap<int32_t, QMap<ValueIdColumns, QVariant> >::iterator it;
QMap<int32_t, QMap<ValueIdColumns, QVariant> > newValueMap;
qint32 newrow = 0;
for (it = this->m_valueData.begin(); it != this->m_valueData.end(); ++it) {
for (it = this->m_valueData.begin(); it != this->m_valueData.end();) {
if (it.value()[QTOZW_ValueIds::ValueIdColumns::Node] == _node) {
qCDebug(valueModel) << "Removing Value " << it.value()[QTOZW_ValueIds::ValueIdColumns::Label] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
this->m_valueData.erase(it);
it = this->m_valueData.erase(it);
this->endRemoveRows();
continue;
} else {
newValueMap[newrow] = it.value();
newrow++;
it++;
}
}
this->m_valueData.swap(newValueMap);
}
void QTOZW_ValueIds_internal::resetModel() {

View file

@ -4,6 +4,7 @@
#include "mqttcommands/mqttcommands.h"
#include "mqttcommands/ping.h"
#include "mqttcommands/open.h"
#include "mqttcommands/close.h"
#include "mqttcommands/refreshnodeinfo.h"
#include "mqttcommands/requestNodeState.h"
#include "mqttcommands/requestNodeDynamic.h"
@ -211,6 +212,7 @@ void MqttCommands::Register(QString command, pfnCreateCommand_t _create) {
void MqttCommands::setupCommands() {
this->Register(MqttCommand_Ping::StaticGetCommand(), &MqttCommand_Ping::Create);
this->Register(MqttCommand_Open::StaticGetCommand(), &MqttCommand_Open::Create);
this->Register(MqttCommand_Close::StaticGetCommand(), &MqttCommand_Close::Create);
this->Register(MqttCommand_RefreshNodeInfo::StaticGetCommand(), &MqttCommand_RefreshNodeInfo::Create);
this->Register(MqttCommand_RequestNodeState::StaticGetCommand(), &MqttCommand_RequestNodeState::Create);
this->Register(MqttCommand_RequestNodeDynamic::StaticGetCommand(), &MqttCommand_RequestNodeDynamic::Create);

View file

@ -378,6 +378,7 @@ void mqttpublisher::cleanTopics(QMqttMessage msg) {
if (jsmsg.HasMember("Status") && (QString::fromStdString(jsmsg["Status"].GetString()) != "Offline")) {
qCDebug(ozwmp) << "Unsubscribing from Topic Cleanup";
this->m_cleanTopicSubscription->unsubscribe();
exit(-1);
}
return;
}
@ -658,7 +659,6 @@ bool mqttpublisher::sendCommandClassUpdate(quint8 node, quint8 instance, quint8
return true;
}
void mqttpublisher::sendCommandUpdate(QString command, rapidjson::Document &js) {
QT2JS::SetUInt64(js, "TimeStamp", QDateTime::currentSecsSinceEpoch());
this->m_client->publish(QMqttTopicName(getCommandResponseTopic(command.toLower())), QT2JS::getJSON(js), 0, false);
@ -666,7 +666,7 @@ void mqttpublisher::sendCommandUpdate(QString command, rapidjson::Document &js)
}
bool mqttpublisher::delNodeTopic(quint8 node) {
this->m_client->publish(QMqttTopicName(getNodeTopic(MQTT_OZW_NODE_TOPIC, node)), NULL, 0, false);
this->m_client->publish(QMqttTopicName(getNodeTopic(MQTT_OZW_NODE_TOPIC, node)), NULL, 0, true);
return true;
}
@ -686,13 +686,22 @@ bool mqttpublisher::delValueTopic(quint64 vidKey) {
qCWarning(ozwmp) << "sendValueUpdate: Can't find CC for Value: " << vidKey;
return false;
}
this->m_client->publish(QMqttTopicName(getValueTopic(MQTT_OZW_VID_TOPIC, node, instance, cc, vidKey)), NULL, 0, false);
this->m_client->publish(QMqttTopicName(getValueTopic(MQTT_OZW_VID_TOPIC, node, instance, cc, vidKey)), NULL, 0, true);
/* XXX TODO: Scan though remaining Values, and see if any other Values are under the same CC or instance
* if not - Then we should delete the CC/instance topic as well
*/
return true;
}
bool mqttpublisher::delInstanceTopic(quint8 node, quint8 instance) {
this->m_client->publish(QMqttTopicName(getInstanceTopic(MQTT_OZW_INSTANCE_TOPIC, node, instance)), NULL, 0, true);
return true;
}
bool mqttpublisher::delCommandClassTopic(quint8 node, quint8 instance, quint8 cc) {
this->m_client->publish(QMqttTopicName(getCommandClassTopic(MQTT_OZW_COMMANDCLASS_TOPIC, node, instance, cc)), NULL, 0, true);
return true;
}
void mqttpublisher::ready() {
qCDebug(ozwmp) << "Publishing Event ready:";

View file

@ -113,6 +113,8 @@ private:
bool sendCommandClassUpdate(quint8, quint8, quint8);
bool delNodeTopic(quint8);
bool delValueTopic(quint64);
bool delInstanceTopic(quint8, quint8);
bool delCommandClassTopic(quint8, quint8, quint8);
rapidjson::Document *getInstanceJSON(quint8, quint8);
rapidjson::Document *getCommandClassJSON(quint8, quint8, quint8);

View file

@ -27,6 +27,7 @@ qtHaveModule(mqtt) {
mqttcommands/mqttcommands.cpp \
mqttcommands/ping.cpp \
mqttcommands/open.cpp \
mqttcommands/close.cpp \
mqttcommands/refreshnodeinfo.cpp \
mqttcommands/requestNodeState.cpp \
mqttcommands/requestNodeDynamic.cpp \
@ -61,6 +62,7 @@ qtHaveModule(mqtt) {
mqttcommands/mqttcommands.h \
mqttcommands/ping.h \
mqttcommands/open.h \
mqttcommands/close.h \
mqttcommands/refreshnodeinfo.h \
mqttcommands/requestNodeState.h \
mqttcommands/requestNodeDynamic.h \