From c004c0d81de70f3448b48c69ff09615dc7e28eed Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 24 Feb 2021 13:24:46 +0100 Subject: [PATCH] Make thingclassId optional in AddThing() when there's already a ThingDescriptor --- libnymea-core/jsonrpc/integrationshandler.cpp | 15 ++++++++++++--- nymea.pro | 2 +- tests/auto/api.json | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libnymea-core/jsonrpc/integrationshandler.cpp b/libnymea-core/jsonrpc/integrationshandler.cpp index eac9f524..b12bcbe9 100644 --- a/libnymea-core/jsonrpc/integrationshandler.cpp +++ b/libnymea-core/jsonrpc/integrationshandler.cpp @@ -140,7 +140,7 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *thingManager, QObject *pa "Things with CreateMethodDiscovery require the use of a thingDescriptorId. For discovered " "things, params are not required and will be taken from the ThingDescriptor, however, they " "may be overridden by supplying thingParams."; - params.insert("thingClassId", enumValueName(Uuid)); + params.insert("o:thingClassId", enumValueName(Uuid)); params.insert("name", enumValueName(String)); params.insert("o:thingDescriptorId", enumValueName(Uuid)); params.insert("o:thingParams", objectRef()); @@ -642,7 +642,7 @@ JsonReply* IntegrationsHandler::SetPluginConfiguration(const QVariantMap ¶ms JsonReply* IntegrationsHandler::AddThing(const QVariantMap ¶ms, const JsonContext &context) { - ThingClassId ThingClassId(params.value("thingClassId").toString()); + ThingClassId thingClassId(params.value("thingClassId").toString()); QString thingName = params.value("name").toString(); ParamList thingParams = unpack(params.value("thingParams")); ThingDescriptorId thingDescriptorId(params.value("thingDescriptorId").toString()); @@ -652,7 +652,16 @@ JsonReply* IntegrationsHandler::AddThing(const QVariantMap ¶ms, const JsonCo ThingSetupInfo *info; if (thingDescriptorId.isNull()) { - info = NymeaCore::instance()->thingManager()->addConfiguredThing(ThingClassId, thingParams, thingName); + if (thingClassId.isNull()) { + qCWarning(dcJsonRpc()) << "Either thingClassId or thingDescriptorId is required."; + QVariantMap returns; + returns.insert("thingError", enumValueName(Thing::ThingErrorMissingParameter)); + jsonReply->setData(returns); + jsonReply->finished(); + return jsonReply; + } + info = NymeaCore::instance()->thingManager()->addConfiguredThing(thingClassId, thingParams, thingName); + } else { info = NymeaCore::instance()->thingManager()->addConfiguredThing(thingDescriptorId, thingParams, thingName); } diff --git a/nymea.pro b/nymea.pro index 918fef97..9fec9c53 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=6 -JSON_PROTOCOL_VERSION_MINOR=0 +JSON_PROTOCOL_VERSION_MINOR=1 JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}" LIBNYMEA_API_VERSION_MAJOR=7 LIBNYMEA_API_VERSION_MINOR=3 diff --git a/tests/auto/api.json b/tests/auto/api.json index e78a856e..108385a5 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -1,4 +1,4 @@ -6.0 +6.1 { "enums": { "BasicType": [ @@ -698,9 +698,9 @@ "description": "Add a new thing to the system. Only things with a setupMethod of SetupMethodJustAdd can be added this way. For things with a setupMethod different than SetupMethodJustAdd, use PairThing. Things with CreateMethodJustAdd require all parameters to be supplied here. Things with CreateMethodDiscovery require the use of a thingDescriptorId. For discovered things, params are not required and will be taken from the ThingDescriptor, however, they may be overridden by supplying thingParams.", "params": { "name": "String", + "o:thingClassId": "Uuid", "o:thingDescriptorId": "Uuid", - "o:thingParams": "$ref:ParamList", - "thingClassId": "Uuid" + "o:thingParams": "$ref:ParamList" }, "permissionScope": "PermissionScopeConfigureThings", "returns": {