Introduce centralized node initializer for unified network behaviour

This commit is contained in:
Simon Stürz 2020-11-06 18:11:56 +01:00
parent b6a6371021
commit 5d467de47d
5 changed files with 161 additions and 4 deletions

View File

@ -132,7 +132,8 @@ HEADERS += nymeacore.h \
platform/platform.h \ \
zigbee/zigbeeadapter.h \
zigbee/zigbeeadapters.h \
zigbee/zigbeemanager.h
zigbee/zigbeemanager.h \
zigbee/zigbeenodeinitializer.h
SOURCES += nymeacore.cpp \
@ -220,7 +221,8 @@ SOURCES += nymeacore.cpp \
platform/platform.cpp \
zigbee/zigbeeadapter.cpp \
zigbee/zigbeeadapters.cpp \
zigbee/zigbeemanager.cpp
zigbee/zigbeemanager.cpp \
zigbee/zigbeenodeinitializer.cpp
versionAtLeast(QT_VERSION, 5.12.0) {

View File

@ -82,7 +82,8 @@ ZigbeeManager::ZigbeeManager(QObject *parent) :
// Load zigbee networks from settings
loadZigbeeNetworks();
// TODO: load platform configuration for networks we know for sure how they work
// TODO: load platform configuration for networks we know for sure how they work after loading already configured networks
}
bool ZigbeeManager::available() const
@ -357,7 +358,11 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
if (node->shortAddress() == 0) {
return;
}
emit nodeAdded(network->networkUuid(), node);
ZigbeeNodeInitializer *nodeInitializer = m_zigbeeNodeInitializers.value(network->networkUuid());
nodeInitializer->initializeNode(node);
//emit nodeAdded(network->networkUuid(), node);
});
connect(network, &ZigbeeNetwork::nodeRemoved, this, [this, network](ZigbeeNode *node){
@ -376,6 +381,15 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
m_zigbeeNetworks.insert(network->networkUuid(), network);
emit zigbeeNetworkAdded(network);
// Create node initializer when a new node joins the network
ZigbeeNodeInitializer *nodeInitializer = new ZigbeeNodeInitializer(network, this);
connect(nodeInitializer, &ZigbeeNodeInitializer::nodeInitialized, this, [this, network](ZigbeeNode *node){
qCDebug(dcZigbee()) << "Node initialied from nymea" << node;
emit nodeAdded(network->networkUuid(), node);
});
m_zigbeeNodeInitializers.insert(network->networkUuid(), nodeInitializer);
}
ZigbeeAdapter ZigbeeManager::convertUartAdapterToAdapter(const ZigbeeUartAdapter &uartAdapter)

View File

@ -37,6 +37,7 @@
#include <zigbeeuartadaptermonitor.h>
#include "zigbeeadapters.h"
#include "zigbeenodeinitializer.h"
namespace nymeaserver {
@ -80,6 +81,8 @@ private:
ZigbeeAdapters m_adapters;
ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr;
QHash<QUuid, ZigbeeNetwork *> m_zigbeeNetworks;
QHash<QUuid, ZigbeeNodeInitializer *> m_zigbeeNodeInitializers;
bool m_available = false;
void saveNetwork(ZigbeeNetwork *network);

View File

@ -0,0 +1,82 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, GNU version 3. This project is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "zigbeenodeinitializer.h"
#include "loggingcategories.h"
#include <zigbeenetwork.h>
Q_DECLARE_LOGGING_CATEGORY(dcZigbee)
ZigbeeNodeInitializer::ZigbeeNodeInitializer(ZigbeeNetwork *network, QObject *parent) :
QObject(parent),
m_network(network)
{
}
void ZigbeeNodeInitializer::initializeNode(ZigbeeNode *node)
{
qCDebug(dcZigbee()) << "Start initializing node internally" << node;
// Initialize and configure server clusters
foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) {
// Read values
if (endpoint->hasInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)) {
}
foreach (ZigbeeCluster *cluster, endpoint->inputClusters()) {
switch (cluster->clusterId()) {
case ZigbeeClusterLibrary::ClusterIdPowerConfiguration: {
// Read values
// Configure attribute reporting
break;
}
default:
// Not handeld, leave it to the plugin
break;
}
}
}
// Initialize and configure client clusters
}

View File

@ -0,0 +1,56 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, GNU version 3. This project is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef ZIGBEENODEINITIALIZER_H
#define ZIGBEENODEINITIALIZER_H
#include <QObject>
class ZigbeeNode;
class ZigbeeNetwork;
class ZigbeeNodeInitializer : public QObject
{
Q_OBJECT
public:
explicit ZigbeeNodeInitializer(ZigbeeNetwork *network, QObject *parent = nullptr);
void initializeNode(ZigbeeNode *node);
private:
ZigbeeNetwork *m_network = nullptr;
signals:
void nodeInitialized(ZigbeeNode *node);
};
#endif // ZIGBEENODEINITIALIZER_H