complete discovery renaming
parent
9a08e50ae3
commit
76954a1403
|
|
@ -199,12 +199,10 @@ void registerQmlTypes() {
|
|||
qmlRegisterUncreatableType<DeviceClass>(uri, 1, 0, "DeviceClass", "Can't create this in QML. Get it from the DeviceClasses.");
|
||||
qmlRegisterUncreatableType<DeviceClasses>(uri, 1, 0, "DeviceClasses", "Can't create this in QML. Get it from the DeviceManager.");
|
||||
qmlRegisterType<DeviceClassesProxy>(uri, 1, 0, "DeviceClassesProxy");
|
||||
qmlRegisterType<ThingDiscovery>(uri, 1, 0, "DeviceDiscovery");
|
||||
qmlRegisterType<ThingDiscovery>(uri, 1, 0, "ThingDiscovery");
|
||||
qmlRegisterType<DeviceDiscoveryProxy>(uri, 1, 0, "DeviceDiscoveryProxy");
|
||||
qmlRegisterType<DeviceDiscoveryProxy>(uri, 1, 0, "ThingDiscoveryProxy");
|
||||
qmlRegisterUncreatableType<DeviceDescriptor>(uri, 1, 0, "DeviceDescriptor", "Get it from DeviceDiscovery");
|
||||
qmlRegisterUncreatableType<DeviceDescriptor>(uri, 1, 0, "ThingDescriptor", "Get it from ThingDiscovery");
|
||||
qmlRegisterType<ThingDiscoveryProxy>(uri, 1, 0, "ThingDiscoveryProxy");
|
||||
qmlRegisterUncreatableType<ThingDescriptor>(uri, 1, 0, "DeviceDescriptor", "Get it from DeviceDiscovery");
|
||||
qmlRegisterUncreatableType<ThingDescriptor>(uri, 1, 0, "ThingDescriptor", "Get it from ThingDiscovery");
|
||||
|
||||
qmlRegisterType<DeviceModel>(uri, 1, 0, "DeviceModel");
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ QVariant ThingDiscovery::data(const QModelIndex &index, int role) const
|
|||
case RoleDescription:
|
||||
return m_foundDevices.at(index.row())->description();
|
||||
case RoleDeviceId:
|
||||
return m_foundDevices.at(index.row())->deviceId();
|
||||
return m_foundDevices.at(index.row())->thingId();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
@ -100,7 +100,7 @@ void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantLi
|
|||
emit busyChanged();
|
||||
}
|
||||
|
||||
DeviceDescriptor *ThingDiscovery::get(int index) const
|
||||
ThingDescriptor *ThingDiscovery::get(int index) const
|
||||
{
|
||||
if (index < 0 || index >= m_foundDevices.count()) {
|
||||
return nullptr;
|
||||
|
|
@ -139,7 +139,7 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap
|
|||
qDebug() << "Found device. Descriptor:" << descriptorVariant;
|
||||
if (!contains(descriptorVariant.toMap().value("id").toUuid())) {
|
||||
beginInsertRows(QModelIndex(), m_foundDevices.count(), m_foundDevices.count());
|
||||
DeviceDescriptor *descriptor = new DeviceDescriptor(descriptorVariant.toMap().value("id").toUuid(),
|
||||
ThingDescriptor *descriptor = new ThingDescriptor(descriptorVariant.toMap().value("id").toUuid(),
|
||||
descriptorVariant.toMap().value("deviceId").toString(),
|
||||
descriptorVariant.toMap().value("title").toString(),
|
||||
descriptorVariant.toMap().value("description").toString());
|
||||
|
|
@ -161,7 +161,7 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap
|
|||
|
||||
bool ThingDiscovery::contains(const QUuid &deviceDescriptorId) const
|
||||
{
|
||||
foreach (DeviceDescriptor *descriptor, m_foundDevices) {
|
||||
foreach (ThingDescriptor *descriptor, m_foundDevices) {
|
||||
if (descriptor->id() == deviceDescriptorId) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -169,10 +169,10 @@ bool ThingDiscovery::contains(const QUuid &deviceDescriptorId) const
|
|||
return false;
|
||||
}
|
||||
|
||||
DeviceDescriptor::DeviceDescriptor(const QUuid &id, const QUuid &deviceId, const QString &name, const QString &description, QObject *parent):
|
||||
ThingDescriptor::ThingDescriptor(const QUuid &id, const QUuid &thingId, const QString &name, const QString &description, QObject *parent):
|
||||
QObject(parent),
|
||||
m_id(id),
|
||||
m_deviceId(deviceId),
|
||||
m_thingId(thingId),
|
||||
m_name(name),
|
||||
m_description(description),
|
||||
m_params(new Params(this))
|
||||
|
|
@ -180,60 +180,60 @@ DeviceDescriptor::DeviceDescriptor(const QUuid &id, const QUuid &deviceId, const
|
|||
|
||||
}
|
||||
|
||||
QUuid DeviceDescriptor::id() const
|
||||
QUuid ThingDescriptor::id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
QUuid DeviceDescriptor::deviceId() const
|
||||
QUuid ThingDescriptor::thingId() const
|
||||
{
|
||||
return m_deviceId;
|
||||
return m_thingId;
|
||||
}
|
||||
|
||||
QString DeviceDescriptor::name() const
|
||||
QString ThingDescriptor::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
QString DeviceDescriptor::description() const
|
||||
QString ThingDescriptor::description() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
Params* DeviceDescriptor::params() const
|
||||
Params* ThingDescriptor::params() const
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
DeviceDiscoveryProxy::DeviceDiscoveryProxy(QObject *parent):
|
||||
ThingDiscoveryProxy::ThingDiscoveryProxy(QObject *parent):
|
||||
QSortFilterProxyModel (parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ThingDiscovery *DeviceDiscoveryProxy::deviceDiscovery() const
|
||||
ThingDiscovery *ThingDiscoveryProxy::thingDiscovery() const
|
||||
{
|
||||
return m_deviceDiscovery;
|
||||
return m_thingDiscovery;
|
||||
}
|
||||
|
||||
void DeviceDiscoveryProxy::setDeviceDiscovery(ThingDiscovery *deviceDiscovery)
|
||||
void ThingDiscoveryProxy::setThingDiscovery(ThingDiscovery *thingDiscovery)
|
||||
{
|
||||
if (m_deviceDiscovery != deviceDiscovery) {
|
||||
m_deviceDiscovery = deviceDiscovery;
|
||||
setSourceModel(deviceDiscovery);
|
||||
emit deviceDiscoveryChanged();
|
||||
if (m_thingDiscovery != thingDiscovery) {
|
||||
m_thingDiscovery = thingDiscovery;
|
||||
setSourceModel(thingDiscovery);
|
||||
emit thingDiscoveryChanged();
|
||||
emit countChanged();
|
||||
connect(m_deviceDiscovery, &ThingDiscovery::countChanged, this, &DeviceDiscoveryProxy::countChanged);
|
||||
connect(m_thingDiscovery, &ThingDiscovery::countChanged, this, &ThingDiscoveryProxy::countChanged);
|
||||
invalidateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
bool DeviceDiscoveryProxy::showAlreadyAdded() const
|
||||
bool ThingDiscoveryProxy::showAlreadyAdded() const
|
||||
{
|
||||
return m_showAlreadyAdded;
|
||||
}
|
||||
|
||||
void DeviceDiscoveryProxy::setShowAlreadyAdded(bool showAlreadyAdded)
|
||||
void ThingDiscoveryProxy::setShowAlreadyAdded(bool showAlreadyAdded)
|
||||
{
|
||||
if (m_showAlreadyAdded != showAlreadyAdded) {
|
||||
m_showAlreadyAdded = showAlreadyAdded;
|
||||
|
|
@ -243,12 +243,12 @@ void DeviceDiscoveryProxy::setShowAlreadyAdded(bool showAlreadyAdded)
|
|||
}
|
||||
}
|
||||
|
||||
bool DeviceDiscoveryProxy::showNew() const
|
||||
bool ThingDiscoveryProxy::showNew() const
|
||||
{
|
||||
return m_showNew;
|
||||
}
|
||||
|
||||
void DeviceDiscoveryProxy::setShowNew(bool showNew)
|
||||
void ThingDiscoveryProxy::setShowNew(bool showNew)
|
||||
{
|
||||
if (m_showNew != showNew) {
|
||||
m_showNew = showNew;
|
||||
|
|
@ -258,37 +258,37 @@ void DeviceDiscoveryProxy::setShowNew(bool showNew)
|
|||
}
|
||||
}
|
||||
|
||||
QUuid DeviceDiscoveryProxy::filterDeviceId() const
|
||||
QUuid ThingDiscoveryProxy::filterThingId() const
|
||||
{
|
||||
return m_filterDeviceId;
|
||||
return m_filterThingId;
|
||||
}
|
||||
|
||||
void DeviceDiscoveryProxy::setFilterDeviceId(const QUuid &filterDeviceId)
|
||||
void ThingDiscoveryProxy::setFilterThingId(const QUuid &filterDeviceId)
|
||||
{
|
||||
if (m_filterDeviceId != filterDeviceId) {
|
||||
m_filterDeviceId = filterDeviceId;
|
||||
emit filterDeviceIdChanged();
|
||||
if (m_filterThingId != filterDeviceId) {
|
||||
m_filterThingId = filterDeviceId;
|
||||
emit filterThingIdChanged();
|
||||
invalidateFilter();
|
||||
emit countChanged();
|
||||
}
|
||||
}
|
||||
|
||||
DeviceDescriptor *DeviceDiscoveryProxy::get(int index) const
|
||||
ThingDescriptor *ThingDiscoveryProxy::get(int index) const
|
||||
{
|
||||
return m_deviceDiscovery->get(mapToSource(this->index(index, 0)).row());
|
||||
return m_thingDiscovery->get(mapToSource(this->index(index, 0)).row());
|
||||
}
|
||||
|
||||
bool DeviceDiscoveryProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
bool ThingDiscoveryProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
Q_UNUSED(sourceParent)
|
||||
DeviceDescriptor* dev = m_deviceDiscovery->get(sourceRow);
|
||||
if (!m_showAlreadyAdded && !dev->deviceId().isNull()) {
|
||||
ThingDescriptor* dev = m_thingDiscovery->get(sourceRow);
|
||||
if (!m_showAlreadyAdded && !dev->thingId().isNull()) {
|
||||
return false;
|
||||
}
|
||||
if (!m_showNew && dev->deviceId().isNull()) {
|
||||
if (!m_showNew && dev->thingId().isNull()) {
|
||||
return false;
|
||||
}
|
||||
if (!m_filterDeviceId.isNull() && dev->deviceId() != m_filterDeviceId) {
|
||||
if (!m_filterThingId.isNull() && dev->thingId() != m_filterThingId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -36,25 +36,25 @@
|
|||
|
||||
#include "engine.h"
|
||||
|
||||
class DeviceDescriptor: public QObject {
|
||||
class ThingDescriptor: public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||
Q_PROPERTY(QUuid deviceId READ deviceId CONSTANT)
|
||||
Q_PROPERTY(QUuid thingId READ thingId CONSTANT)
|
||||
Q_PROPERTY(QString name READ name CONSTANT)
|
||||
Q_PROPERTY(QString description READ description CONSTANT)
|
||||
Q_PROPERTY(Params* params READ params CONSTANT)
|
||||
public:
|
||||
DeviceDescriptor(const QUuid &id, const QUuid &deviceId, const QString &name, const QString &description, QObject *parent = nullptr);
|
||||
ThingDescriptor(const QUuid &id, const QUuid &thingId, const QString &name, const QString &description, QObject *parent = nullptr);
|
||||
|
||||
QUuid id() const;
|
||||
QUuid deviceId() const;
|
||||
QUuid thingId() const;
|
||||
QString name() const;
|
||||
QString description() const;
|
||||
Params* params() const;
|
||||
|
||||
private:
|
||||
QUuid m_id;
|
||||
QUuid m_deviceId;
|
||||
QUuid m_thingId;
|
||||
QString m_name;
|
||||
QString m_description;
|
||||
Params *m_params = nullptr;
|
||||
|
|
@ -84,7 +84,7 @@ public:
|
|||
|
||||
Q_INVOKABLE void discoverThings(const QUuid &thingClassId, const QVariantList &discoveryParams = {});
|
||||
|
||||
Q_INVOKABLE DeviceDescriptor* get(int index) const;
|
||||
Q_INVOKABLE ThingDescriptor* get(int index) const;
|
||||
|
||||
Engine* engine() const;
|
||||
void setEngine(Engine *jsonRpcClient);
|
||||
|
|
@ -106,23 +106,23 @@ private:
|
|||
QString m_displayMessage;
|
||||
|
||||
bool contains(const QUuid &deviceDescriptorId) const;
|
||||
QList<DeviceDescriptor*> m_foundDevices;
|
||||
QList<ThingDescriptor*> m_foundDevices;
|
||||
};
|
||||
|
||||
class DeviceDiscoveryProxy: public QSortFilterProxyModel
|
||||
class ThingDiscoveryProxy: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||
Q_PROPERTY(ThingDiscovery* deviceDiscovery READ deviceDiscovery WRITE setDeviceDiscovery NOTIFY deviceDiscoveryChanged)
|
||||
Q_PROPERTY(ThingDiscovery* thingDiscovery READ thingDiscovery WRITE setThingDiscovery NOTIFY thingDiscoveryChanged)
|
||||
Q_PROPERTY(bool showAlreadyAdded READ showAlreadyAdded WRITE setShowAlreadyAdded NOTIFY showAlreadyAddedChanged)
|
||||
Q_PROPERTY(bool showNew READ showNew WRITE setShowNew NOTIFY showNewChanged)
|
||||
Q_PROPERTY(QUuid filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged)
|
||||
Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
||||
|
||||
public:
|
||||
DeviceDiscoveryProxy(QObject *parent = nullptr);
|
||||
ThingDiscoveryProxy(QObject *parent = nullptr);
|
||||
|
||||
ThingDiscovery* deviceDiscovery() const;
|
||||
void setDeviceDiscovery(ThingDiscovery* deviceDiscovery);
|
||||
ThingDiscovery* thingDiscovery() const;
|
||||
void setThingDiscovery(ThingDiscovery* thingDiscovery);
|
||||
|
||||
bool showAlreadyAdded() const;
|
||||
void setShowAlreadyAdded(bool showAlreadyAdded);
|
||||
|
|
@ -130,26 +130,26 @@ public:
|
|||
bool showNew() const;
|
||||
void setShowNew(bool showNew);
|
||||
|
||||
QUuid filterDeviceId() const;
|
||||
void setFilterDeviceId(const QUuid &filterDeviceId);
|
||||
QUuid filterThingId() const;
|
||||
void setFilterThingId(const QUuid &filterDeviceId);
|
||||
|
||||
Q_INVOKABLE DeviceDescriptor* get(int index) const;
|
||||
Q_INVOKABLE ThingDescriptor* get(int index) const;
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
void deviceDiscoveryChanged();
|
||||
void thingDiscoveryChanged();
|
||||
void showAlreadyAddedChanged();
|
||||
void showNewChanged();
|
||||
void filterDeviceIdChanged();
|
||||
void filterThingIdChanged();
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||
|
||||
private:
|
||||
ThingDiscovery* m_deviceDiscovery = nullptr;
|
||||
ThingDiscovery* m_thingDiscovery = nullptr;
|
||||
bool m_showAlreadyAdded = false;
|
||||
bool m_showNew = true;
|
||||
QUuid m_filterDeviceId;
|
||||
QUuid m_filterThingId;
|
||||
};
|
||||
|
||||
#endif // THINGDISCOVERY_H
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ Page {
|
|||
id: d
|
||||
property var vendorId: null
|
||||
property ThingDescriptor thingDescriptor: null
|
||||
property alias deviceDescriptor: d.thingDescriptor
|
||||
property var discoveryParams: []
|
||||
property string deviceName: ""
|
||||
property int pairRequestId: 0
|
||||
|
|
@ -86,7 +85,7 @@ Page {
|
|||
internalPageStack.push(discoveryParamsPage)
|
||||
} else {
|
||||
print("Starting discovery...")
|
||||
discovery.discoverDevices(deviceClass.id)
|
||||
discovery.discoverThings(deviceClass.id)
|
||||
internalPageStack.push(discoveryPage, {deviceClass: deviceClass})
|
||||
}
|
||||
} else if (root.deviceClass.createMethods.indexOf("CreateMethodUser") !== -1) {
|
||||
|
|
@ -171,7 +170,7 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
DeviceDiscovery {
|
||||
ThingDiscovery {
|
||||
id: discovery
|
||||
engine: _engine
|
||||
}
|
||||
|
|
@ -218,7 +217,7 @@ Page {
|
|||
param["value"] = paramRepeater.itemAt(i).value
|
||||
d.discoveryParams.push(param);
|
||||
}
|
||||
discovery.discoverDevices(root.deviceClass.id, d.discoveryParams)
|
||||
discovery.discoverThings(root.deviceClass.id, d.discoveryParams)
|
||||
internalPageStack.push(discoveryPage, {deviceClass: root.deviceClass})
|
||||
}
|
||||
}
|
||||
|
|
@ -259,12 +258,12 @@ Page {
|
|||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
clip: true
|
||||
model: DeviceDiscoveryProxy {
|
||||
model: ThingDiscoveryProxy {
|
||||
id: discoveryProxy
|
||||
deviceDiscovery: discovery
|
||||
thingDiscovery: discovery
|
||||
showAlreadyAdded: root.device !== null
|
||||
showNew: root.device === null
|
||||
filterDeviceId: root.device ? root.device.id : ""
|
||||
filterThingId: root.device ? root.device.id : ""
|
||||
}
|
||||
delegate: NymeaSwipeDelegate {
|
||||
width: parent.width
|
||||
|
|
@ -273,7 +272,7 @@ Page {
|
|||
subText: model.description
|
||||
iconName: app.interfacesToIcon(discoveryView.deviceClass.interfaces)
|
||||
onClicked: {
|
||||
d.deviceDescriptor = discoveryProxy.get(index);
|
||||
d.thingDescriptor = discoveryProxy.get(index);
|
||||
d.deviceName = model.name;
|
||||
internalPageStack.push(paramsPage)
|
||||
}
|
||||
|
|
@ -284,7 +283,7 @@ Page {
|
|||
Layout.fillWidth: true
|
||||
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins
|
||||
text: qsTr("Search again")
|
||||
onClicked: discovery.discoverDevices(root.deviceClass.id, d.discoveryParams)
|
||||
onClicked: discovery.discoverThings(root.deviceClass.id, d.discoveryParams)
|
||||
visible: !discovery.busy
|
||||
}
|
||||
|
||||
|
|
@ -384,7 +383,7 @@ Page {
|
|||
|
||||
Repeater {
|
||||
id: paramRepeater
|
||||
model: engine.jsonRpcClient.ensureServerVersion("1.12") || d.deviceDescriptor == null ? root.deviceClass.paramTypes : null
|
||||
model: engine.jsonRpcClient.ensureServerVersion("1.12") || d.thingDescriptor == null ? root.deviceClass.paramTypes : null
|
||||
delegate: ParamDelegate {
|
||||
// Layout.preferredHeight: 60
|
||||
Layout.fillWidth: true
|
||||
|
|
@ -441,14 +440,14 @@ Page {
|
|||
switch (root.deviceClass.setupMethod) {
|
||||
case 0:
|
||||
if (root.device) {
|
||||
if (d.deviceDescriptor) {
|
||||
engine.deviceManager.reconfigureDiscoveredDevice(root.device.id, d.deviceDescriptor.id, params);
|
||||
if (d.thingDescriptor) {
|
||||
engine.deviceManager.reconfigureDiscoveredDevice(root.device.id, d.thingDescriptor.id, params);
|
||||
} else {
|
||||
engine.deviceManager.reconfigureDevice(root.device.id, params);
|
||||
}
|
||||
} else {
|
||||
if (d.deviceDescriptor) {
|
||||
engine.deviceManager.addDiscoveredDevice(root.deviceClass.id, d.deviceDescriptor.id, nameTextField.text, params);
|
||||
if (d.thingDescriptor) {
|
||||
engine.deviceManager.addDiscoveredDevice(root.deviceClass.id, d.thingDescriptor.id, nameTextField.text, params);
|
||||
} else {
|
||||
engine.deviceManager.addDevice(root.deviceClass.id, nameTextField.text, params);
|
||||
}
|
||||
|
|
@ -460,15 +459,15 @@ Page {
|
|||
case 4:
|
||||
case 5:
|
||||
if (root.device) {
|
||||
if (d.deviceDescriptor) {
|
||||
engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.deviceDescriptor.id, params, nameTextField.text);
|
||||
if (d.thingDescriptor) {
|
||||
engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.thingDescriptor.id, params, nameTextField.text);
|
||||
} else {
|
||||
engine.deviceManager.rePairDevice(root.device.id, params, nameTextField.text);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (d.deviceDescriptor) {
|
||||
engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.deviceDescriptor.id, params, nameTextField.text);
|
||||
if (d.thingDescriptor) {
|
||||
engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.thingDescriptor.id, params, nameTextField.text);
|
||||
} else {
|
||||
engine.deviceManager.pairDevice(root.deviceClass.id, params, nameTextField.text);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue