From 1c6fbc8d1eb886d151af0149b8332d6d17bc793a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 8 Jan 2025 16:36:38 +0100 Subject: [PATCH] Add network device mock thing --- plugins/mock/extern-plugininfo.h | 5 ++ plugins/mock/integrationpluginmock.cpp | 27 ++++++++++ plugins/mock/integrationpluginmock.json | 53 ++++++++++++++++++++ plugins/mock/plugininfo.h | 20 ++++++++ tests/auto/integrations/testintegrations.cpp | 4 +- 5 files changed, 107 insertions(+), 2 deletions(-) diff --git a/plugins/mock/extern-plugininfo.h b/plugins/mock/extern-plugininfo.h index 9138c85b..5924a803 100644 --- a/plugins/mock/extern-plugininfo.h +++ b/plugins/mock/extern-plugininfo.h @@ -232,5 +232,10 @@ extern StateTypeId virtualIoTemperatureSensorMockInputStateTypeId; extern StateTypeId virtualIoTemperatureSensorMockTemperatureStateTypeId; extern ActionTypeId virtualIoTemperatureSensorMockInputActionTypeId; extern ParamTypeId virtualIoTemperatureSensorMockInputActionInputParamTypeId; +extern ThingClassId networkDeviceMockThingClassId; +extern ParamTypeId networkDeviceMockThingMacAddressParamTypeId; +extern ParamTypeId networkDeviceMockThingHostNameParamTypeId; +extern ParamTypeId networkDeviceMockThingAddressParamTypeId; +extern ParamTypeId networkDeviceMockDiscoveryResultTypeParamTypeId; #endif // EXTERNPLUGININFO_H diff --git a/plugins/mock/integrationpluginmock.cpp b/plugins/mock/integrationpluginmock.cpp index 85127145..02424271 100644 --- a/plugins/mock/integrationpluginmock.cpp +++ b/plugins/mock/integrationpluginmock.cpp @@ -126,6 +126,27 @@ void IntegrationPluginMock::discoverThings(ThingDiscoveryInfo *info) return; } + if (info->thingClassId() == networkDeviceMockThingClassId) { + qCDebug(dcMock()) << "starting network device mock discovery:" << info->params(); + QTimer::singleShot(1000, info, [info](){ + QString resultType = info->params().paramValue(networkDeviceMockDiscoveryResultTypeParamTypeId).toString(); + ParamList params; + if (resultType == "MAC address") { + params.append(Param(networkDeviceMockThingMacAddressParamTypeId, "00:11:22:33:44:55")); + } else if (resultType == "Host name") { + params.append(Param(networkDeviceMockThingHostNameParamTypeId, "hostname.localhost")); + } else if (resultType == "IP address") { + params.append(Param(networkDeviceMockThingAddressParamTypeId, "127.0.0.1")); + } + + ThingDescriptor descriptor(networkDeviceMockThingClassId, "Mocked Thing (networkdevice)", QString()); + descriptor.setParams(params); + info->addThingDescriptor(descriptor); + info->finish(Thing::ThingErrorNoError); + }); + return; + } + qCWarning(dcMock()) << "Cannot discover for ThingClassId" << info->thingClassId(); info->finish(Thing::ThingErrorThingNotFound); } @@ -273,6 +294,12 @@ void IntegrationPluginMock::setupThing(ThingSetupInfo *info) return; } + if (info->thing()->thingClassId() == networkDeviceMockThingClassId) { + qCDebug(dcMock()) << "Network device mock setup complete"; + info->finish(Thing::ThingErrorNoError); + return; + } + qCWarning(dcMock()) << "Unhandled thing class" << info->thing()->thingClass(); info->finish(Thing::ThingErrorThingClassNotFound); } diff --git a/plugins/mock/integrationpluginmock.json b/plugins/mock/integrationpluginmock.json index 60af47ca..47f1fec9 100644 --- a/plugins/mock/integrationpluginmock.json +++ b/plugins/mock/integrationpluginmock.json @@ -1198,6 +1198,59 @@ "defaultValue": -20 } ] + }, + { + "id": "cd8fad43-174b-4ca4-a225-c07e4dbba10a", + "name": "networkDeviceMock", + "displayName": "Mocked Thing (network device)", + "interfaces": ["networkdevice"], + "createMethods": ["discovery", "user"], + "setupMethod": "justAdd", + "discoveryParamTypes": [ + { + "id": "762d9bc3-c07e-42e7-8dab-62c980998677", + "name": "resultType", + "displayName": "Result type", + "type": "QString", + "defaultValue": "MAC address", + "allowedValues": [ + "MAC address", + "Host name", + "IP address" + ] + } + ], + "paramTypes": [ + { + "id": "5c2462ca-883e-4fe1-91f2-7190f9363247", + "name": "macAddress", + "displayName": "MAC address", + "type": "QString", + "defaultValue":"", + "inputType": "MacAddress", + "defaultValue": "", + "readOnly": true + }, + { + "id": "ae867d45-c743-4185-87d3-1a027c985f11", + "name": "hostName", + "displayName": "Host name", + "type": "QString", + "inputType": "TextLine", + "defaultValue": "" + }, + { + "id": "619fb102-0ebd-497e-9960-615c5d347db9", + "name": "address", + "displayName": "IP address", + "type": "QString", + "inputType": "IPv4Address", + "defaultValue": "" + } + ], + "stateTypes": [ ], + "actionTypes": [ ], + "eventTypes": [ ] } ] } diff --git a/plugins/mock/plugininfo.h b/plugins/mock/plugininfo.h index d16ce9ba..c8ee9052 100644 --- a/plugins/mock/plugininfo.h +++ b/plugins/mock/plugininfo.h @@ -236,6 +236,11 @@ StateTypeId virtualIoTemperatureSensorMockInputStateTypeId = StateTypeId("{fd341 StateTypeId virtualIoTemperatureSensorMockTemperatureStateTypeId = StateTypeId("{db9cc518-1012-47e2-8212-6e616fed07a6}"); ActionTypeId virtualIoTemperatureSensorMockInputActionTypeId = ActionTypeId("{fd341f72-6d9a-4812-9f66-47197c48a935}"); ParamTypeId virtualIoTemperatureSensorMockInputActionInputParamTypeId = ParamTypeId("{fd341f72-6d9a-4812-9f66-47197c48a935}"); +ThingClassId networkDeviceMockThingClassId = ThingClassId("{cd8fad43-174b-4ca4-a225-c07e4dbba10a}"); +ParamTypeId networkDeviceMockThingMacAddressParamTypeId = ParamTypeId("{5c2462ca-883e-4fe1-91f2-7190f9363247}"); +ParamTypeId networkDeviceMockThingHostNameParamTypeId = ParamTypeId("{ae867d45-c743-4185-87d3-1a027c985f11}"); +ParamTypeId networkDeviceMockThingAddressParamTypeId = ParamTypeId("{619fb102-0ebd-497e-9960-615c5d347db9}"); +ParamTypeId networkDeviceMockDiscoveryResultTypeParamTypeId = ParamTypeId("{762d9bc3-c07e-42e7-8dab-62c980998677}"); const QString translations[] { //: The name of the Browser Item ActionType ({00b8f0a8-99ca-4aa4-833d-59eb8d4d6de3}) of ThingClass mock @@ -361,6 +366,12 @@ const QString translations[] { //: The name of the ThingClass ({f8917e12-c9cb-4ea1-a06e-1ce6db2194f3}) QT_TRANSLATE_NOOP("mock", "Generic Temperature Sensor (Mock)"), + //: The name of the ParamType (ThingClass: networkDeviceMock, Type: thing, ID: {ae867d45-c743-4185-87d3-1a027c985f11}) + QT_TRANSLATE_NOOP("mock", "Host name"), + + //: The name of the ParamType (ThingClass: networkDeviceMock, Type: thing, ID: {619fb102-0ebd-497e-9960-615c5d347db9}) + QT_TRANSLATE_NOOP("mock", "IP address"), + //: The name of the ParamType (ThingClass: inputTypeMock, Type: thing, ID: {9e5f86a0-4bb3-4892-bff8-3fc4032af6e2}) QT_TRANSLATE_NOOP("mock", "IPv4 address"), @@ -388,6 +399,9 @@ const QString translations[] { //: The name of the StateType ({23df3dce-bd10-4eb3-b5e3-221168440cd4}) of ThingClass inputTypeMock QT_TRANSLATE_NOOP("mock", "Localized list"), + //: The name of the ParamType (ThingClass: networkDeviceMock, Type: thing, ID: {5c2462ca-883e-4fe1-91f2-7190f9363247}) + QT_TRANSLATE_NOOP("mock", "MAC address"), + //: The name of the ParamType (ThingClass: inputTypeMock, Type: thing, ID: {e93db587-7919-48f3-8c88-1651de63c765}) QT_TRANSLATE_NOOP("mock", "Mac address"), @@ -481,6 +495,9 @@ const QString translations[] { //: The name of the ThingClass ({6fe07a77-9c07-4736-81e2-d504314bbcb9}) QT_TRANSLATE_NOOP("mock", "Mocked Thing (User & Password)"), + //: The name of the ThingClass ({cd8fad43-174b-4ca4-a225-c07e4dbba10a}) + QT_TRANSLATE_NOOP("mock", "Mocked Thing (network device)"), + //: The name of the plugin mock ({727a4a9a-c187-446f-aadf-f1b2220607d1}) QT_TRANSLATE_NOOP("mock", "Mocked things"), @@ -508,6 +525,9 @@ const QString translations[] { //: The name of the ParamType (ThingClass: mock, Type: discovery, ID: {d222adb4-2f9c-4c3f-8655-76400d0fb6ce}) QT_TRANSLATE_NOOP("mock", "Result count"), + //: The name of the ParamType (ThingClass: networkDeviceMock, Type: discovery, ID: {762d9bc3-c07e-42e7-8dab-62c980998677}) + QT_TRANSLATE_NOOP("mock", "Result type"), + //: The name of the ParamType (ThingClass: inputTypeMock, Type: thing, ID: {22add8c9-ee4f-43ad-8931-58e999313ac3}) QT_TRANSLATE_NOOP("mock", "Search text"), diff --git a/tests/auto/integrations/testintegrations.cpp b/tests/auto/integrations/testintegrations.cpp index 93f1db9f..4b1835f0 100644 --- a/tests/auto/integrations/testintegrations.cpp +++ b/tests/auto/integrations/testintegrations.cpp @@ -298,8 +298,8 @@ void TestIntegrations::getThingClasses_data() QTest::addColumn>("thingClassIds"); QTest::addColumn("resultCount"); - QTest::newRow("vendor nymea") << nymeaVendorId << QList() << 16; - QTest::newRow("no filter") << VendorId() << QList() << 16; + QTest::newRow("vendor nymea") << nymeaVendorId << QList() << 17; + QTest::newRow("no filter") << VendorId() << QList() << 17; QTest::newRow("invalid vendor") << VendorId("93e7d361-8025-4354-b17e-b68406c800bc") << QList() << 0; QTest::newRow("mockThingClassId") << VendorId() << (QList() << mockThingClassId) << 1; QTest::newRow("invalid thingClassId") << VendorId() << (QList() << ThingClassId("6c78ec28-09b6-476d-ac27-1d6966a45c57")) << 0;