From f2fe43573dadfb0425550ae8b7143ef17af7c8d4 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 20 Jan 2020 22:12:23 +0100 Subject: [PATCH] Make use of the new setupStatus property --- libnymea-app-core/devices.cpp | 10 ++--- libnymea-app-core/devices.h | 2 +- libnymea-app-core/jsonrpc/jsontypes.cpp | 8 +++- libnymea-common/types/device.cpp | 12 +++--- libnymea-common/types/device.h | 44 ++++++++++++--------- nymea-app/ui/devicepages/DevicePageBase.qml | 24 +++++++---- 6 files changed, 62 insertions(+), 38 deletions(-) diff --git a/libnymea-app-core/devices.cpp b/libnymea-app-core/devices.cpp index e2066b1b..bf3a9b3e 100644 --- a/libnymea-app-core/devices.cpp +++ b/libnymea-app-core/devices.cpp @@ -82,8 +82,8 @@ QVariant Devices::data(const QModelIndex &index, int role) const return device->deviceClassId().toString(); case RoleParentDeviceId: return device->parentDeviceId().toString(); - case RoleSetupComplete: - return device->setupComplete(); + case RoleSetupStatus: + return device->setupStatus(); case RoleInterfaces: return device->deviceClass()->interfaces(); case RoleBaseInterface: @@ -104,10 +104,10 @@ void Devices::addDevice(Device *device) if (idx < 0) return; emit dataChanged(index(idx), index(idx), {RoleName}); }); - connect(device, &Device::setupCompleteChanged, this, [device, this]() { + connect(device, &Device::setupStatusChanged, this, [device, this]() { int idx = m_devices.indexOf(device); if (idx < 0) return; - emit dataChanged(index(idx), index(idx), {RoleSetupComplete}); + emit dataChanged(index(idx), index(idx), {RoleSetupStatus}); }); connect(device->states(), &States::dataChanged, this, [device, this]() { int idx = m_devices.indexOf(device); @@ -144,7 +144,7 @@ QHash Devices::roleNames() const roles[RoleId] = "id"; roles[RoleDeviceClass] = "deviceClassId"; roles[RoleParentDeviceId] = "parentDeviceId"; - roles[RoleSetupComplete] = "setupComplete"; + roles[RoleSetupStatus] = "setupStatus"; roles[RoleInterfaces] = "interfaces"; roles[RoleBaseInterface] = "baseInterface"; return roles; diff --git a/libnymea-app-core/devices.h b/libnymea-app-core/devices.h index 3b5e0450..97893f78 100644 --- a/libnymea-app-core/devices.h +++ b/libnymea-app-core/devices.h @@ -46,7 +46,7 @@ public: RoleId, RoleParentDeviceId, RoleDeviceClass, - RoleSetupComplete, + RoleSetupStatus, RoleInterfaces, RoleBaseInterface }; diff --git a/libnymea-app-core/jsonrpc/jsontypes.cpp b/libnymea-app-core/jsonrpc/jsontypes.cpp index b4255e66..7978498d 100644 --- a/libnymea-app-core/jsonrpc/jsontypes.cpp +++ b/libnymea-app-core/jsonrpc/jsontypes.cpp @@ -240,7 +240,13 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev } device->setName(deviceMap.value("name").toString()); device->setId(deviceMap.value("id").toUuid()); - device->setSetupComplete(deviceMap.value("setupComplete").toBool()); + // As of JSONRPC 4.2 setupComplete is deprecated and setupStatus is new + if (deviceMap.contains("setupStatus")) { + QMetaEnum setupStatusEnum = QMetaEnum::fromType(); + device->setSetupStatus(static_cast(setupStatusEnum.keyToValue(deviceMap.value("setupStatus").toByteArray().data()))); + } else { + device->setSetupStatus(deviceMap.value("setupComplete").toBool() ? Device::DeviceSetupStatusComplete : Device::DeviceSetupStatusNone); + } Params *params = device->params(); if (!params) { diff --git a/libnymea-common/types/device.cpp b/libnymea-common/types/device.cpp index fc72d9b1..5ff7cd3b 100644 --- a/libnymea-common/types/device.cpp +++ b/libnymea-common/types/device.cpp @@ -76,15 +76,17 @@ bool Device::isChild() const return !m_parentDeviceId.isNull(); } -bool Device::setupComplete() +Device::DeviceSetupStatus Device::setupStatus() const { - return m_setupComplete; + return m_setupStatus; } -void Device::setSetupComplete(const bool &setupComplete) +void Device::setSetupStatus(Device::DeviceSetupStatus setupStatus) { - m_setupComplete = setupComplete; - emit setupCompleteChanged(); + if (m_setupStatus != setupStatus) { + m_setupStatus = setupStatus; + emit setupStatusChanged(); + } } Params *Device::params() const diff --git a/libnymea-common/types/device.h b/libnymea-common/types/device.h index ca48bb09..a69f2969 100644 --- a/libnymea-common/types/device.h +++ b/libnymea-common/types/device.h @@ -48,27 +48,35 @@ class Device : public QObject Q_PROPERTY(QUuid parentDeviceId READ parentDeviceId CONSTANT) Q_PROPERTY(bool isChild READ isChild CONSTANT) Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) + Q_PROPERTY(DeviceSetupStatus setupStatus READ setupStatus NOTIFY setupStatusChanged) Q_PROPERTY(Params *params READ params NOTIFY paramsChanged) Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged) Q_PROPERTY(States *states READ states NOTIFY statesChanged) Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT) public: - explicit Device(DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr); + enum DeviceSetupStatus { + DeviceSetupStatusNone, + DeviceSetupStatusInProgress, + DeviceSetupStatusComplete, + DeviceSetupStatusFailed + }; + Q_ENUM(DeviceSetupStatus) - QString name() const; - void setName(const QString &name); + explicit Device(DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr); QUuid id() const; void setId(const QUuid &id); + QString name() const; + void setName(const QString &name); + QUuid deviceClassId() const; QUuid parentDeviceId() const; bool isChild() const; - bool setupComplete(); - void setSetupComplete(const bool &setupComplete); + DeviceSetupStatus setupStatus() const; + void setSetupStatus(DeviceSetupStatus setupStatus); Params *params() const; void setParams(Params *params); @@ -86,25 +94,25 @@ public: Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId); void setStateValue(const QUuid &stateTypeId, const QVariant &value); -private: - QString m_name; - QUuid m_id; - QUuid m_parentDeviceId; - bool m_setupComplete; - Params *m_params = nullptr; - Params *m_settings = nullptr; - States *m_states = nullptr; - DeviceClass *m_deviceClass = nullptr; - - signals: void nameChanged(); - void setupCompleteChanged(); + void setupStatusChanged(); void paramsChanged(); void settingsChanged(); void statesChanged(); void eventTriggered(const QString &eventTypeId, const QVariantMap ¶ms); +private: + +private: + QString m_name; + QUuid m_id; + QUuid m_parentDeviceId; + DeviceSetupStatus m_setupStatus; + Params *m_params = nullptr; + Params *m_settings = nullptr; + States *m_states = nullptr; + DeviceClass *m_deviceClass = nullptr; }; QDebug operator<<(QDebug &dbg, Device* device); diff --git a/nymea-app/ui/devicepages/DevicePageBase.qml b/nymea-app/ui/devicepages/DevicePageBase.qml index 7b02a777..cdeebeb6 100644 --- a/nymea-app/ui/devicepages/DevicePageBase.qml +++ b/nymea-app/ui/devicepages/DevicePageBase.qml @@ -214,14 +214,16 @@ Page { Rectangle { id: infoPane - visible: batteryState !== null || (connectedState !== null && connectedState.value === false) + visible: setupInProgress || setupFailure || batteryState !== null || (connectedState !== null && connectedState.value === false) height: visible ? contentRow.implicitHeight : 0 anchors { left: parent.left; top: parent.top; right: parent.right } + property bool setupInProgress: device.setupStatus == Device.DeviceSetupStatusInProgress + property bool setupFailure: device.setupStatus == Device.DeviceSetupStatusFailed property var batteryState: deviceClass.interfaces.indexOf("battery") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("batteryLevel").id) : null property var batteryCriticalState: deviceClass.interfaces.indexOf("battery") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("batteryCritical").id) : null -// property var connectedState: deviceClass.interfaces.indexOf("connectable") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("connected").id) : null property var connectedState: deviceClass.interfaces.indexOf("connectable") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("connected").id) : null - property bool alertState: (connectedState !== null && connectedState.value === false) || + property bool alertState: setupFailure || + (connectedState !== null && connectedState.value === false) || (batteryCriticalState !== null && batteryCriticalState.value === true) color: alertState ? "red" : "transparent" z: 1000 @@ -235,9 +237,13 @@ Page { } Label { - text: (infoPane.connectedState !== null && infoPane.connectedState.value === false) ? - qsTr("Thing is not connected!") - : qsTr("Thing runs out of battery!") + text: infoPane.setupInProgress ? + qsTr("Thing is being set up...") + : infoPane.setupFailure ? + qsTr("Thing setup failed!") + : (infoPane.connectedState !== null && infoPane.connectedState.value === false) ? + qsTr("Thing is not connected!") + : qsTr("Thing runs out of battery!") visible: infoPane.alertState font.pixelSize: app.smallFont color: "white" @@ -246,9 +252,11 @@ Page { ColorIcon { height: app.iconSize / 2 width: height - visible: infoPane.connectedState !== null && infoPane.connectedState.value === false + visible: infoPane.setupInProgress || infoPane.setupFailure || (infoPane.connectedState !== null && infoPane.connectedState.value === false) color: "white" - name: "../images/dialog-warning-symbolic.svg" + name: infoPane.setupInProgress ? + "../images/settings.svg" + : "../images/dialog-warning-symbolic.svg" } ColorIcon {