diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 4c9f5aff..ad87afc8 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -131,8 +131,7 @@ HEADERS += nymeacore.h \ platform/platform.h \ zigbee/zigbeeadapter.h \ zigbee/zigbeeadapters.h \ - zigbee/zigbeemanager.h \ - zigbee/zigbeenodeinitializer.h + zigbee/zigbeemanager.h SOURCES += nymeacore.cpp \ @@ -219,8 +218,7 @@ SOURCES += nymeacore.cpp \ platform/platform.cpp \ zigbee/zigbeeadapter.cpp \ zigbee/zigbeeadapters.cpp \ - zigbee/zigbeemanager.cpp \ - zigbee/zigbeenodeinitializer.cpp + zigbee/zigbeemanager.cpp versionAtLeast(QT_VERSION, 5.12.0) { diff --git a/libnymea-core/zigbee/zigbeemanager.cpp b/libnymea-core/zigbee/zigbeemanager.cpp index be46a14d..86ee191d 100644 --- a/libnymea-core/zigbee/zigbeemanager.cpp +++ b/libnymea-core/zigbee/zigbeemanager.cpp @@ -474,11 +474,6 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network) } } - -// ZigbeeNodeInitializer *nodeInitializer = m_zigbeeNodeInitializers.value(network->networkUuid()); -// nodeInitializer->initializeNode(node); - //TODO: emit node added once initialized so the plugins can use it - emit nodeAdded(network->networkUuid(), node); }); @@ -499,13 +494,6 @@ 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); - }); - qCDebug(dcZigbee()) << "Network added" << network; foreach (ZigbeeNode *node, network->nodes()) { qCDebug(dcZigbee()) << "-->" << node; @@ -533,8 +521,6 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network) } } } - - 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 0b4196ed..84a39211 100644 --- a/libnymea-core/zigbee/zigbeemanager.h +++ b/libnymea-core/zigbee/zigbeemanager.h @@ -37,7 +37,6 @@ #include #include "zigbeeadapters.h" -#include "zigbeenodeinitializer.h" namespace nymeaserver { @@ -82,7 +81,6 @@ private: ZigbeeAdapters m_adapters; ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr; QHash m_zigbeeNetworks; - QHash m_zigbeeNodeInitializers; bool m_available = false; diff --git a/libnymea-core/zigbee/zigbeenodeinitializer.cpp b/libnymea-core/zigbee/zigbeenodeinitializer.cpp deleted file mode 100644 index b7a5c6de..00000000 --- a/libnymea-core/zigbee/zigbeenodeinitializer.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* 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; - - // Bind the coordinator to group 0x0000 - //m_network->coordinatorNode()->deviceObject()->requestBindShortAddress(0x01, ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000); - - // Initialize and configure server clusters - foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) { - // Configure attribute reporting - if (endpoint->hasInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)) { - - // Read current battery remaining - qCDebug(dcZigbee()) << "Read power configuration cluster attributes" << node; - ZigbeeClusterReply *readAttributeReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->readAttributes({ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining}); - connect(readAttributeReply, &ZigbeeClusterReply::finished, node, [=](){ - if (readAttributeReply->error() != ZigbeeClusterReply::ErrorNoError) { - qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << readAttributeReply->error(); - //emit nodeInitialized(node); - return; - } - qCDebug(dcZigbee()) << "Read power configuration cluster attributes finished successfully"; - - // Bind the cluster to the coordinator - qCDebug(dcZigbee()) << "Bind power configuration cluster to coordinaotr"; - ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindIeeeAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdPowerConfiguration, m_network->coordinatorNode()->extendedAddress(), 0x01); - connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ - if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { - qCWarning(dcZigbee()) << "Failed to bind power cluster to coordinator" << readAttributeReply->error(); - return; - } - qCDebug(dcZigbee()) << "Bind power configuration cluster to coordinaotr finished successfully"; - - // Configure attribute rporting for battery remaining - ZigbeeClusterLibrary::AttributeReportingConfiguration reportingConfig; - reportingConfig.attributeId = ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining; - reportingConfig.dataType = Zigbee::Uint8; - reportingConfig.minReportingInterval = 300; - reportingConfig.maxReportingInterval = 2700; - reportingConfig.reportableChange = ZigbeeDataType(static_cast(14)).data(); - - qCDebug(dcZigbee()) << "Configure attribute reporting for power configuration cluster to coordinator"; - ZigbeeClusterReply *reportingReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->configureReporting({reportingConfig}); - connect(reportingReply, &ZigbeeClusterReply::finished, this, [reportingReply](){ - if (reportingReply->error() != ZigbeeClusterReply::ErrorNoError) { - qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << reportingReply->error(); - return; - } - - qCDebug(dcZigbee()) << "Reporting config finished" << ZigbeeClusterLibrary::parseAttributeReportingStatusRecords(reportingReply->responseFrame().payload); - }); - }); - }); - } - } - - - // Initialize and configure client clusters - foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) { - - if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdOnOff)) { - // Bind command - ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, m_network->coordinatorNode()->shortAddress()); - connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [zdoReply](){ - if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { - qCWarning(dcZigbee()) << "Failed to bind OnOff cluster attributes" << zdoReply->error(); - return; - } - }); - } - - if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdLevelControl)) { - // Bind command - ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, m_network->coordinatorNode()->shortAddress()); - connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [this, node, zdoReply](){ - if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { - qCWarning(dcZigbee()) << "Failed to bind Level cluster attributes" << zdoReply->error(); - //emit nodeInitialized(node); - return; - } - }); - } - } - - //emit nodeInitialized(node); -} diff --git a/libnymea-core/zigbee/zigbeenodeinitializer.h b/libnymea-core/zigbee/zigbeenodeinitializer.h deleted file mode 100644 index 7bfe5304..00000000 --- a/libnymea-core/zigbee/zigbeenodeinitializer.h +++ /dev/null @@ -1,56 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* 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