Add basic structure for the zigbee manager and implement adapter handling

This commit is contained in:
Simon Stürz 2020-11-01 12:29:04 +01:00 committed by Michael Zanetti
parent e6d4af8556
commit ff8f2d0aad
18 changed files with 1183 additions and 1 deletions

View File

@ -38,6 +38,7 @@
#include "connection/awsclient.h"
#include "system/systemcontroller.h"
#include "configuration/networkmanager.h"
#include "zigbee/zigbeemanager.h"
Engine::Engine(QObject *parent) :
QObject(parent),
@ -48,7 +49,8 @@ Engine::Engine(QObject *parent) :
m_logManager(new LogManager(m_jsonRpcClient, this)),
m_tagsManager(new TagsManager(m_jsonRpcClient, this)),
m_nymeaConfiguration(new NymeaConfiguration(m_jsonRpcClient, this)),
m_systemController(new SystemController(m_jsonRpcClient, this))
m_systemController(new SystemController(m_jsonRpcClient, this)),
m_zigbeeManager(new ZigbeeManager(m_jsonRpcClient, this))
{
connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, &Engine::onConnectedChanged);
@ -117,6 +119,11 @@ SystemController *Engine::systemController() const
return m_systemController;
}
ZigbeeManager *Engine::zigbeeManager() const
{
return m_zigbeeManager;
}
void Engine::deployCertificate()
{
if (!m_jsonRpcClient->connected()) {
@ -154,8 +161,13 @@ void Engine::onDeviceManagerFetchingChanged()
m_scriptManager->init();
m_nymeaConfiguration->init();
m_systemController->init();
if (m_jsonRpcClient->ensureServerVersion("1.7")) {
m_tagsManager->init();
}
if (m_jsonRpcClient->ensureServerVersion("5.1")) {
m_zigbeeManager->init();
}
}
}

View File

@ -45,6 +45,7 @@ class TagsManager;
class NymeaConfiguration;
class SystemController;
class NetworkManager;
class ZigbeeManager;
class Engine : public QObject
{
@ -57,6 +58,7 @@ class Engine : public QObject
Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient CONSTANT)
Q_PROPERTY(NymeaConfiguration* nymeaConfiguration READ nymeaConfiguration CONSTANT)
Q_PROPERTY(SystemController* systemController READ systemController CONSTANT)
Q_PROPERTY(ZigbeeManager *zigbeeManager READ zigbeeManager CONSTANT)
public:
explicit Engine(QObject *parent = nullptr);
@ -70,6 +72,7 @@ public:
LogManager *logManager() const;
NymeaConfiguration *nymeaConfiguration() const;
SystemController *systemController() const;
ZigbeeManager *zigbeeManager() const;
Q_INVOKABLE void deployCertificate();
@ -82,6 +85,7 @@ private:
TagsManager *m_tagsManager;
NymeaConfiguration *m_nymeaConfiguration;
SystemController *m_systemController;
ZigbeeManager *m_zigbeeManager;
private slots:
void onConnectedChanged();

View File

@ -120,6 +120,10 @@
#include "types/ioconnection.h"
#include "types/ioconnections.h"
#include "types/ioconnectionwatcher.h"
#include "zigbee/zigbeemanager.h"
#include "zigbee/zigbeeadapter.h"
#include "zigbee/zigbeeadapters.h"
#include "zigbee/zigbeeadaptersproxy.h"
#include <QtQml/qqml.h>
@ -296,6 +300,11 @@ void registerQmlTypes() {
qmlRegisterUncreatableType<Repository>(uri, 1, 0, "Repository", "Get it from Repositories");
qmlRegisterType<PackagesFilterModel>(uri, 1, 0, "PackagesFilterModel");
qmlRegisterUncreatableType<ZigbeeManager>(uri, 1, 0, "ZigbeeManager", "Get it from Engine");
qmlRegisterUncreatableType<ZigbeeAdapter>(uri, 1, 0, "ZigbeeAdapter", "Get it from the ZigbeeAdapters");
qmlRegisterUncreatableType<ZigbeeAdapters>(uri, 1, 0, "ZigbeeAdapters", "Get it from ZigbeeManager");
qmlRegisterType<ZigbeeAdaptersProxy>(uri, 1, 0, "ZigbeeAdaptersProxy");
qmlRegisterType<NetworkManager>(uri, 1, 0, "NetworkManager");
qmlRegisterUncreatableType<NetworkDevices>(uri, 1, 0, "NetworkDevices", "Get it from NetworkManager");
qmlRegisterUncreatableType<WiredNetworkDevices>(uri, 1, 0, "WiredNetworkDevices", "Get it from NetworkManager");

View File

@ -160,6 +160,11 @@ SOURCES += \
models/devicemodel.cpp \
system/systemcontroller.cpp \
thinggroup.cpp \
zigbee/zigbeeadapters.cpp \
zigbee/zigbeeadaptersproxy.cpp \
zigbee/zigbeemanager.cpp \
zigbee/zigbeeadapter.cpp \
HEADERS += \
@ -299,6 +304,10 @@ HEADERS += \
models/devicemodel.h \
system/systemcontroller.h \
thinggroup.h \
zigbee/zigbeeadapters.h \
zigbee/zigbeeadaptersproxy.h \
zigbee/zigbeemanager.h \
zigbee/zigbeeadapter.h \
ubports: {
DEFINES += UBPORTS

View File

@ -0,0 +1,125 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 "zigbeeadapter.h"
ZigbeeAdapter::ZigbeeAdapter(QObject *parent) : QObject(parent)
{
}
QString ZigbeeAdapter::name() const
{
return m_name;
}
void ZigbeeAdapter::setName(const QString &name)
{
m_name = name;
emit nameChanged();
}
QString ZigbeeAdapter::description() const
{
return m_description;
}
void ZigbeeAdapter::setDescription(const QString &description)
{
m_description = description;
emit descriptionChanged();
}
QString ZigbeeAdapter::systemLocation() const
{
return m_systemLocation;
}
void ZigbeeAdapter::setSystemLocation(const QString &systemLocation)
{
m_systemLocation = systemLocation;
emit systemLocationChanged();
}
bool ZigbeeAdapter::hardwareRecognized() const
{
return m_hardwareRecognized;
}
void ZigbeeAdapter::setHardwareRecognized(bool hardwareRecognized)
{
m_hardwareRecognized = hardwareRecognized;
emit hardwareRecognizedChanged();
}
ZigbeeAdapter::ZigbeeBackendType ZigbeeAdapter::backendType() const
{
return m_backendType;
}
void ZigbeeAdapter::setBackendType(ZigbeeAdapter::ZigbeeBackendType backendType)
{
m_backendType = backendType;
emit backendTypeChanged();
}
qint32 ZigbeeAdapter::baudRate() const
{
return m_baudRate;
}
void ZigbeeAdapter::setBaudRate(qint32 baudRate)
{
m_baudRate = baudRate;
emit baudRateChanged();
}
bool ZigbeeAdapter::operator==(const ZigbeeAdapter &other) const
{
return m_systemLocation == other.systemLocation()
&& m_name == other.name()
&& m_description == other.description()
&& m_hardwareRecognized == other.hardwareRecognized()
&& m_backendType == other.backendType()
&& m_baudRate == other.baudRate();
}
ZigbeeAdapter::ZigbeeBackendType ZigbeeAdapter::stringToZigbeeBackendType(const QString &backendTypeString)
{
if (backendTypeString == "ZigbeeBackendTypeNxp") {
return ZigbeeBackendTypeNxp;
} else if (backendTypeString == "ZigbeeBackendTypeDeconz") {
return ZigbeeBackendTypeDeconz;
} else {
// default if not recognized
return ZigbeeBackendTypeDeconz;
}
}

View File

@ -0,0 +1,94 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 ZIGBEEADAPTER_H
#define ZIGBEEADAPTER_H
#include <QObject>
class ZigbeeAdapter : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
Q_PROPERTY(QString systemLocation READ systemLocation WRITE setSystemLocation NOTIFY systemLocationChanged)
Q_PROPERTY(bool hardwareRecognized READ hardwareRecognized WRITE setHardwareRecognized NOTIFY hardwareRecognizedChanged)
Q_PROPERTY(ZigbeeAdapter::ZigbeeBackendType backendType READ backendType WRITE setBackendType NOTIFY backendTypeChanged)
Q_PROPERTY(qint32 baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
public:
enum ZigbeeBackendType {
ZigbeeBackendTypeDeconz,
ZigbeeBackendTypeNxp
};
Q_ENUM(ZigbeeBackendType)
explicit ZigbeeAdapter(QObject *parent = nullptr);
QString name() const;
void setName(const QString &name);
QString description() const;
void setDescription(const QString &description);
QString systemLocation() const;
void setSystemLocation(const QString &systemLocation);
bool hardwareRecognized() const;
void setHardwareRecognized(bool hardwareRecognized);
ZigbeeAdapter::ZigbeeBackendType backendType() const;
void setBackendType(ZigbeeAdapter::ZigbeeBackendType backendType);
qint32 baudRate() const;
void setBaudRate(qint32 baudRate);
bool operator==(const ZigbeeAdapter &other) const;
static ZigbeeAdapter::ZigbeeBackendType stringToZigbeeBackendType(const QString &backendTypeString);
private:
QString m_name;
QString m_description;
QString m_systemLocation;
bool m_hardwareRecognized = false;
ZigbeeAdapter::ZigbeeBackendType m_backendType = ZigbeeAdapter::ZigbeeBackendTypeDeconz;
qint32 m_baudRate = 38400;
signals:
void nameChanged();
void descriptionChanged();
void systemLocationChanged();
void hardwareRecognizedChanged();
void backendTypeChanged();
void baudRateChanged();
};
#endif // ZIGBEEADAPTER_H

View File

@ -0,0 +1,143 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 "zigbeeadapters.h"
ZigbeeAdapters::ZigbeeAdapters(QObject *parent) : QAbstractListModel(parent)
{
}
int ZigbeeAdapters::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_adapters.count();
}
QVariant ZigbeeAdapters::data(const QModelIndex &index, int role) const
{
switch (role) {
case RoleName:
return m_adapters.at(index.row())->name();
case RoleDescription:
return m_adapters.at(index.row())->description();
case RoleSystemLocation:
return m_adapters.at(index.row())->systemLocation();
case RoleHardwareRecognized:
return m_adapters.at(index.row())->hardwareRecognized();
case RoleBackendType:
return m_adapters.at(index.row())->backendType();
case RoleBaudRate:
return m_adapters.at(index.row())->baudRate();
}
return QVariant();
}
QHash<int, QByteArray> ZigbeeAdapters::roleNames() const
{
QHash<int, QByteArray> roles;
roles.insert(RoleName, "name");
roles.insert(RoleDescription, "description");
roles.insert(RoleSystemLocation, "systemLocation");
roles.insert(RoleHardwareRecognized, "hardwareRecognized");
roles.insert(RoleBackendType, "backendType");
roles.insert(RoleBaudRate, "baudRate");
return roles;
}
void ZigbeeAdapters::addAdapter(ZigbeeAdapter *adapter)
{
adapter->setParent(this);
beginInsertRows(QModelIndex(), m_adapters.count(), m_adapters.count());
m_adapters.append(adapter);
connect(adapter, &ZigbeeAdapter::nameChanged, this, [this, adapter]() {
QModelIndex idx = index(m_adapters.indexOf(adapter), 0);
emit dataChanged(idx, idx, {RoleName});
});
connect(adapter, &ZigbeeAdapter::descriptionChanged, this, [this, adapter]() {
QModelIndex idx = index(m_adapters.indexOf(adapter), 0);
emit dataChanged(idx, idx, {RoleDescription});
});
connect(adapter, &ZigbeeAdapter::systemLocationChanged, this, [this, adapter]() {
QModelIndex idx = index(m_adapters.indexOf(adapter), 0);
emit dataChanged(idx, idx, {RoleSystemLocation});
});
connect(adapter, &ZigbeeAdapter::hardwareRecognizedChanged, this, [this, adapter]() {
QModelIndex idx = index(m_adapters.indexOf(adapter), 0);
emit dataChanged(idx, idx, {RoleHardwareRecognized});
});
connect(adapter, &ZigbeeAdapter::backendTypeChanged, this, [this, adapter]() {
QModelIndex idx = index(m_adapters.indexOf(adapter), 0);
emit dataChanged(idx, idx, {RoleBackendType});
});
connect(adapter, &ZigbeeAdapter::baudRateChanged, this, [this, adapter]() {
QModelIndex idx = index(m_adapters.indexOf(adapter), 0);
emit dataChanged(idx, idx, {RoleBaudRate});
});
endInsertRows();
emit countChanged();
}
void ZigbeeAdapters::removeAdapter(const QString &systemLocation)
{
for (int i = 0; i < m_adapters.count(); i++) {
if (m_adapters.at(i)->systemLocation() == systemLocation) {
beginRemoveRows(QModelIndex(), i, i);
m_adapters.takeAt(i)->deleteLater();
endRemoveRows();
return;
}
}
}
void ZigbeeAdapters::clear()
{
beginResetModel();
qDeleteAll(m_adapters);
m_adapters.clear();
endResetModel();
emit countChanged();
}
ZigbeeAdapter *ZigbeeAdapters::get(int index) const
{
if (index < 0 || index > m_adapters.count() - 1) {
return nullptr;
}
return m_adapters.at(index);
}

View File

@ -0,0 +1,77 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 ZIGBEEADAPTERS_H
#define ZIGBEEADAPTERS_H
#include <QObject>
#include <QAbstractListModel>
#include "zigbeeadapter.h"
class ZigbeeAdapters : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
enum Roles {
RoleName,
RoleDescription,
RoleSystemLocation,
RoleHardwareRecognized,
RoleBackendType,
RoleBaudRate
};
Q_ENUM(Roles)
explicit ZigbeeAdapters(QObject *parent = nullptr);
virtual ~ZigbeeAdapters() override = default;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
void addAdapter(ZigbeeAdapter *adapter);
void removeAdapter(const QString &systemLocation);
void clear();
Q_INVOKABLE virtual ZigbeeAdapter *get(int index) const;
signals:
void countChanged();
protected:
QList<ZigbeeAdapter *> m_adapters;
};
#endif // ZIGBEEADAPTERS_H

View File

@ -0,0 +1,93 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 "zigbeeadaptersproxy.h"
#include "zigbeeadapters.h"
ZigbeeAdaptersProxy::ZigbeeAdaptersProxy(QObject *parent) : QSortFilterProxyModel(parent)
{
}
ZigbeeAdapters *ZigbeeAdaptersProxy::adapters() const
{
return m_adapters;
}
void ZigbeeAdaptersProxy::setAdapters(ZigbeeAdapters *adapters)
{
m_adapters = adapters;
emit adaptersChanged();
setSourceModel(m_adapters);
connect(m_adapters, &ZigbeeAdapters::countChanged, this, &ZigbeeAdaptersProxy::countChanged);
setSortRole(ZigbeeAdapters::RoleSystemLocation);
sort(0, Qt::DescendingOrder);
invalidateFilter();
}
ZigbeeAdaptersProxy::HardwareFilter ZigbeeAdaptersProxy::hardwareFilter() const
{
return m_hardwareFilter;
}
void ZigbeeAdaptersProxy::setHardwareFilter(ZigbeeAdaptersProxy::HardwareFilter hardwareFilter)
{
m_hardwareFilter = hardwareFilter;
emit hardwareFilterChanged(m_hardwareFilter);
invalidateFilter();
}
ZigbeeAdapter *ZigbeeAdaptersProxy::get(int index) const
{
return m_adapters->get(mapToSource(this->index(index, 0)).row());
}
bool ZigbeeAdaptersProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
Q_UNUSED(source_parent)
ZigbeeAdapter *adapter = m_adapters->get(source_row);
if (m_hardwareFilter == HardwareFilterRecognized) {
if (adapter->hardwareRecognized() == false) {
return true;
}
}
if (m_hardwareFilter == HardwareFilterUnrecognized) {
if (adapter->hardwareRecognized() == true) {
return true;
}
}
return false;
}

View File

@ -0,0 +1,78 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 ZIGBEEADAPTERSPROXY_H
#define ZIGBEEADAPTERSPROXY_H
#include <QObject>
#include <QSortFilterProxyModel>
class ZigbeeAdapter;
class ZigbeeAdapters;
class ZigbeeAdaptersProxy : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(ZigbeeAdapters * adapters READ adapters WRITE setAdapters NOTIFY adaptersChanged)
Q_PROPERTY(ZigbeeAdaptersProxy::HardwareFilter hardwareFilter READ hardwareFilter WRITE setHardwareFilter NOTIFY hardwareFilterChanged)
public:
enum HardwareFilter {
HardwareFilterNone,
HardwareFilterRecognized,
HardwareFilterUnrecognized
};
Q_ENUM(HardwareFilter)
explicit ZigbeeAdaptersProxy(QObject *parent = nullptr);
ZigbeeAdapters *adapters() const;
void setAdapters(ZigbeeAdapters *adapters);
HardwareFilter hardwareFilter() const;
void setHardwareFilter(HardwareFilter hardwareFilter);
Q_INVOKABLE ZigbeeAdapter* get(int index) const;
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
signals:
void countChanged();
void adaptersChanged();
void hardwareFilterChanged(HardwareFilter hardwareFilter);
private:
ZigbeeAdapters *m_adapters = nullptr;
HardwareFilter m_hardwareFilter = HardwareFilterNone;
};
#endif // ZIGBEEADAPTERSPROXY_H

View File

@ -0,0 +1,111 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 "zigbeemanager.h"
#include "jsonrpc/jsonrpcclient.h"
#include "zigbee/zigbeeadapters.h"
ZigbeeManager::ZigbeeManager(JsonRpcClient *client, QObject *parent) :
JsonHandler(parent),
m_client(client),
m_adapters(new ZigbeeAdapters(this))
{
client->registerNotificationHandler(this, "notificationReceived");
}
ZigbeeManager::~ZigbeeManager()
{
}
QString ZigbeeManager::nameSpace() const
{
return "Zigbee";
}
ZigbeeAdapters *ZigbeeManager::adapters() const
{
return m_adapters;
}
void ZigbeeManager::init()
{
qDebug() << "Zigbee init...";
m_adapters->clear();
m_client->sendCommand("Zigbee.GetAdapters", this, "getAdaptersResponse");
}
void ZigbeeManager::getAdaptersResponse(const QVariantMap &params)
{
qDebug() << "Get adapters response" << params;
m_adapters->clear();
foreach (const QVariant &adapterVariant, params.value("params").toMap().value("adapters").toList()) {
QVariantMap adapterMap = adapterVariant.toMap();
ZigbeeAdapter *adapter = new ZigbeeAdapter(m_adapters);
adapter->setName(adapterMap.value("name").toString());
adapter->setDescription(adapterMap.value("description").toString());
adapter->setSystemLocation(adapterMap.value("systemLocation").toString());
adapter->setBackendType(ZigbeeAdapter::stringToZigbeeBackendType(adapterMap.value("backendType").toString()));
adapter->setBaudRate(adapterMap.value("baudRate").toUInt());
qDebug() << "Zigbee adapter added" << adapter->description() << adapter->systemLocation();
m_adapters->addAdapter(adapter);
}
}
void ZigbeeManager::notificationReceived(const QVariantMap &notification)
{
QString notificationString = notification.value("notification").toString();
if (notificationString == "Zigbee.AdapterAdded") {
QVariantMap adapterMap = notification.value("params").toMap().value("adapter").toMap();
m_adapters->addAdapter(unpackAdapter(adapterMap));
return;
}
if (notificationString == "Zigbee.AdapterRemoved") {
QVariantMap adapterMap = notification.value("params").toMap().value("adapter").toMap();
m_adapters->removeAdapter(adapterMap.value("systemLocation").toString());
return;
}
qDebug() << "Unhandled Zigbee notification" << notificationString << notification;
}
ZigbeeAdapter *ZigbeeManager::unpackAdapter(const QVariantMap &adapterMap)
{
ZigbeeAdapter *adapter = new ZigbeeAdapter(m_adapters);
adapter->setName(adapterMap.value("name").toString());
adapter->setDescription(adapterMap.value("description").toString());
adapter->setSystemLocation(adapterMap.value("systemLocation").toString());
adapter->setBackendType(ZigbeeAdapter::stringToZigbeeBackendType(adapterMap.value("backendType").toString()));
adapter->setBaudRate(adapterMap.value("baudRate").toUInt());
return adapter;
}

View File

@ -0,0 +1,72 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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 ZIGBEEMANAGER_H
#define ZIGBEEMANAGER_H
#include <QObject>
#include "jsonrpc/jsonhandler.h"
class JsonRpcClient;
class ZigbeeAdapter;
class ZigbeeAdapters;
class ZigbeeManager : public JsonHandler
{
Q_OBJECT
Q_PROPERTY(ZigbeeAdapters *adapters READ adapters CONSTANT)
public:
explicit ZigbeeManager(JsonRpcClient* client, QObject *parent = nullptr);
~ZigbeeManager();
QString nameSpace() const override;
ZigbeeAdapters *adapters() const;
void init();
signals:
private:
Q_INVOKABLE void getAdaptersResponse(const QVariantMap &params);
Q_INVOKABLE void notificationReceived(const QVariantMap &notification);
private:
JsonRpcClient* m_client = nullptr;
ZigbeeAdapters *m_adapters = nullptr;
ZigbeeAdapter *unpackAdapter(const QVariantMap &adapterMap);
};
#endif // ZIGBEEMANAGER_H

View File

@ -241,5 +241,6 @@
<file>ui/images/state-in.svg</file>
<file>ui/images/state-out.svg</file>
<file>ui/images/like.svg</file>
<file>ui/images/zigbee.svg</file>
</qresource>
</RCC>

View File

@ -225,5 +225,7 @@
<file>ui/components/ThingStatusIcons.qml</file>
<file>ui/components/InfoPaneBase.qml</file>
<file>ui/components/ThingInfoPane.qml</file>
<file>ui/system/ZigbeeNetworkSettingsPage.qml</file>
<file>ui/system/ZigbeeNetworkAddPage.qml</file>
</qresource>
</RCC>

View File

@ -153,6 +153,23 @@ Page {
}
}
Pane {
Layout.fillWidth: true
Material.elevation: layout.isGrid ? 1 : 0
visible: engine.jsonRpcClient.ensureServerVersion("1.11")
padding: 0
NymeaListItemDelegate {
width: parent.width
iconName: "../images/zigbee.svg"
text: qsTr("ZigBee networking")
subText: qsTr("Manage and configure ZigBee networks")
prominentSubText: false
wrapTexts: false
onClicked: pageStack.push(Qt.resolvedUrl("system/ZigbeeNetworkSettingsPage.qml"))
}
}
Pane {
Layout.fillWidth: true
Material.elevation: layout.isGrid ? 1 : 0

View File

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="96"
height="96"
id="svg4874"
version="1.1"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
viewBox="0 0 96 96.000001"
sodipodi:docname="zigbee_.svg">
<defs
id="defs4876" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="8.7812489"
inkscape:cx="10.528112"
inkscape:cy="41.064759"
inkscape:document-units="px"
inkscape:current-layer="g4780"
showgrid="true"
showborder="true"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:snap-bbox="true"
inkscape:bbox-paths="true"
inkscape:bbox-nodes="true"
inkscape:snap-bbox-edge-midpoints="true"
inkscape:snap-bbox-midpoints="true"
inkscape:object-paths="true"
inkscape:snap-intersection-paths="true"
inkscape:object-nodes="true"
inkscape:snap-smooth-nodes="true"
inkscape:snap-midpoints="true"
inkscape:snap-object-midpoints="true"
inkscape:snap-center="true"
showguides="true"
inkscape:guide-bbox="true"
inkscape:window-width="2880"
inkscape:window-height="1663"
inkscape:window-x="0"
inkscape:window-y="76"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid5451"
empspacing="8" />
<sodipodi:guide
orientation="1,0"
position="8,-8.0000001"
id="guide4063"
inkscape:locked="false" />
<sodipodi:guide
orientation="1,0"
position="4,-8.0000001"
id="guide4065"
inkscape:locked="false" />
<sodipodi:guide
orientation="0,1"
position="-8,88.000001"
id="guide4067"
inkscape:locked="false" />
<sodipodi:guide
orientation="0,1"
position="-8,92.000001"
id="guide4069"
inkscape:locked="false" />
<sodipodi:guide
orientation="0,1"
position="104,4"
id="guide4071"
inkscape:locked="false" />
<sodipodi:guide
orientation="0,1"
position="-5,8.0000001"
id="guide4073"
inkscape:locked="false" />
<sodipodi:guide
orientation="1,0"
position="92,-8.0000001"
id="guide4075"
inkscape:locked="false" />
<sodipodi:guide
orientation="1,0"
position="88,-8.0000001"
id="guide4077"
inkscape:locked="false" />
<sodipodi:guide
orientation="0,1"
position="-8,84.000001"
id="guide4074"
inkscape:locked="false" />
<sodipodi:guide
orientation="1,0"
position="12,-8.0000001"
id="guide4076"
inkscape:locked="false" />
<sodipodi:guide
orientation="0,1"
position="-5,12"
id="guide4078"
inkscape:locked="false" />
<sodipodi:guide
orientation="1,0"
position="84,-9.0000001"
id="guide4080"
inkscape:locked="false" />
<sodipodi:guide
position="48,-8.0000001"
orientation="1,0"
id="guide4170"
inkscape:locked="false" />
<sodipodi:guide
position="-8,48"
orientation="0,1"
id="guide4172"
inkscape:locked="false" />
</sodipodi:namedview>
<metadata
id="metadata4879">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(67.857146,-78.50504)">
<g
transform="matrix(0,-1,-1,0,373.50506,516.50504)"
id="g4845"
style="display:inline">
<g
inkscape:export-ydpi="90"
inkscape:export-xdpi="90"
inkscape:export-filename="next01.png"
transform="matrix(-0.9996045,0,0,1,575.94296,-611.00001)"
id="g4778"
inkscape:label="Layer 1">
<g
transform="matrix(-1,0,0,1,575.99999,611)"
id="g4780"
style="display:inline">
<path
inkscape:connector-curvature="0"
d="m 418.41067,377.27822 c -2.47698,-9.19 -6.3325,-9.76 -10.1,-11.048 -5.65022,5.45 -41.7365,40.432 -41.7365,40.432 0,0 -2.35494,-21.802 2.0068,-46.974 -0.058,0.002 -0.096,0.004 -0.152,0.006 6.22646,-3.99 13.61138,-6.332 21.55452,-6.332 22.10074,0 40.01582,17.908 40.01582,40 0,11.268 -4.67784,21.43 -12.17882,28.7 1.92676,-11.678 3.36934,-34.48 0.59024,-44.784 z"
id="path2"
style="fill:#808080;fill-opacity:1;stroke-width:2.00039554" />
<path
inkscape:connector-curvature="0"
d="m 363.40291,411.91422 c 0.69428,3.964 4.2637,8.424 10.6082,9.414 2.47898,-2.874 41.03022,-39.988 41.03022,-39.988 0.84834,14.016 0.93038,29.138 -1.72868,44.474 -6.5726,4.732 -14.61378,7.548 -23.32922,7.548 -22.10074,0 -40.01582,-17.908 -40.01582,-40 0,-12.346 5.6022,-23.378 14.39568,-30.716 -1.05042,7.744 -3.92954,32.202 -0.96038,49.268 z"
id="path4"
style="fill:#808080;fill-opacity:1;stroke-width:2.00039554" />
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -0,0 +1,81 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Nymea 1.0
import "../components"
SettingsPageBase {
id: root
title: qsTr("Add a new ZigBee network")
SettingsPageSectionHeader {
text: qsTr("ZigBee adapters")
}
Repeater {
model: ZigbeeAdaptersProxy {
adapters: engine.zigbeeManager.adapters
hardwareFilter: ZigbeeAdaptersProxy.HardwareFilterRecognized
}
delegate: NymeaListItemDelegate {
Layout.fillWidth: true
property var adapter: engine.zigbeeManager.adapters.get(index)
iconName: "../images/stock_link.svg"
text: model.description + " - " + model.systemLocation
//onClicked: pageStack.push(Qt.resolvedUrl("PluginParamsPage.qml"), {plugin: plugin})
}
}
SettingsPageSectionHeader {
text: qsTr("Unrecognized ZigBee adapters")
}
Repeater {
model: ZigbeeAdaptersProxy {
adapters: engine.zigbeeManager.adapters
hardwareFilter: ZigbeeAdaptersProxy.HardwareFilterUnrecognized
}
delegate: NymeaListItemDelegate {
Layout.fillWidth: true
property var adapter: engine.zigbeeManager.adapters.get(index)
iconName: "../images/stock_link.svg"
text: model.description + " - " + model.systemLocation
//onClicked: pageStack.push(Qt.resolvedUrl("PluginParamsPage.qml"), {plugin: plugin})
}
}
}

View File

@ -0,0 +1,75 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 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
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.8
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.3
import "../components"
import Nymea 1.0
Page {
id: root
header: NymeaHeader {
text: qsTr("ZigBee networking")
backButtonVisible: true
onBackPressed: pageStack.pop()
HeaderButton {
text: qsTr("Settings")
imageSource: "../images/settings.svg"
onClicked: {
//pageStack.push()
}
}
}
ColumnLayout {
id: contentColumn
anchors.fill: parent
// List networks
SettingsPageSectionHeader {
text: qsTr("ZigBee networks")
}
NymeaListItemDelegate {
Layout.fillWidth: true
text: qsTr("Add ZigBee network")
subText: qsTr("Set up a new ZigBee network")
prominentSubText: false
onClicked: {
pageStack.push(Qt.resolvedUrl("../system/ZigbeeNetworkAddPage.qml"))
}
}
}
}