Add enabled property to network and implement permit join
This commit is contained in:
parent
9acef17318
commit
a171879db7
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user