diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 08365605..bcb2b87a 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -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) { diff --git a/libnymea-core/zigbee/zigbeemanager.cpp b/libnymea-core/zigbee/zigbeemanager.cpp index cfce0fb7..ae5337c0 100644 --- a/libnymea-core/zigbee/zigbeemanager.cpp +++ b/libnymea-core/zigbee/zigbeemanager.cpp @@ -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) diff --git a/libnymea-core/zigbee/zigbeemanager.h b/libnymea-core/zigbee/zigbeemanager.h index be796203..d235727d 100644 --- a/libnymea-core/zigbee/zigbeemanager.h +++ b/libnymea-core/zigbee/zigbeemanager.h @@ -37,6 +37,7 @@ #include #include "zigbeeadapters.h" +#include "zigbeenodeinitializer.h" namespace nymeaserver { @@ -80,6 +81,8 @@ private: ZigbeeAdapters m_adapters; ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr; QHash m_zigbeeNetworks; + QHash m_zigbeeNodeInitializers; + bool m_available = false; void saveNetwork(ZigbeeNetwork *network); diff --git a/libnymea-core/zigbee/zigbeenodeinitializer.cpp b/libnymea-core/zigbee/zigbeenodeinitializer.cpp new file mode 100644 index 00000000..96b48cfe --- /dev/null +++ b/libnymea-core/zigbee/zigbeenodeinitializer.cpp @@ -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 . +* +* 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 + +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 + + + +} diff --git a/libnymea-core/zigbee/zigbeenodeinitializer.h b/libnymea-core/zigbee/zigbeenodeinitializer.h new file mode 100644 index 00000000..7bfe5304 --- /dev/null +++ b/libnymea-core/zigbee/zigbeenodeinitializer.h @@ -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 . +* +* 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 + +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