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();
|
||||
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<int, QByteArray> 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;
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
RoleId,
|
||||
RoleParentDeviceId,
|
||||
RoleDeviceClass,
|
||||
RoleSetupComplete,
|
||||
RoleSetupStatus,
|
||||
RoleInterfaces,
|
||||
RoleBaseInterface
|
||||
};
|
||||
|
||||
@ -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::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();
|
||||
if (!params) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user