From a171879db764e62c8530a306335f7398a07f2192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 5 Nov 2020 16:43:42 +0100 Subject: [PATCH] Add enabled property to network and implement permit join --- libnymea-app/zigbee/zigbeemanager.cpp | 13 ++++++++++ libnymea-app/zigbee/zigbeemanager.h | 2 ++ libnymea-app/zigbee/zigbeenetwork.cpp | 14 ++++++++++ libnymea-app/zigbee/zigbeenetwork.h | 6 +++++ nymea-app/ui/system/ZigbeeNetworkAddPage.qml | 6 +++-- nymea-app/ui/system/ZigbeeNetworkPage.qml | 27 ++++++++++++++++++-- 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/libnymea-app/zigbee/zigbeemanager.cpp b/libnymea-app/zigbee/zigbeemanager.cpp index fb54aa80..c420d309 100644 --- a/libnymea-app/zigbee/zigbeemanager.cpp +++ b/libnymea-app/zigbee/zigbeemanager.cpp @@ -89,6 +89,14 @@ void ZigbeeManager::removeNetwork(const QUuid &networkUuid) m_client->sendCommand("Zigbee.RemoveNetwork", params, this, "removeNetworkResponse"); } +void ZigbeeManager::setPermitJoin(const QUuid &networkUuid, uint duration) +{ + QVariantMap params; + params.insert("networkUuid", networkUuid); + params.insert("duration", duration); + m_client->sendCommand("Zigbee.SetPermitJoin", params, this, "setPermitJoinResponse"); +} + void ZigbeeManager::init() { // FIXME: load only when used @@ -132,6 +140,11 @@ void ZigbeeManager::removeNetworkResponse(int commandId, const QVariantMap ¶ qDebug() << "Zigbee remove network response" << commandId << params; } +void ZigbeeManager::setPermitJoinResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Zigbee set permit join network response" << commandId << params; +} + void ZigbeeManager::notificationReceived(const QVariantMap ¬ification) { QString notificationString = notification.value("notification").toString(); diff --git a/libnymea-app/zigbee/zigbeemanager.h b/libnymea-app/zigbee/zigbeemanager.h index 091fb047..443872c0 100644 --- a/libnymea-app/zigbee/zigbeemanager.h +++ b/libnymea-app/zigbee/zigbeemanager.h @@ -57,6 +57,7 @@ public: Q_INVOKABLE void addNetwork(const QString &serialPort, uint baudRate, ZigbeeAdapter::ZigbeeBackendType backendType); Q_INVOKABLE void removeNetwork(const QUuid &networkUuid); + Q_INVOKABLE void setPermitJoin(const QUuid &networkUuid, uint duration = 120); void init(); @@ -68,6 +69,7 @@ private: Q_INVOKABLE void addNetworkResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void removeNetworkResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void setPermitJoinResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void notificationReceived(const QVariantMap ¬ification); diff --git a/libnymea-app/zigbee/zigbeenetwork.cpp b/libnymea-app/zigbee/zigbeenetwork.cpp index 4458c0e1..982a6121 100644 --- a/libnymea-app/zigbee/zigbeenetwork.cpp +++ b/libnymea-app/zigbee/zigbeenetwork.cpp @@ -58,6 +58,20 @@ void ZigbeeNetwork::setNetworkUuid(const QUuid &networkUuid) emit networkUuidChanged(); } +bool ZigbeeNetwork::enabled() const +{ + return m_enabled; +} + +void ZigbeeNetwork::setEnabled(bool enabled) +{ + if (m_enabled == enabled) + return; + + m_enabled = enabled; + emit enabledChanged(); +} + QString ZigbeeNetwork::serialPort() const { return m_serialPort; diff --git a/libnymea-app/zigbee/zigbeenetwork.h b/libnymea-app/zigbee/zigbeenetwork.h index 7df52102..d5044bcf 100644 --- a/libnymea-app/zigbee/zigbeenetwork.h +++ b/libnymea-app/zigbee/zigbeenetwork.h @@ -41,6 +41,7 @@ class ZigbeeNetwork : public QObject { Q_OBJECT Q_PROPERTY(QUuid networkUuid READ networkUuid NOTIFY networkUuidChanged) + Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) Q_PROPERTY(QString serialPort READ serialPort NOTIFY serialPortChanged) Q_PROPERTY(uint baudRate READ baudRate NOTIFY baudRateChanged) Q_PROPERTY(QString macAddress READ macAddress NOTIFY macAddressChanged) @@ -71,6 +72,9 @@ public: QUuid networkUuid() const; void setNetworkUuid(const QUuid &networkUuid); + bool enabled() const; + void setEnabled(bool enabled); + QString serialPort() const; void setSerialPort(const QString &serialPort); @@ -111,6 +115,7 @@ public: signals: void networkUuidChanged(); + void enabledChanged(); void serialPortChanged(); void baudRateChanged(); void macAddressChanged(); @@ -126,6 +131,7 @@ signals: private: QUuid m_networkUuid; + bool m_enabled; QString m_serialPort; uint m_baudRate; QString m_macAddress; diff --git a/nymea-app/ui/system/ZigbeeNetworkAddPage.qml b/nymea-app/ui/system/ZigbeeNetworkAddPage.qml index 2904f2c0..2c97a356 100644 --- a/nymea-app/ui/system/ZigbeeNetworkAddPage.qml +++ b/nymea-app/ui/system/ZigbeeNetworkAddPage.qml @@ -58,7 +58,10 @@ SettingsPageBase { iconName: "../images/stock_usb.svg" progressive: false text: model.description + " - " + model.serialPort - onClicked: engine.zigbeeManager.addNetwork(adapter.serialPort, adapter.baudRate, adapter.backendType) + onClicked: { + engine.zigbeeManager.addNetwork(adapter.serialPort, adapter.baudRate, adapter.backendType) + pageStack.pop() + } } } @@ -80,7 +83,6 @@ SettingsPageBase { iconName: "../images/stock_usb.svg" text: model.description + " - " + model.serialPort // TODO: show backend and baudrate popup before adding - //onClicked: pageStack.push(Qt.resolvedUrl("PluginParamsPage.qml"), {plugin: plugin}) onClicked: engine.zigbeeManager.addNetwork(adapter.serialPort, adapter.baudRate, adapter.backendType) } } diff --git a/nymea-app/ui/system/ZigbeeNetworkPage.qml b/nymea-app/ui/system/ZigbeeNetworkPage.qml index 6fd630cc..3848a6e5 100644 --- a/nymea-app/ui/system/ZigbeeNetworkPage.qml +++ b/nymea-app/ui/system/ZigbeeNetworkPage.qml @@ -59,7 +59,21 @@ SettingsPageBase { NymeaListItemDelegate { Layout.fillWidth: true text: qsTr("Network state") - subText: root.network.networkState + subText: { + switch (root.network.networkState) { + case ZigbeeNetwork.ZigbeeNetworkStateOnline: + return qsTr("The network is online") + case ZigbeeNetwork.ZigbeeNetworkStateOffline: + return qsTr("The network is offline") + case ZigbeeNetwork.ZigbeeNetworkStateStarting: + return qsTr("The network is starting...") + case ZigbeeNetwork.ZigbeeNetworkStateUpdating: + return qsTr("The controller is currently installing an update") + case ZigbeeNetwork.ZigbeeNetworkStateError: + return qsTr("The network is in an error state.") + } + } + progressive: false } @@ -108,7 +122,16 @@ SettingsPageBase { Layout.rightMargin: app.margins enabled: network.networkState === ZigbeeNetwork.ZigbeeNetworkStateOnline text: root.network.permitJoiningEnabled ? qsTr("Extend network open duration") : qsTr("Open network for new Zigbee devices") - onClicked: print("Permit join clicked") + onClicked: engine.zigbeeManager.setPermitJoin(root.network.networkUuid) + } + + Button { + Layout.fillWidth: true + Layout.leftMargin: app.margins + Layout.rightMargin: app.margins + visible: network.networkState === ZigbeeNetwork.ZigbeeNetworkStateOnline && root.network.permitJoiningEnabled + text: qsTr("Close network") + onClicked: engine.zigbeeManager.setPermitJoin(root.network.networkUuid, 0) } }