From f2898b9fc87bfd1dcec6afb4e18f90d6cddaad21 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 10 Nov 2021 12:57:28 +0100 Subject: [PATCH] Add a providedInterfaces property to thingClass --- libnymea/integrations/pluginmetadata.cpp | 15 ++++++++++++++- libnymea/types/thingclass.cpp | 17 +++++++++++++++++ libnymea/types/thingclass.h | 5 +++++ nymea.pro | 2 +- tests/auto/api.json | 4 +++- tests/auto/autotests.pri | 2 +- 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libnymea/integrations/pluginmetadata.cpp b/libnymea/integrations/pluginmetadata.cpp index a4c55893..8d4a08fb 100644 --- a/libnymea/integrations/pluginmetadata.cpp +++ b/libnymea/integrations/pluginmetadata.cpp @@ -202,7 +202,7 @@ void PluginMetadata::parse(const QJsonObject &jsonObject) QJsonObject thingClassObject = thingClassJson.toObject(); /*! Returns a list of all valid JSON properties a ThingClass JSON definition can have. */ QStringList thingClassProperties = QStringList() << "id" << "name" << "displayName" << "createMethods" << "setupMethod" - << "interfaces" << "browsable" << "discoveryParamTypes" + << "interfaces" << "providedInterfaces" << "browsable" << "discoveryParamTypes" << "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes" << "browserItemActionTypes"; QStringList mandatoryThingClassProperties = QStringList() << "id" << "name" << "displayName"; @@ -870,6 +870,19 @@ void PluginMetadata::parse(const QJsonObject &jsonObject) interfaces.removeDuplicates(); thingClass.setInterfaces(interfaces); + QStringList providedInterfaces; + foreach (const QJsonValue &value, thingClassObject.value("providedInterfaces").toArray()) { + Interface iface = ThingUtils::loadInterface(value.toString()); + if (!iface.isValid()) { + m_validationErrors.append("Thing class \"" + thingClass.name() + "\" uses non-existing interface \"" + value.toString() + "\" in providedInterfaces."); + hasError = true; + continue; + } + providedInterfaces.append(iface.name()); + } + + thingClass.setProvidedInterfaces(providedInterfaces); + thingClass.setStateTypes(stateTypes); thingClass.setActionTypes(actionTypes); thingClass.setEventTypes(eventTypes); diff --git a/libnymea/types/thingclass.cpp b/libnymea/types/thingclass.cpp index 33d114ae..a4ae297e 100644 --- a/libnymea/types/thingclass.cpp +++ b/libnymea/types/thingclass.cpp @@ -357,6 +357,23 @@ void ThingClass::setInterfaces(const QStringList &interfaces) m_interfaces = interfaces; } +/*! Returns the interfaces that a thing does not directly implement, but it may still cater for + them by creating childs that do implement those. This is used as a hint for clients to + filter for desired interfaces during thing setup. + */ +QStringList ThingClass::providedInterfaces() const +{ + return m_providedInterfaces; +} + +/*! Set the list of provided interfaces. This list should contain interfaces for things that + may be created as childs of this thing class. +*/ +void ThingClass::setProvidedInterfaces(const QStringList &providedInterfaces) +{ + m_providedInterfaces = providedInterfaces; +} + /*! Returns whether \l{Device}{Devices} created from this \l{DeviceClass} are browsable */ bool ThingClass::browsable() const { diff --git a/libnymea/types/thingclass.h b/libnymea/types/thingclass.h index 66ce7a09..14382e49 100644 --- a/libnymea/types/thingclass.h +++ b/libnymea/types/thingclass.h @@ -51,6 +51,7 @@ class LIBNYMEA_EXPORT ThingClass Q_PROPERTY(QString name READ name) Q_PROPERTY(QString displayName READ displayName) Q_PROPERTY(QStringList interfaces READ interfaces) + Q_PROPERTY(QStringList providedInterfaces READ providedInterfaces) Q_PROPERTY(bool browsable READ browsable) Q_PROPERTY(SetupMethod setupMethod READ setupMethod) Q_PROPERTY(CreateMethods createMethods READ createMethods) @@ -136,6 +137,9 @@ public: QStringList interfaces() const; void setInterfaces(const QStringList &interfaces); + QStringList providedInterfaces() const; + void setProvidedInterfaces(const QStringList &providedInterfaces); + bool operator==(const ThingClass &device) const; private: @@ -155,6 +159,7 @@ private: CreateMethods m_createMethods; SetupMethod m_setupMethod; QStringList m_interfaces; + QStringList m_providedInterfaces; }; Q_DECLARE_OPERATORS_FOR_FLAGS(ThingClass::CreateMethods) diff --git a/nymea.pro b/nymea.pro index 0794868b..d7a63840 100644 --- a/nymea.pro +++ b/nymea.pro @@ -5,7 +5,7 @@ NYMEA_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p" # define protocol versions JSON_PROTOCOL_VERSION_MAJOR=5 -JSON_PROTOCOL_VERSION_MINOR=7 +JSON_PROTOCOL_VERSION_MINOR=8 JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}" LIBNYMEA_API_VERSION_MAJOR=7 LIBNYMEA_API_VERSION_MINOR=2 diff --git a/tests/auto/api.json b/tests/auto/api.json index 9d6b39ad..bce4b718 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -1,4 +1,4 @@ -5.7 +5.8 { "enums": { "BasicType": [ @@ -2788,6 +2788,7 @@ "r:name": "String", "r:paramTypes": "$ref:ParamTypes", "r:pluginId": "Uuid", + "r:providedInterfaces": "StringList", "r:settingsTypes": "$ref:ParamTypes", "r:setupMethod": "$ref:SetupMethod", "r:stateTypes": "$ref:StateTypes", @@ -3127,6 +3128,7 @@ "r:name": "String", "r:paramTypes": "$ref:ParamTypes", "r:pluginId": "Uuid", + "r:providedInterfaces": "StringList", "r:settingsTypes": "$ref:ParamTypes", "r:setupMethod": "$ref:SetupMethod", "r:stateTypes": "$ref:StateTypes", diff --git a/tests/auto/autotests.pri b/tests/auto/autotests.pri index 2585c9cd..20146fba 100644 --- a/tests/auto/autotests.pri +++ b/tests/auto/autotests.pri @@ -7,7 +7,7 @@ packagesExist(Qt5SerialBus) { DEFINES += WITH_QTSERIALBUS } -PKGCONFIG += nymea-zigbee +PKGCONFIG += nymea-zigbee nymea-networkmanager INCLUDEPATH += $$top_srcdir/libnymea \ $$top_srcdir/libnymea-core \