From a9c98dfa0f770eae7ee180d8f16375e86977a18f Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 1 Mar 2022 11:06:36 +0100 Subject: [PATCH] Add support for discoveryType --- libnymea-app/thingdiscovery.cpp | 5 ++++- libnymea-app/thingmanager.cpp | 3 +++ libnymea-app/types/thingclass.cpp | 10 ++++++++++ libnymea-app/types/thingclass.h | 10 ++++++++++ nymea-app/main.cpp | 6 +----- nymea-app/ui/mainviews/energy/ConsumersPieChart.qml | 4 ++-- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/libnymea-app/thingdiscovery.cpp b/libnymea-app/thingdiscovery.cpp index 6d58626e..751f793d 100644 --- a/libnymea-app/thingdiscovery.cpp +++ b/libnymea-app/thingdiscovery.cpp @@ -119,6 +119,9 @@ QList ThingDiscovery::discoverThingsByInterface(const QString &interfaceNam if (!thingClass->interfaces().contains(interfaceName) && !thingClass->providedInterfaces().contains(interfaceName)) { continue; } + if (thingClass->discoveryType() == ThingClass::DiscoveryTypeWeak) { + continue; + } if (!thingClass->createMethods().contains("CreateMethodDiscovery")) { continue; } @@ -198,7 +201,7 @@ void ThingDiscovery::discoverThingsResponse(int commandId, const QVariantMap &pa Param* p = new Param(paramVariant.toMap().value("paramTypeId").toString(), paramVariant.toMap().value("value")); descriptor->params()->addParam(p); } - qCDebug(dcThingManager()) << "Found thing. Descriptor:" << descriptor->name() << descriptor->id(); + qCInfo(dcThingManager()) << "Found thing. Descriptor:" << descriptor->name() << descriptor->id(); m_foundThings.append(descriptor); endInsertRows(); emit countChanged(); diff --git a/libnymea-app/thingmanager.cpp b/libnymea-app/thingmanager.cpp index 7a3b6660..6c10d1af 100644 --- a/libnymea-app/thingmanager.cpp +++ b/libnymea-app/thingmanager.cpp @@ -244,6 +244,7 @@ void ThingManager::getVendorsResponse(int /*commandId*/, const QVariantMap ¶ void ThingManager::getThingClassesResponse(int /*commandId*/, const QVariantMap ¶ms) { + qCDebug(dcThingManager) << "GetThingClasses response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); if (params.keys().contains("thingClasses")) { QVariantList thingClassList = params.value("thingClasses").toList(); foreach (QVariant thingClassVariant, thingClassList) { @@ -774,6 +775,8 @@ ThingClass *ThingManager::unpackThingClass(const QVariantMap &thingClassMap) createMethods.append(method.toString()); } thingClass->setCreateMethods(createMethods); + QMetaEnum metaEnum = QMetaEnum::fromType(); + thingClass->setDiscoveryType(static_cast(metaEnum.keyToValue(thingClassMap.value("discoveryType").toByteArray()))); thingClass->setSetupMethod(stringToSetupMethod(thingClassMap.value("setupMethod").toString())); thingClass->setInterfaces(thingClassMap.value("interfaces").toStringList()); thingClass->setProvidedInterfaces(thingClassMap.value("providedInterfaces").toStringList()); diff --git a/libnymea-app/types/thingclass.cpp b/libnymea-app/types/thingclass.cpp index 381230ff..760be37e 100644 --- a/libnymea-app/types/thingclass.cpp +++ b/libnymea-app/types/thingclass.cpp @@ -97,6 +97,16 @@ void ThingClass::setCreateMethods(const QStringList &createMethods) m_createMethods = createMethods; } +ThingClass::DiscoveryType ThingClass::discoveryType() const +{ + return m_discoveryType; +} + +void ThingClass::setDiscoveryType(ThingClass::DiscoveryType discoveryType) +{ + m_discoveryType = discoveryType; +} + ThingClass::SetupMethod ThingClass::setupMethod() const { return m_setupMethod; diff --git a/libnymea-app/types/thingclass.h b/libnymea-app/types/thingclass.h index 4243c94f..887bee41 100644 --- a/libnymea-app/types/thingclass.h +++ b/libnymea-app/types/thingclass.h @@ -49,6 +49,7 @@ class ThingClass : public QObject Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QUuid vendorId READ vendorId CONSTANT) + Q_PROPERTY(DiscoveryType discoveryTye READ discoveryType CONSTANT) Q_PROPERTY(QStringList createMethods READ createMethods CONSTANT) Q_PROPERTY(SetupMethod setupMethod READ setupMethod CONSTANT) Q_PROPERTY(QStringList interfaces READ interfaces CONSTANT) @@ -64,6 +65,11 @@ class ThingClass : public QObject Q_PROPERTY(ActionTypes *browserItemActionTypes READ browserItemActionTypes NOTIFY browserItemActionTypesChanged) public: + enum DiscoveryType { + DiscoveryTypeWeak, + DiscoveryTypePrecise + }; + Q_ENUM(DiscoveryType) enum SetupMethod { SetupMethodJustAdd, @@ -95,6 +101,9 @@ public: QStringList createMethods() const; void setCreateMethods(const QStringList &createMethods); + DiscoveryType discoveryType() const; + void setDiscoveryType(DiscoveryType discoveryType); + SetupMethod setupMethod() const; void setSetupMethod(SetupMethod setupMethod); @@ -148,6 +157,7 @@ private: QString m_name; QString m_displayName; QStringList m_createMethods; + DiscoveryType m_discoveryType = DiscoveryTypePrecise; SetupMethod m_setupMethod; QStringList m_interfaces; QStringList m_providedInterfaces; diff --git a/nymea-app/main.cpp b/nymea-app/main.cpp index 5d5f9239..7e009a31 100644 --- a/nymea-app/main.cpp +++ b/nymea-app/main.cpp @@ -70,11 +70,7 @@ int main(int argc, char *argv[]) // qt.qml.connections warnings are disabled since the replace only exists // in Qt 5.12. Remove that once 5.12 is the minimum supported version. - QLoggingCategory::setFilterRules("RemoteProxyClientJsonRpcTraffic.debug=false\n" - "RemoteProxyClientJsonRpc.debug=false\n" - "RemoteProxyClientWebSocket.debug=false\n" - "RemoteProxyClientConnection.debug=false\n" - "RemoteProxyClientConnectionTraffic.debug=false\n" + QLoggingCategory::setFilterRules("*.debug=false\n" "qt.qml.connections.warning=false\n" ); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); diff --git a/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml b/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml index 186523ab..ea3c1aa9 100644 --- a/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml +++ b/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml @@ -71,8 +71,8 @@ ChartView { for (var i = 0; i < consumers.count; i++) { var consumer = consumers.get(i) colorMap[consumer] = root.colors[i % root.colors.length] - var currentPowerState = consumer.stateByName("currentPower") - var slice = consumersBalanceSeries.append(consumer.name, currentPowerState.value) + let currentPowerState = consumer.stateByName("currentPower") + let slice = consumersBalanceSeries.append(consumer.name, currentPowerState.value) slice.color = root.colors[i % root.colors.length] currentPowerState.valueChanged.connect(function() { slice.value = currentPowerState.value