Allow filtering GetThingClasses for thingClassIds
This commit is contained in:
parent
bfaa85979d
commit
4a41df3cf6
@ -104,8 +104,9 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *thingManager, QObject *pa
|
||||
registerMethod("GetVendors", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Returns a list of supported thing classes, optionally filtered by vendorId.";
|
||||
description = "Returns a list of supported thing classes, optionally filtered by vendorId or by a list of thing class ids.";
|
||||
params.insert("o:vendorId", enumValueName(Uuid));
|
||||
params.insert("o:thingClassIds", QVariantList() << enumValueName(Uuid));
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:thingClasses", objectRef<ThingClasses>());
|
||||
registerMethod("GetThingClasses", description, params, returns);
|
||||
@ -507,21 +508,25 @@ JsonReply* IntegrationsHandler::GetThingClasses(const QVariantMap ¶ms, const
|
||||
QVariantMap returns;
|
||||
QVariantList thingClasses;
|
||||
|
||||
if (params.contains("vendorId")) {
|
||||
VendorId vendorId = VendorId(params.value("vendorId").toString());
|
||||
if (m_thingManager->supportedVendors().findById(vendorId).id().isNull()) {
|
||||
qCWarning(dcThingManager()) << "No such vendor:" << vendorId;
|
||||
return createReply(statusToReply(Thing::ThingErrorVendorNotFound));
|
||||
foreach (const ThingClass &thingClass, NymeaCore::instance()->thingManager()->supportedThings()) {
|
||||
if (params.contains("vendorId") && thingClass.vendorId() != VendorId(params.value("vendorId").toUuid())) {
|
||||
continue;
|
||||
}
|
||||
foreach (const ThingClass &thingClass, NymeaCore::instance()->thingManager()->supportedThings(vendorId)) {
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
thingClasses.append(pack(translatedThingClass));
|
||||
}
|
||||
} else {
|
||||
foreach (const ThingClass &thingClass, NymeaCore::instance()->thingManager()->supportedThings()) {
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
thingClasses.append(pack(translatedThingClass));
|
||||
if (params.contains("thingClassIds")) {
|
||||
bool found = false;
|
||||
foreach (const QString &tcString, params.value("thingClassIds").toStringList()) {
|
||||
if (ThingClassId(tcString) == thingClass.id()) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
thingClasses.append(pack(translatedThingClass));
|
||||
}
|
||||
|
||||
returns.insert("thingError", enumValueName(Thing::ThingErrorNoError));
|
||||
|
||||
@ -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=2
|
||||
JSON_PROTOCOL_VERSION_MINOR=3
|
||||
JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}"
|
||||
LIBNYMEA_API_VERSION_MAJOR=7
|
||||
LIBNYMEA_API_VERSION_MINOR=0
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
5.2
|
||||
5.3
|
||||
{
|
||||
"enums": {
|
||||
"BasicType": [
|
||||
@ -1119,8 +1119,11 @@
|
||||
}
|
||||
},
|
||||
"Integrations.GetThingClasses": {
|
||||
"description": "Returns a list of supported thing classes, optionally filtered by vendorId.",
|
||||
"description": "Returns a list of supported thing classes, optionally filtered by vendorId or by a list of thing class ids.",
|
||||
"params": {
|
||||
"o:thingClassIds": [
|
||||
"Uuid"
|
||||
],
|
||||
"o:vendorId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
|
||||
@ -289,22 +289,33 @@ void TestIntegrations::getSupportedVendors()
|
||||
void TestIntegrations::getThingClasses_data()
|
||||
{
|
||||
QTest::addColumn<VendorId>("vendorId");
|
||||
QTest::addColumn<QList<ThingClassId>>("thingClassIds");
|
||||
QTest::addColumn<int>("resultCount");
|
||||
|
||||
QTest::newRow("vendor nymea") << nymeaVendorId << 17;
|
||||
QTest::newRow("no filter") << VendorId() << 17;
|
||||
QTest::newRow("invalid vendor") << VendorId("93e7d361-8025-4354-b17e-b68406c800bc") << 0;
|
||||
QTest::newRow("vendor nymea") << nymeaVendorId << QList<ThingClassId>() << 17;
|
||||
QTest::newRow("no filter") << VendorId() << QList<ThingClassId>() << 17;
|
||||
QTest::newRow("invalid vendor") << VendorId("93e7d361-8025-4354-b17e-b68406c800bc") << QList<ThingClassId>() << 0;
|
||||
QTest::newRow("mockThingClassId") << VendorId() << (QList<ThingClassId>() << mockThingClassId) << 1;
|
||||
QTest::newRow("invalid thingClassId") << VendorId() << (QList<ThingClassId>() << ThingClassId("6c78ec28-09b6-476d-ac27-1d6966a45c57")) << 0;
|
||||
}
|
||||
|
||||
void TestIntegrations::getThingClasses()
|
||||
{
|
||||
QFETCH(VendorId, vendorId);
|
||||
QFETCH(QList<ThingClassId>, thingClassIds);
|
||||
QFETCH(int, resultCount);
|
||||
|
||||
QVariantMap params;
|
||||
if (!vendorId.isNull()) {
|
||||
params.insert("vendorId", vendorId);
|
||||
}
|
||||
if (!thingClassIds.isEmpty()) {
|
||||
QStringList thingClassIdStrings;
|
||||
foreach (const ThingClassId &id, thingClassIds) {
|
||||
thingClassIdStrings.append(id.toString());
|
||||
}
|
||||
params.insert("thingClassIds", thingClassIdStrings);
|
||||
}
|
||||
QVariant result = injectAndWait("Integrations.GetThingClasses", params);
|
||||
|
||||
QVariantList thingClasses = result.toMap().value("params").toMap().value("thingClasses").toList();
|
||||
|
||||
Reference in New Issue
Block a user