Introduce centralized node initializer for unified network behaviour
This commit is contained in:
parent
b6a6371021
commit
5d467de47d
@ -132,7 +132,8 @@ HEADERS += nymeacore.h \
|
|||||||
platform/platform.h \ \
|
platform/platform.h \ \
|
||||||
zigbee/zigbeeadapter.h \
|
zigbee/zigbeeadapter.h \
|
||||||
zigbee/zigbeeadapters.h \
|
zigbee/zigbeeadapters.h \
|
||||||
zigbee/zigbeemanager.h
|
zigbee/zigbeemanager.h \
|
||||||
|
zigbee/zigbeenodeinitializer.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += nymeacore.cpp \
|
SOURCES += nymeacore.cpp \
|
||||||
@ -220,7 +221,8 @@ SOURCES += nymeacore.cpp \
|
|||||||
platform/platform.cpp \
|
platform/platform.cpp \
|
||||||
zigbee/zigbeeadapter.cpp \
|
zigbee/zigbeeadapter.cpp \
|
||||||
zigbee/zigbeeadapters.cpp \
|
zigbee/zigbeeadapters.cpp \
|
||||||
zigbee/zigbeemanager.cpp
|
zigbee/zigbeemanager.cpp \
|
||||||
|
zigbee/zigbeenodeinitializer.cpp
|
||||||
|
|
||||||
|
|
||||||
versionAtLeast(QT_VERSION, 5.12.0) {
|
versionAtLeast(QT_VERSION, 5.12.0) {
|
||||||
|
|||||||
@ -82,7 +82,8 @@ ZigbeeManager::ZigbeeManager(QObject *parent) :
|
|||||||
// Load zigbee networks from settings
|
// Load zigbee networks from settings
|
||||||
loadZigbeeNetworks();
|
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
|
bool ZigbeeManager::available() const
|
||||||
@ -357,7 +358,11 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
|
|||||||
if (node->shortAddress() == 0) {
|
if (node->shortAddress() == 0) {
|
||||||
return;
|
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){
|
connect(network, &ZigbeeNetwork::nodeRemoved, this, [this, network](ZigbeeNode *node){
|
||||||
@ -376,6 +381,15 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
|
|||||||
|
|
||||||
m_zigbeeNetworks.insert(network->networkUuid(), network);
|
m_zigbeeNetworks.insert(network->networkUuid(), network);
|
||||||
emit zigbeeNetworkAdded(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)
|
ZigbeeAdapter ZigbeeManager::convertUartAdapterToAdapter(const ZigbeeUartAdapter &uartAdapter)
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
#include <zigbeeuartadaptermonitor.h>
|
#include <zigbeeuartadaptermonitor.h>
|
||||||
|
|
||||||
#include "zigbeeadapters.h"
|
#include "zigbeeadapters.h"
|
||||||
|
#include "zigbeenodeinitializer.h"
|
||||||
|
|
||||||
namespace nymeaserver {
|
namespace nymeaserver {
|
||||||
|
|
||||||
@ -80,6 +81,8 @@ private:
|
|||||||
ZigbeeAdapters m_adapters;
|
ZigbeeAdapters m_adapters;
|
||||||
ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr;
|
ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr;
|
||||||
QHash<QUuid, ZigbeeNetwork *> m_zigbeeNetworks;
|
QHash<QUuid, ZigbeeNetwork *> m_zigbeeNetworks;
|
||||||
|
QHash<QUuid, ZigbeeNodeInitializer *> m_zigbeeNodeInitializers;
|
||||||
|
|
||||||
bool m_available = false;
|
bool m_available = false;
|
||||||
|
|
||||||
void saveNetwork(ZigbeeNetwork *network);
|
void saveNetwork(ZigbeeNetwork *network);
|
||||||
|
|||||||
82
libnymea-core/zigbee/zigbeenodeinitializer.cpp
Normal file
82
libnymea-core/zigbee/zigbeenodeinitializer.cpp
Normal 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
56
libnymea-core/zigbee/zigbeenodeinitializer.h
Normal file
56
libnymea-core/zigbee/zigbeenodeinitializer.h
Normal 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
|
||||||
Reference in New Issue
Block a user