Make use of the new setupStatus property
This commit is contained in:
parent
ec61b27129
commit
f2fe43573d
@ -82,8 +82,8 @@ QVariant Devices::data(const QModelIndex &index, int role) const
|
|||||||
return device->deviceClassId().toString();
|
return device->deviceClassId().toString();
|
||||||
case RoleParentDeviceId:
|
case RoleParentDeviceId:
|
||||||
return device->parentDeviceId().toString();
|
return device->parentDeviceId().toString();
|
||||||
case RoleSetupComplete:
|
case RoleSetupStatus:
|
||||||
return device->setupComplete();
|
return device->setupStatus();
|
||||||
case RoleInterfaces:
|
case RoleInterfaces:
|
||||||
return device->deviceClass()->interfaces();
|
return device->deviceClass()->interfaces();
|
||||||
case RoleBaseInterface:
|
case RoleBaseInterface:
|
||||||
@ -104,10 +104,10 @@ void Devices::addDevice(Device *device)
|
|||||||
if (idx < 0) return;
|
if (idx < 0) return;
|
||||||
emit dataChanged(index(idx), index(idx), {RoleName});
|
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);
|
int idx = m_devices.indexOf(device);
|
||||||
if (idx < 0) return;
|
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]() {
|
connect(device->states(), &States::dataChanged, this, [device, this]() {
|
||||||
int idx = m_devices.indexOf(device);
|
int idx = m_devices.indexOf(device);
|
||||||
@ -144,7 +144,7 @@ QHash<int, QByteArray> Devices::roleNames() const
|
|||||||
roles[RoleId] = "id";
|
roles[RoleId] = "id";
|
||||||
roles[RoleDeviceClass] = "deviceClassId";
|
roles[RoleDeviceClass] = "deviceClassId";
|
||||||
roles[RoleParentDeviceId] = "parentDeviceId";
|
roles[RoleParentDeviceId] = "parentDeviceId";
|
||||||
roles[RoleSetupComplete] = "setupComplete";
|
roles[RoleSetupStatus] = "setupStatus";
|
||||||
roles[RoleInterfaces] = "interfaces";
|
roles[RoleInterfaces] = "interfaces";
|
||||||
roles[RoleBaseInterface] = "baseInterface";
|
roles[RoleBaseInterface] = "baseInterface";
|
||||||
return roles;
|
return roles;
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public:
|
|||||||
RoleId,
|
RoleId,
|
||||||
RoleParentDeviceId,
|
RoleParentDeviceId,
|
||||||
RoleDeviceClass,
|
RoleDeviceClass,
|
||||||
RoleSetupComplete,
|
RoleSetupStatus,
|
||||||
RoleInterfaces,
|
RoleInterfaces,
|
||||||
RoleBaseInterface
|
RoleBaseInterface
|
||||||
};
|
};
|
||||||
|
|||||||
@ -240,7 +240,13 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev
|
|||||||
}
|
}
|
||||||
device->setName(deviceMap.value("name").toString());
|
device->setName(deviceMap.value("name").toString());
|
||||||
device->setId(deviceMap.value("id").toUuid());
|
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::DeviceSetupStatus>();
|
||||||
|
device->setSetupStatus(static_cast<Device::DeviceSetupStatus>(setupStatusEnum.keyToValue(deviceMap.value("setupStatus").toByteArray().data())));
|
||||||
|
} else {
|
||||||
|
device->setSetupStatus(deviceMap.value("setupComplete").toBool() ? Device::DeviceSetupStatusComplete : Device::DeviceSetupStatusNone);
|
||||||
|
}
|
||||||
|
|
||||||
Params *params = device->params();
|
Params *params = device->params();
|
||||||
if (!params) {
|
if (!params) {
|
||||||
|
|||||||
@ -76,15 +76,17 @@ bool Device::isChild() const
|
|||||||
return !m_parentDeviceId.isNull();
|
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;
|
if (m_setupStatus != setupStatus) {
|
||||||
emit setupCompleteChanged();
|
m_setupStatus = setupStatus;
|
||||||
|
emit setupStatusChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Params *Device::params() const
|
Params *Device::params() const
|
||||||
|
|||||||
@ -48,27 +48,35 @@ class Device : public QObject
|
|||||||
Q_PROPERTY(QUuid parentDeviceId READ parentDeviceId CONSTANT)
|
Q_PROPERTY(QUuid parentDeviceId READ parentDeviceId CONSTANT)
|
||||||
Q_PROPERTY(bool isChild READ isChild CONSTANT)
|
Q_PROPERTY(bool isChild READ isChild CONSTANT)
|
||||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
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 *params READ params NOTIFY paramsChanged)
|
||||||
Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged)
|
Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged)
|
||||||
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
||||||
Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT)
|
Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Device(DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr);
|
enum DeviceSetupStatus {
|
||||||
|
DeviceSetupStatusNone,
|
||||||
|
DeviceSetupStatusInProgress,
|
||||||
|
DeviceSetupStatusComplete,
|
||||||
|
DeviceSetupStatusFailed
|
||||||
|
};
|
||||||
|
Q_ENUM(DeviceSetupStatus)
|
||||||
|
|
||||||
QString name() const;
|
explicit Device(DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr);
|
||||||
void setName(const QString &name);
|
|
||||||
|
|
||||||
QUuid id() const;
|
QUuid id() const;
|
||||||
void setId(const QUuid &id);
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
QUuid deviceClassId() const;
|
QUuid deviceClassId() const;
|
||||||
QUuid parentDeviceId() const;
|
QUuid parentDeviceId() const;
|
||||||
bool isChild() const;
|
bool isChild() const;
|
||||||
|
|
||||||
bool setupComplete();
|
DeviceSetupStatus setupStatus() const;
|
||||||
void setSetupComplete(const bool &setupComplete);
|
void setSetupStatus(DeviceSetupStatus setupStatus);
|
||||||
|
|
||||||
Params *params() const;
|
Params *params() const;
|
||||||
void setParams(Params *params);
|
void setParams(Params *params);
|
||||||
@ -86,25 +94,25 @@ public:
|
|||||||
Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId);
|
Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId);
|
||||||
void setStateValue(const QUuid &stateTypeId, const QVariant &value);
|
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:
|
signals:
|
||||||
void nameChanged();
|
void nameChanged();
|
||||||
void setupCompleteChanged();
|
void setupStatusChanged();
|
||||||
void paramsChanged();
|
void paramsChanged();
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
void statesChanged();
|
void statesChanged();
|
||||||
void eventTriggered(const QString &eventTypeId, const QVariantMap ¶ms);
|
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);
|
QDebug operator<<(QDebug &dbg, Device* device);
|
||||||
|
|||||||
@ -214,14 +214,16 @@ Page {
|
|||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: infoPane
|
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
|
height: visible ? contentRow.implicitHeight : 0
|
||||||
anchors { left: parent.left; top: parent.top; right: parent.right }
|
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 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 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 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)
|
(batteryCriticalState !== null && batteryCriticalState.value === true)
|
||||||
color: alertState ? "red" : "transparent"
|
color: alertState ? "red" : "transparent"
|
||||||
z: 1000
|
z: 1000
|
||||||
@ -235,9 +237,13 @@ Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: (infoPane.connectedState !== null && infoPane.connectedState.value === false) ?
|
text: infoPane.setupInProgress ?
|
||||||
qsTr("Thing is not connected!")
|
qsTr("Thing is being set up...")
|
||||||
: qsTr("Thing runs out of battery!")
|
: 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
|
visible: infoPane.alertState
|
||||||
font.pixelSize: app.smallFont
|
font.pixelSize: app.smallFont
|
||||||
color: "white"
|
color: "white"
|
||||||
@ -246,9 +252,11 @@ Page {
|
|||||||
ColorIcon {
|
ColorIcon {
|
||||||
height: app.iconSize / 2
|
height: app.iconSize / 2
|
||||||
width: height
|
width: height
|
||||||
visible: infoPane.connectedState !== null && infoPane.connectedState.value === false
|
visible: infoPane.setupInProgress || infoPane.setupFailure || (infoPane.connectedState !== null && infoPane.connectedState.value === false)
|
||||||
color: "white"
|
color: "white"
|
||||||
name: "../images/dialog-warning-symbolic.svg"
|
name: infoPane.setupInProgress ?
|
||||||
|
"../images/settings.svg"
|
||||||
|
: "../images/dialog-warning-symbolic.svg"
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorIcon {
|
ColorIcon {
|
||||||
|
|||||||
Reference in New Issue
Block a user